Blog · Guide
Script coding agents from your shell with zoes session wait
Zoes's zoes command lets you script coding agents from any shell. It can create a session in a new git worktree, send a prompt, read replies and wait for a result. zoes session wait exits 0 when the agent is done, 3 when it failed, 4 when it needs you, 5 on timeout, and 6 if the session closed.
This post is a set of recipes. Every flag and exit code here is in the command reference.
Install the zoes command
zoes is pocketd, Zoes's background service, run under another name. anywhere, the old name, still works too. Sessions it starts show in the desktop app like any other.
- macOS. Open Settings › General, find Command line tool under Startup & background, and click Install. Zoes links
/usr/local/bin/zoesand/usr/local/bin/anywhereto the pocketd inside the app. The button is only in release builds. - Linux. Link
zoesto the pocketd in the unpackedZoesfolder, then install the skill:ln -s "$PWD/Zoes/pocketd" ~/.local/bin/zoes Zoes/pocketd skill install
Installing also writes a skill to ~/.claude/skills/zoes/SKILL.md and ~/.agents/skills/zoes/SKILL.md, which tells Claude Code and Codex how to use the command. Check it from a new terminal outside Zoes:
zoes project list
The command talks to pocketd over ~/.zoes/pocketd.sock. Set POCKETD_SOCK to use another path. If pocketd isn't running, it fails with can't reach Zoes's service at <socket>.
Start a session in a new worktree and send a prompt
From inside your repository:
id=$(zoes session create --new-worktree --base main --provider claude \
--prompt "Fix the flaky login test and run the test suite")
echo "$id"
What happens:
- The command starts a chat session in a new worktree off
mainand prints the session id. - Without
--project, it uses the project whose checkout or worktree holds the current directory. - With
--new-worktreeand no name, pocketd names the branch from the prompt. - With
--prompt, it waits up to 30 seconds for the turn to start. If it doesn't start, the command fails withsession <id> didn't start a turn within 30s, and the session still exists. --accesssets what the agent may do without asking:settings(the default, the agent's own settings),ask,edits,auto, orfull.
--provider takes one of ten ids: claude (the default), codex, cursor, grok, opencode, pi, omp, fx, hermes, or antigravity. Two of them differ from the command they run: cursor runs cursor-agent, and antigravity runs agy.
Follow-up prompts go to the same session. A text argument of - reads standard input, which is handy for piping in context:
zoes session prompt "$id" "Now add a regression test for it"
git log -5 --oneline | zoes session prompt "$id" -
To print the agent's last reply, everything after your last message:
zoes session read "$id"
Wait for a result and branch on the exit code
zoes session wait [--timeout 30m] <id>
session wait waits until the session is no longer Working, then prints one word and exits with its code. --timeout takes a duration such as 90s, 30m, or 2h. The default is 30m.
| Word | Exit code | Meaning |
|---|---|---|
done | 0 | The turn ended. The session is Done, or Idle if someone was looking at it. |
failed | 3 | The turn ended with an error. |
needsYou | 4 | The agent is waiting for an answer or a permission. |
timeout | 5 | The timeout passed first. |
closed | 6 | The session closed. |
Exit code 1 means the command itself failed, and 2 means a bad command line. If the session isn't Working when the command starts, it reports the current state right away. A session that doesn't report its status, such as an agent other than Claude Code or Codex running in a terminal, fails with exit code 1. Sessions that session create starts are chats, and every agent reports its status from a chat.
A complete script: start Codex on a task, wait, and act on the result.
#!/bin/sh
id=$(zoes session create --new-worktree --provider codex \
--prompt "Fix the flaky login test and run the test suite") || exit 1
zoes session wait --timeout 45m "$id"
case $? in
0) zoes session read "$id" ;;
3) echo "agent failed: $id" >&2; exit 1 ;;
4) echo "agent needs you: $id" >&2; exit 4 ;;
5) echo "still working after 45m: $id" >&2; exit 5 ;;
*) echo "session ended: $id" >&2; exit 1 ;;
esac
A Needs you result isn't a dead end. The session waits in the Inbox, with a banner, until you answer it in the app. After you answer, run session wait again to wait for the rest of the turn.
To fan out, start several sessions first and wait on each. They run at the same time; only the waits are in order:
a=$(zoes session create --new-worktree --provider claude --prompt "Migrate the settings page to the new form API")
b=$(zoes session create --new-worktree --provider codex --prompt "Raise test coverage of src/billing")
zoes session wait --timeout 1h "$a"; ra=$?
zoes session wait --timeout 1h "$b"; rb=$?
echo "claude: $ra, codex: $rb"
Tickets from the CLI
The Board is the queue version of the same idea. A ticket is a prompt, an agent, a project, and a base branch. A started ticket waits in Queued until a slot is free, then gets its own worktree and session. The Board runs four at once by default.
zoes ticket create --project app --provider codex --start "Fix the flaky login test"
cat tasks/search.md | zoes ticket create --title "Search index" --start -
zoes ticket list
ticket list shows each ticket's state, which for a started ticket is its session's status. ticket read, ticket update, and ticket delete do the rest. Use tickets when you want to queue more work than should run at once; use session create when you want to wait on a result in the same script.
Scheduled automations vs your own cron
For a prompt on a schedule, Zoes has automations built in: chosen weekdays at a time, or a repeat from every 5 minutes to every 7 days. pocketd starts each run as an ordinary session, keeps firing while the desktop app is closed, keeps a run history, and handles a run that needs you like any other session. No script needed.
Reach for cron, or a CI runner on a machine where Zoes runs, when you want logic around the run: chain steps, act on the exit code, or post the reply somewhere else. A weekday morning job could look like this:
0 9 * * 1-5 cd ~/code/app && /usr/local/bin/zoes session create --new-worktree --prompt "Update dependencies and run the tests" >> ~/agents.log 2>&1
Three things to keep in mind:
- Use the full path to
zoes. Cron'sPATHis usually shorter than your shell's. - pocketd must be running on that machine, because the command talks to its socket.
- Run it from outside Zoes. A process inside a Zoes terminal can only read:
project list,session list,session read, andsession waitwork there, and every other command fails.
Because pocketd owns the sessions, none of this needs the window open. See Keep coding agents running after you close the window. For agents that hand work to each other from a chat, see delegation.
FAQ
Can I start a Claude Code agent from a shell script?
Zoes's zoes command lets you script coding agents from any shell. It can create a session in a new git worktree, send a prompt, read replies and wait for a result. zoes session wait exits 0 when the agent is done, 3 when it failed, 4 when it needs you, 5 on timeout, and 6 if the session closed.
How do I wait for a coding agent to finish in CI or cron?
Run zoes session wait with the session id. It waits until the session is no longer Working, prints one word and exits with its code: 0 for done, 3 for failed, 4 for needsYou, 5 for timeout and 6 for closed. The default timeout is 30m; pass --timeout with a duration such as 90s, 30m or 2h to change it. The command talks to pocketd, so it runs on a machine where Zoes's service is running.
Can agents use the zoes command themselves?
Yes, within limits. Installing the command also installs a skill that tells Claude Code and Codex how to use it. A process inside a Zoes terminal can only read: project list, session list, session read and session wait work there. To have a chat start other sessions, use delegation, which goes through pocketd's orchestrator over MCP.