Using the CLI¶
The CLI reference lists every verb and its flags. This page covers the sequences an operator runs, in order, and the places where the obvious next command is the wrong one.
One rule up front, which every example below follows: from a shell, anything that changes
state needs sudo; from an admin agent it needs nothing, which is the intended way to
drive a fleet (the admin role). Reads run as any caller. Both
follow from the same split — a verb that changes state is handed to agentd, the root
daemon, and a read is not. Where a verb runs has the mechanism.
Bringing a new agent online¶
agents add is not a ledger write. In one command it provisions the Linux user, converges
the whole manifest (files, symlinks, units, display), renders the env file, commits the
shard, and starts the unit. No apply follows it.
sudo agentctl agents add assistant --user-email person@example.com --api-key <key>
sudo agentctl agents status assistant # unit, uptime, restarts, mem/cpu, creds, shim
sudo agentctl doctor assistant # the same facts as problems, each with a fix line
Two things it does not do.
It does not log the agent in. A pi agent — the default — boots on a provider API key, and
agents add starts the unit only if that key is already in the store, whether from --api-key
or from an earlier secret set. Without one it enables the unit, leaves it stopped, reports
NEEDS-LOGIN, and names the secret set + agents restart pair that fixes it.
A --runtime claude agent's unit starts with no Claude credentials instead. They arrive later,
from a self-serve OAuth flow on the agent's channel or from the host side:
sudo agentctl login claude assistant # PKCE
sudo agentctl login claude assistant --status # prints logged-in | needs-login
It does not reconcile the gateway host. The shard is committed to /opt/agentctl and —
on any host with an origin — pushed there in the same step. What does not happen is the
other hosts picking it up: a shared gateway renders its routing table from the ledger at
apply time, so the gateway host has to fleet sync && apply before the new agent is
routable (Multi-host fleet).
Adding and removing skills and MCPs¶
Both take effect immediately; neither needs apply. Both also record the per-agent delta in
the shard, so a later apply reproduces the same state — see
Config layering § Membership.
agentctl agents skills list # the catalog plus the default-seeded set
sudo agentctl agents skills add browser assistant # symlinks it in, records the delta
sudo agentctl agents skills add browser '*' # every agent — operator/admin scope only
A skill is a directory the agent reads per turn, so the symlink is the whole change and nothing restarts.
An MCP is a process, and the agent's wiring for it is read once at start:
agentctl mcp catalog list # what is pinned on this host, and its auth mode
sudo agentctl mcp add ynab assistant # installs the runtime, starts the socket unit, wires ~/.claude.json
sudo agentctl agents restart assistant
sudo agentctl mcp remove ynab assistant # detaches; this one prints `restart to apply`
Both halves of the pair need the restart, because the client config is read only at process
start. mcp remove always prints restart to apply: agentctl agents restart <agent>;
mcp add prints it on a pi agent and stays silent on a claude one — restart either way.
mcp add wires the same catalog entry over the same socket on both runtimes; only the client
config file differs (~/.pi/agent/mcp.json on pi, ~/.claude.json on claude). See
MCPs § What mcp add actually does.
An activated MCP with a required_env key absent from the secret store is a doctor FAIL,
not a warning. The agent starts and the tool silently does not.
A ledger change: set records, apply renders¶
agents set writes one scalar into agents.d/<name>.yaml, commits it, and stops. Nothing on
the host has moved yet, and the command prints the one that moves it:
✓ assistant.model = <id> — run agentctl apply assistant to reconcile the runtime.
sudo agentctl agents set assistant model <id>
sudo agentctl apply assistant --dry-run # the plan, including the exact ↻ restart set
sudo agentctl apply assistant # converge, then restart what changed
A bare name after apply is the selector, not a path to an agents.yaml; the two are
told apart by whether the argument looks like a path.
Four settable scalars break the record-then-render rule:
| scalar | what agents set does by itself |
|---|---|
channel, runtime |
runs apply <name> for you — both bake into on-disk unit names that nothing else re-derives |
user_email |
reconciles the web-view gateway's email→agent ledger at once, so the new address is routable without a host-level apply — then still names the apply you owe for the rest |
cost_cap_usd |
writes the value into the agent's env; live on the next turn, subsession or cron tick, with no apply and no restart |
| everything else | records only |
Secrets live in a separate store. Both writing verbs carry a per-agent secret all the way
to the process: they re-render the unit's EnvironmentFile from the store, then restart the
agent if that file actually changed and the unit is currently active.
sudo agentctl secret set ANTHROPIC_API_KEY --agent assistant # value on stdin; --value V also works
sudo agentctl secret remove ANTHROPIC_API_KEY --agent assistant
The gate is the rendered file, not the stored value, and the difference is load-bearing in
three places: re-setting a key to the value it already has still repairs an EnvironmentFile
that had drifted (the obvious thing to try when a secret "did not take"), a recipient-only
re-wrap renders identical bytes and so bounces nothing, and remove genuinely revokes instead
of leaving the deleted value loaded in the running agent until someone runs apply.
A shared secret (no --agent) does neither. apply owns it and secret set does not
say so — run apply yourself. Empty stdin with no --value is refused rather than written,
so a mistyped pipe cannot blank a key.
Cron jobs behave like skills, not like scalars. cron add writes the overlay descriptor,
records the label, and installs and starts the systemd timer inline. The one case that waits
for an apply is a --host cron pinned with --run-on to another machine; that machine
converges it on its own next run. See Crons.
Reading an apply¶
apply streams the reconcile back over the socket as it runs. Before planning anything it
pulls the repo from origin when one is configured — a merge, git pull --no-rebase
--autostash --no-edit. --no-pull reconciles the checked-out tree as-is.
- It is queued. agentd serializes reconciles behind one FIFO ticket. If yours is not
first you get
queued behind N…and then the stream.agentctl queueprints the register —ID STATE VERB CALLER RESULT. Check it first when an unrelated verb appears to hang. - A set of verbs skips that queue. Everything on the converge-exempt list — reaching an
owner (
notify,inject,agent-message,ws write),login, everysubsessionsubcommand,secret get/secret list, the*-gateway statusverbs and the grant and tunnel verbs behindhost shell— takes a per-agent lock with a timeout instead, so none of them waits behind a fleet reconcile. - Ctrl-C cancels the run; it does not detach from it. agentd watches the client connection and cancels the reconcile's context on EOF, which kills its whole process group.
- To detach on purpose, ask for it.
--async(equivalently--no-wait) is stripped client-side and tells agentd to register the job and answerpending (request <id>)without streaming. - To re-attach,
agentctl apply logs. It is answered outside the FIFO, so a second terminal can tail a run it did not start.
On a terminal you get one live line, not the scroll. A full-fleet reconcile emits ~80
✓ <step> lines, which pushes what is happening now off the top of the window, so the human
default is a single in-place progress bar — phase, a determinate meter, the current sub-step,
elapsed. It is rendered by the CLIENT, off the same NDJSON event stream --json prints,
because apply runs inside agentd as a subprocess with no terminal of its own. Four ways back
to the old output, in the order they are checked:
--json |
the raw NDJSON event stream; the bar never appears |
--verbose |
the scrolling ✓ <step> narrative, byte-for-byte what it always was |
AGENTCTL_NO_PROGRESS=1, or TERM=dumb |
the escape hatch for a terminal that redraws badly |
| stdout is not a terminal | automatic — a pipe, a log file or a cron journal gets the scroll, because \r and \033[K would land in it as control bytes |
The bar lights up lazily, on the first progress event, so everything apply prints before
the long part — the plan table, a --dry-run summary, a hidden secret prompt — still prints
the way it always has.
--force reconciles and restarts every agent and gateway regardless of fingerprint. A plain
apply already restarts what changed; --force is the "restart it anyway" override, not the
thorough one. The remaining flags are in
Operations § apply semantics.
Checking a fleet¶
There is no terminal dashboard; the live grid is the cockpit's fleet mini-app. The CLI
answers one question at a time.
agentctl status # THIS host: agents group, slices, MCP sockets, config validity
agentctl agents list # who is on it
agentctl agents status # per agent: unit state, uptime, NRestarts, mem/cpu, creds, shim
agentctl health # the per-agent sweep plus host-level checks, folded into an exit code
agentctl timers # schedule, next fire, last run and result
agentctl creds # per (agent, provider) login health
agentctl usage --days 7 # token and estimated-cost rollup
health exits 1 if anything FAILs and 0 otherwise; WARNs never move the exit code,
so it works as a watchdog signal. It also checks the host itself — the agents group, every
failed agentctl-managed unit, the ledger, and secret-shard recipient drift — which doctor
does not. doctor exits 1 on a FAIL, 2 on a syntactically invalid agent name, and
0 on WARNs or a clean sweep, and prints a fix: line under every finding. health
prints a fix: line for the shard check only; its other host findings carry an inline hint
or none. See Troubleshooting.
Run these as root or as an admin agent. A plain agent gets only its own row, and even that is partial. Credential files are 0600 inside a 0750 home, so a non-root caller is told it cannot read them.
Troubleshooting a stuck agent¶
agentctl doctor assistant # start here
agentctl logs assistant --since '-10 min' # the unit journal, via agentd
agentctl logs assistant -f
sudo agentctl agents restart assistant
If the CLI rather than the agent is what hangs, check agentctl queue before anything else.
Every mutating verb waits on the same FIFO, so one wedged reconcile makes the whole tool look
broken.
Troubleshooting is the ladder from here: what each doctor finding
means, the raw systemd unit, the host-wide failed-unit sweep, journal reads for units
doctor doesn't know about, looking inside the workspace without shelling in, and where a
slow turn's time went.
Taking an agent out of service¶
sudo agentctl agents remove assistant --yes
It stops the units, runs userdel -r, and prunes the agent's timers, sockets and
credentials. Without --yes it refuses with exit 2 after printing what it would destroy. The
home directory is wiped, not archived.
The opposite case — an agent live on this host that the ledger no longer lists, usually after
pulling someone else's deletion — belongs to apply:
sudo agentctl apply --prune # list the orphans
sudo agentctl apply --prune --yes # tear them down
Driving it from an admin agent¶
Everything above works unchanged in an admin agent's own shell, minus the sudo. Three verbs
exist mainly on that route:
agentctl inject <agent>|self <text> # deliver a turn into a live session
agentctl notify <agent>|self|admin <text> [--file <path>] # outbound to the owner, over its channel
agentctl host job run <host> apply # an allowlisted verb on ANOTHER fleet host
inject puts words into a live session as though the owner had typed them. notify sends
words out to the owner over whatever channel that agent has. Both are converge-exempt, so
neither waits behind a reconcile.
host job run crosses hosts through the web-view gateway, not over SSH. The target dialled in,
so it traverses NAT and needs no key on the source. A receipt is persisted on the target before
anything runs, so the job survives an agentd restart and a reconnect. The command prints the
job id, follows automatically, and exits with the verb's real code there. Ctrl-C detaches
without cancelling — resume with agentctl host job logs <host> <job-id> --follow.
Naming an agent rather than a host is the other half: inject <agent> and the whole read
surface reach a peer on any host, spelled exactly as they are locally, and run as that agent's
own uid. See Multi-host § Reaching the rest of the
fleet.
How it works: where a verb runs¶
Every verb takes one of two routes, decided by whether it is classified as mutating:
| route | verbs | how it runs |
|---|---|---|
| mutating | apply, agents add, agents restart, every secret subcommand including get and list |
over the unix socket to agentd, which authorizes the caller by SO_PEERCRED and re-execs the verb as root |
| read-only | status, agents list, queue, timers, mcp catalog list |
in the calling process, no daemon hop |
Two kinds of read still hop the daemon. Cross-agent and fleet-wide reads need root to open
another agent's home. And logs / agents logs are sent to agentd as a unit logs request
for any non-root caller, because an agent's uid is in neither adm nor systemd-journal.
That is where the sudo rule comes from, and the gate is the same one in both cases: a
mutating verb always goes to the socket, and agentd decides, reading the caller's uid off
the kernel with SO_PEERCRED. From a shell that means root. From an admin agent it means an
operator-scope caller, which agentd authorizes and re-execs as root on its behalf — so the
same verb needs no sudo there.
provision is the exception in both directions: it installs agentd, so it never routes
through it, and always runs locally as root.