Co-Agent
Use the bundled script. Do not edit co-agent registry, goal, run, segment, prompt, handoff, result, or status files directly.
LLM Role
- Resolve the current agent with
whoami --from <agent>when the user gives an identity; otherwise usewhoamionly if the cwd is registered. - Register or update named agents only when the user provides or confirms their cwd.
- Before substantive work in a registered cwd, if the request may be outside the current agent's responsibilities, run
route --task <original request> --json. - If
routereturnsaction=handoff, create a handoff torecommended_agent; if it returnsaction=handle_here, continue locally; if it returnsaction=ask, ask the user instead of guessing. - When the target agent is not explicit and
routeis insufficient, inspectlist-agents --jsonresponsibilities before choosing who should own the work. - Before
handoff,return,retry, orunblock, runchat-candidatesfor the resolved target agent. Pass--session <thread_id>when one candidate clearly matches the work; otherwise explicitly pass--last. - Start a goal or create a handoff through the script; let the script create
run_id,segment_id, handoff files, prompt files, and JSONL evidence. - After handoff, if this agent needs the target business result before continuing, run one
wait --timeout <realistic seconds>; the script polls every 5 minutes by default, so do not use a 60-second process-exit timeout here. - Do not manually poll
status/resultin a loop. Ifwaittimes out, inspectstatusonce and decide whether to extend the wait or ask the user. - The first
from_agentin a goal is its top-from agent. After every started target in the current round has returned through the existing hierarchical result flow, the top-from agent enters final monitoring: callprocess-monitorevery 30 seconds until it printsALL CLEARED. The script gives each business-terminal process 60 seconds to exit naturally before cleanup. Do not continue task work or create another handoff while it printsWAITING. Intermediate agents do not perform this polling. - Use
wait,result,history, orstatusto answer completion and audit questions. - Summarize script output to the user.
Script Entry
COAGENT="${CODEX_HOME:-$HOME/.codex}/skills/co-agent/scripts/coagent.sh"
"$COAGENT" register "agent name" --cwd <dir> [--role <text>] [--alias "short name"] [--owns <text>] [--not-for <text>] [--update]
"$COAGENT" rename-agent "old agent name" "new agent name" [--alias "short name"]
"$COAGENT" list-agents [--json]
"$COAGENT" resolve "agent name" [--json]
"$COAGENT" resolve-cwd <cwd> [--json]
"$COAGENT" chat-candidates [--agent "agent name"|--cwd <dir>] [--limit N] [--json]
"$COAGENT" whoami [--from "agent name"] [--json]
"$COAGENT" route [--from "agent name"] --task <original request> [--json]
"$COAGENT" start-goal --title <title> --owner "agent name"
"$COAGENT" handoff --goal <goal_id> --from "agent A" --to "agent B" --context <file> --requested-outcome <text> (--session <thread_id>|--last) [--run <run_id>|--new-run] [--foreground] [--no-wake]
"$COAGENT" finish --run <run_id> --segment <n> --state finished|blocked|failed --summary <text> [--result <file>]
"$COAGENT" return --run <run_id> --segment <n> --summary <text> (--session <thread_id>|--last) [--to "upstream agent"]
"$COAGENT" retry --run <run_id> --segment <n> (--session <thread_id>|--last) [--reason <text>]
"$COAGENT" unblock --run <run_id> --segment <n> (--session <thread_id>|--last) [--reason <text>]
"$COAGENT" process-monitor --goal <goal_id> --from "top-from agent"
"$COAGENT" wait --run <run_id> [--segment <n>] [--timeout <seconds>]
"$COAGENT" result <run_id> --segment <n> [--json]
"$COAGENT" status <goal_id|run_id> [--json]
"$COAGENT" history <goal_id|run_id> [--json] [--tree]
Behavior
- Agent name matching is case-insensitive and ignores repeated whitespace.
rename-agentmigrates the registry key and display name while preserving cwd, role, and responsibilities. If--aliasis supplied, it replaces the old alias list.resolve-cwdreturns the registered agent with the longest cwd prefix match; callers should fall back to the original cwd when there is no match.- Short names are explicit aliases. Prefer role-based aliases such as
backend agent,documentation agent, ortest agent; do not rely on substring guessing. - Agent responsibilities are routed by
ownsandnot_for: if a task is outside the current agent'sowns, inspect other agents and hand off to the owner. Handoff prompts and history use the snapshot recorded when the segment was created. routeis a conservative dispatch helper over registered aliases,owns,not_for, and role text. Treataction=handoffas permission to hand off; treataction=askas ambiguous ownership.agents.jsonrecords agent-level identity only: name, aliases, cwd, role, and responsibilities. Session-level title/thread data lives in${CODEX_HOME}/coagents/chat_candidates.json.chat-candidatesreads chat_manager-maintained candidates for an agent cwd, validates thread ids against chat_manager, filters archived/mismatched sessions, and sorts by sessionupdated_atdescending.- Every
handoff,return,retry, andunblockmust explicitly pass exactly one of--session <thread_id>or--last, including--no-waketests. --sessionaccepts only a currently validated candidate for the target agent. Missing selection or an invalid session fails before workflow state is written and prints the valid candidates; there is no implicit fallback to--last.- If
handoffhas no active run and no--runor--new-run, it creates a run automatically. handoffwakes the explicitly selected target session in the background, prints run/segment/result/status paths, and returns. Use--foregroundonly when the caller explicitly needs to wait forcodex execitself to exit.- Use
wait --run ... --segment ...to wait for segment completion, andresult <run_id> --segment <n>to read the latest result directly. status --jsonincludes the latest summary, result path, result excerpt, and wake notes.--no-wakeis for local skill testing: it writes the same evidence files but recordswake_skippedinstead of starting Codex.segments.jsonlis the authoritative evidence ledger.status-SEGNNN.jsonis a generated view.- State is written under
${CODEX_HOME:-<skill-root-parent>}/coagentsunlessCOAGENT_HOMEis set. In restricted Codex sandboxes, the first write may require an approved escalation or an approvedcoagent.shcommand prefix. COAGENT_SEED_REGISTRYmay point to an optional initial registry. No personal or project registry is bundled with the skill.
Read references/design.md only when changing the skill implementation or resolving a state-machine ambiguity.