beetlebug▾
/

Use jcode from a coordinator session

A coordinator is often an AI session, such as Claude Code, that runs shell commands. This guide shows the commands that it uses: start, wait, ask, send, interrupt, read, and cost. Each prints short, plain text, and read --json prints JSON.

The examples use the fake provider (fake:FILE), so they run with no model and no cost. The file has one reply of the model for each turn:

[{"tools":[{"name":"ask_coordinator","input":{"question":"Shall I also add a --help option?"}}]},
 {"text":"I run the slow test.","tools":[{"name":"run","input":{"command":"sleep 120"}}]},
 {"tools":[{"name":"finish","input":{"report":"Added --help. The slow test was stopped."}}]}]

Start and wait

jcode start --dir fk --model fake:$PWD/fk/fake.json --brief brief.md --isolation none --run all
jcode wait a5 --timeout 10
a5
a5 asks none turns 1/40 tokens 120 (in100 out20 cr0 cw0) fake:fk/fake.json fk | asks: Shall I also add a --help option?

wait returns when the state is not running. The end of the line has the question or the reason. A coordinator runs wait in a loop, or runs it in the background and does other work.

Answer a question

jcode ask a5
printf 'Yes.\nKeep it short.\n' | jcode send a5 -
Shall I also add a --help option?
a5 running none turns 1/40 tokens 120 (in100 out20 cr0 cw0) fake:fk/fake.json fk

ask prints the full question. send ID TEXT sends a message; - reads the text from the standard input, for a long answer or one with quotes. send also makes an agent in the state done, stalled, or failed go on.

Stop a command

jcode interrupt a5
jcode wait a5 --timeout 10
jcode read a5 --since 2
a5 running none turns 2/40 tokens 240 (in200 out40 cr0 cw0) fake:fk/fake.json fk
a5 done none turns 3/40 tokens 360 (in300 out60 cr0 cw0) fake:fk/fake.json fk | the agent gave its report
3 user: coordinator: Yes. Keep it short.
4 agent: I run the slow test.
5 tool: run {"command":"sleep 120"}
6 state: interrupt: the coordinator stops the running command
7 result: fail: exit 137 stopped by the coordinator
8 report: Added --help. The slow test was stopped.

interrupt kills the command that the agent runs now, with its process group. The agent gets the result "stopped by the coordinator" and goes on. stop ID ends the agent.

Read only the new entries

read ID --since N prints the entries after N. A coordinator keeps the last number that it read:

jcode read a5 --since 7 --json
{"state":"done","last":8,"entries":[{"n":8,"t":1796324373454,"kind":"report","text":"Added --help. The slow test was stopped."}]}

tail ID follows the transcript and prints each new entry. It runs until the agent is capped or stopped.

Rules for a coordinator