Start or continue a session from a terminal¶
dragon is Dragon Rider on the command line. It starts a session, or continues one, in the
folder of the directory it runs in. The session is a normal session. It runs on the folder's
machine, and the Mac window, the iPhone and iPad app and the web page show it at once. You
can start it in a terminal and answer it on your phone.
dragon uses noun-verb commands. It has three nouns today: sessions, auth and folders.
It keeps a short form for the prompt: dragon "..." starts a session, and dragon continues
the newest one.
dragon keeps no copy of your sessions. Each command reads them from the control plane.
Before you start¶
- A control plane that your other clients use, and a paired window or web page.
- A folder on a machine of that control plane. The directory you run
dragonin is that folder, or a directory in it (a worktree in it is also correct). - The
dragonprogram on yourPATH. See Install dragon, below.
Install dragon¶
Do one of these.
From Dragon Rider.app, on a Mac that has it. The app has dragon in it, and its first-run
set-up links it to ~/.local/bin/dragon for you. It does not ask a question, and it does
not need an administrator password (#6875). The link goes to the app, so when the app
updates itself, dragon updates too.
To see the link, or to install it again after you removed it, open Settings ▸ Machines ▸
This Mac ▸ Command line, or choose Dragon Rider ▸ Install dragon Command…. The section
shows Installed at ~/.local/bin/dragon or Not installed, with Install or
Remove, and whether dragon is paired. When another program is at ~/.local/bin/dragon
(a release download, for example), Dragon Rider does not change it.
Dragon Rider does not edit your shell's files. When ~/.local/bin is not on your login
shell's PATH, the section shows the line to add, with Copy. For zsh, add this line to
~/.zshrc:
export PATH="$HOME/.local/bin:$PATH"
To make the link by hand, use the path to your installed app. This example uses the Applications folder in your home folder:
mkdir -p ~/.local/bin
ln -s "$HOME/Applications/Dragon Rider.app/Contents/Helpers/dragon" ~/.local/bin/dragon
From a source checkout you already have. .agents/skills/ship-app/scripts/ship.sh
--install-cli makes the same link in ~/.local/bin when it installs the app. With
--no-mac, it builds dragon and copies it there.
From a release download on Mac or Linux. Download the dragon archive for your
system and processor from Releases.
Extract it and install the command:
mkdir -p ~/.local/bin
tar -xzf dragon-<os>-<arch>-<version>.tar.gz
install -m 755 dragon ~/.local/bin/dragon
Use the name of the file you downloaded in the tar command. For one release, the
archive and the Mac app include a loops alias. To keep a script that uses loops
with the release download, link ~/.local/bin/loops to dragon.
The alias writes one deprecation line to standard error.
Pair the terminal¶
You pair a terminal one time, as you pair a window.
On a Mac with Dragon Rider, you need no code (#6875). Run any dragon command, or
dragon auth login with no code:
dragonasks Dragon Rider on this Mac to pair it. It says Asked Dragon Rider on this Mac to pair this terminal, and waits.- In the Mac window, Needs you shows Wants to pair dragon on <this Mac's name>, with
the program that ran
dragon(your shell, for example). Click Approve. - The window makes a pairing code for this Mac's control plane. When you have a machine
lock, the window also puts the terminal's key in the lock. Then it gives the code to
dragon, anddragonsays Paired with. There are no digits to compare.
Only the Mac window can approve this request, because that Mac makes the code. On the web page
and the iPhone and iPad app, the request shows only Deny. Dragon Rider cannot tell a
terminal from an agent, so approve only a request that you started. Click Deny for a
request that you did not start. When you click Deny, or nobody answers, dragon is not
paired.
On Linux, or on a Mac without Dragon Rider, pair the terminal with a code:
- In a paired window, open Settings ▸ Control plane, and click Show beside Clients. On the web page, open Settings ▸ Control plane ▸ Clients.
- Click Pair a Client…, choose Mac, then click Copy. On the web page, Copy Command copies
the whole
dragon auth loginline. - In the terminal, type:
dragon auth login '<the code>'
It says Paired with the control plane, as dragon on this computer's name.
4. When you have a machine lock, the terminal must join it too: your machines take
requests only from your devices. dragon auth login asks to join and shows Digits:
and six digits. On another of your devices (a window, the Remote or the web page), click
Compare Digits on the card, make sure that it shows the same digits, and click
Approve. The terminal says Approved. When you have no lock yet, there is no
step 4.
5. Type dragon auth status. It shows the profile, the control plane, the client, this
machine, and the folder of the directory you are in.
The pairing is in ~/.config/dragon/hosts.json (or $XDG_CONFIG_HOME/dragon/hosts.json).
The first command that reads a pairing moves the old loops configuration directory
with its keys. You can use the same pairing. Only you can read it. Anyone who has a copy of it can use your agents, as a paired window
can. The terminal's key for the machine lock is in the Keychain on a Mac, and in
~/.config/dragon/lock-keys/ (mode 0600) on Linux. dragon auth logout deletes both, and
removes the terminal from the control plane's list of clients.
A terminal that you paired before it could join the lock (or whose request ran out, or
was refused) asks to join at the next command, as in step 4. When a machine refuses it,
dragon says takes requests only from your devices: type dragon auth status to ask
again.
Start or continue a session¶
In the folder:
dragon sessions create "fix the flaky test"starts a new session with this prompt, and shows it.dragoncontinues the most recent session here. When the folder has no session, it waits for you to type the first prompt.dragon sessions followcontinues the most recent session here.dragon sessions follow <id or title>continues one session. Use an id asdragon sessions listshows it, or the session's title, or a part of the title that only one session has. To send a prompt at once, usedragon -r <id or title> "…". The short forms aredragon -cfor the newest session anddragon -r <id or title>for one session.dragon sessions listshows the 20 most recent sessions here: the id, the title, the state, the runtime, the folder and the last update.dragon sessions list --allshows all of them, also the archived ones.
A new session starts on Auto. To use a runtime, add --runtime, as
dragon sessions create --runtime claude "…".
The agent's reply comes into the terminal as it writes it. In the chat:
- Return sends what you typed, and Option-Return or Control-J starts a new line.
- Left and Right move one character. Option-Left and Option-Right move one word.
- Home and End move to the start and the end of the line.
- Control-C stops the turn. Push it again in 2 seconds, or when no turn runs, to leave.
- Control-D leaves the chat. The session continues on its machine. Continue it again
with the
dragon sessions followcommand thatdragonshows.
The dragon command lists every key.
Answer a card¶
When the agent asks a question or asks for permission, the terminal shows a card with
numbered answers. Type the number and push Return. For a question with more than one
answer, type the numbers, as 1,3. The same card is also in Needs you on every client:
answer it where you are. When you answer it on another client, the terminal says
answered on another client.
A card that asks for a secret, a step in a browser or a page to open shows in the terminal, but you answer it on another client.
When the directory is not a folder¶
dragon says that the directory is not in a folder on this machine. Then do one of these:
dragon folders addadds this directory as a folder of this machine.dragon folders add <dir>adds another directory.--folder <name>names a folder of the machine by its name, or--folder <path>by its path.--machine <name>names another machine of the control plane. Use it when this computer is not a machine of the control plane.
When you have more than one control plane, --control <host> names the one to use.
Run it from a script¶
Print mode is for scripts, cron jobs and git hooks. It shows no chat. It starts a new session here, waits until its turn ends, and then writes the agent's last reply:
dragon -p "update the changelog for this release"
- The prompt can also come on standard input:
git log -5 | dragon -p. --jsonwrites one JSON object on each line: the session first, the entries as they come, and the end last. See thedragoncommand for each object.dragon sessions create --detach "…"starts the session, writes its id, and stops at once. The session continues.--timeout 10mstops waiting after 10 minutes. The session continues on its machine.
The exit code tells your script how it ended: 0 when the turn ended, 3 when a card waits
and you gave --on-ask=fail, and 4 after the timeout. The
reference has all of them.
When the agent asks¶
By default, print mode waits for an answer. It writes a line on standard error, and you
answer the card on any client, in Needs you. With --on-ask=fail, it stops with exit
code 3 when a card waits, and tells you how to continue: answer the card, then use
dragon sessions follow <id>. dragon never answers a card itself.
Run it from CI¶
A CI runner is not a machine of your control plane. The session runs on the machine that has the folder, and the runner only starts it and follows it.
- Make sure that the runner can get to the control plane. A control plane on your Mac with no public address is not available from a hosted runner. See Run the control plane in the cloud.
- On your computer, pair
dragonone time for CI only, with its own configuration directory.DRAGON_KEY_FILES=1keeps its machine lock key in a file of that directory, not in the Keychain. When it shows the digits, approve it on another device:
export DRAGON_KEY_FILES=1 XDG_CONFIG_HOME=$(mktemp -d)
dragon auth login '<the code>' && tar -C "$XDG_CONFIG_HOME" -cz dragon | base64
- Keep the output as a secret of the CI, for example
LOOPS_CONFIG. It is a key to your agents: do not put it in the repository or in a log. - In the job, write the files and run print mode, with the machine and the folder named:
export DRAGON_KEY_FILES=1 XDG_CONFIG_HOME="$RUNNER_TEMP/dragon-config"
mkdir -p "$XDG_CONFIG_HOME"
printf '%s' "$LOOPS_CONFIG" | base64 -d | tar -C "$XDG_CONFIG_HOME" -xz
dragon -p --machine build-mac --folder my-app --on-ask=fail --timeout 30m \
"the nightly build failed: find why and open a PR with the fix"
To stop the CI's access, remove its client (dragon on the computer that paired it) from
the control plane's list of clients, or run dragon auth logout with the same file.
Where next¶
- The
dragoncommand: every command, flag, exit code and JSON object. - Answer a question: the cards on the other clients.
- Connect a window or phone: pair the other clients, and forget one.