Codex Subagent Orchestrator
Overview
Use this skill to run codex exec workers asynchronously, keep persistent state per job, and orchestrate large batches without blocking the current Codex app conversation.
The orchestrator now emits structured end-of-run artifacts per job so model/runtime metadata is reportable and reproducible.
Defaults for Model and Reasoning
- •Default model: infer from current session env when available (
CODEX_SESSION_MODEL,CODEX_MODEL,OPENAI_MODEL), otherwise fall back to~/.codex/config.tomlmodel. - •Default reasoning effort: infer from session env when available, otherwise
~/.codex/config.tomlmodel_reasoning_effort. - •Override at spawn time:
- •
--model <name> - •
--reasoning-effort <low|medium|high|...>
- •
Runtime Projection Input (Required for Smart Auto-Wait)
wait --interval-mode auto no longer guesses from prompt size. The orchestrating model must provide an explicit runtime projection when spawning jobs:
- •
--projected-runtime-seconds <seconds>forspawn - •
projected_runtime_secondsper task (or batch default) forbatch
Recommended TPS anchors for projection planning:
- •Codex family: ~70 tokens/second
- •Codex Spark family: ~1000 tokens/second
End-of-Run Artifact Contract
Each completed job can generate artifacts.json containing:
- •Model details: requested, effective, source
- •Reasoning effort: requested, effective, source
- •Context limit:
context.limit_tokensand source - •Token usage breakdown: input, cached input, output, reasoning output, total
- •Duration:
run_duration_seconds - •Paths: logs, final message, check-ins
How to generate/report:
- •Launch with JSON event logging enabled (default):
- •
spawnandbatchdefault to--json-events
- •
- •Wait for completion with artifact emission (default):
- •
wait ...emits artifact summary lines and writesartifacts.json
- •
- •Read full report:
- •
python3 "<path-to-skill>/scripts/subagent_fleet.py" artifacts <job-id> --json
- •
Wait Strategy (Adaptive or Event-Driven)
Avoid tight fixed polling loops by default:
- •
wait --interval-mode auto(default)- •Uses only model-provided runtime projections from spawn/batch metadata.
- •If projections are missing, falls back to base interval behavior (no prompt-size heuristics).
- •
wait --interval-mode event- •Uses filesystem notifications (kqueue on macOS) to wake on job-dir updates.
- •Falls back gracefully if event backend is unavailable.
- •
wait --interval-mode fixed --interval N- •Use only when deterministic polling cadence is required.
Status check-ins are recorded by default to <job-dir>/status_checkins.tsv.
Quick Start
- •Verify environment:
- •
python3 "<path-to-skill>/scripts/subagent_fleet.py" doctor
- •
- •Launch a worker with explicit model controls:
- •
python3 "<path-to-skill>/scripts/subagent_fleet.py" spawn --label "schema-audit" --cwd "/path/to/repo" --model "gpt-5.3-codex" --reasoning-effort "medium" --full-auto --sandbox workspace-write --prompt "Audit schema drift and report findings only."
- •
- •Wait (event-driven) and collect artifacts:
- •
python3 "<path-to-skill>/scripts/subagent_fleet.py" wait --interval-mode event <job-id> - •
python3 "<path-to-skill>/scripts/subagent_fleet.py" artifacts <job-id> --json
- •
Workflow
- •Define independent prompts that can run in parallel.
- •Launch each unit with
spawnor submit many at once withbatch. - •Track health with
listand inspect one job withstatus. - •Use
wait(autooreventmode) to complete with minimal polling overhead. - •Read
artifacts.jsonfor model/context/tokens/duration/check-ins. - •Aggregate each
final_message.txtinto a parent synthesis.
Command Guide
spawn
Launch one async subagent and return immediately.
- •Prompt input:
--prompt,--prompt-file, or stdin pipe - •Model/runtime controls:
- •
--model - •
--reasoning-effort - •
--context-limit-tokens(optional explicit report value) - •
--projected-runtime-seconds(model-provided runtime estimate for auto wait cadence)
- •
- •Other controls:
- •
--cwd,--profile,--sandbox,--full-auto - •
--dangerously-bypass-approvals-and-sandboxrequires explicit--allow-dangerous - •
--add-dir(repeatable) - •
--env KEY=VALUE(repeatable)
- •
batch
Launch many jobs from JSON or JSONL.
- •Required:
--file <tasks.json|tasks.jsonl> - •Supports per-task overrides for model/reasoning/context-limit/projection
- •Tasks that set
dangerously_bypass_approvals_and_sandboxare rejected unlessbatch --allow-dangerousis set - •Throttling:
- •
--max-running N - •
--intervalfor throttling checks - •
--launch-intervalpause between launches
- •
- •See task schema:
references/task-file-format.md
list / status
- •
listshows fleet overview with duration and effective model - •
status <job-id>shows metadata and can include artifact summary
logs
- •
logs <job-id> --stream stdout|stderr --lines 80 - •Add
--followfor live tail while running
wait
- •
wait <job-id ...>for targeted jobs - •
waitwith no ids tracks all known jobs - •Defaults:
- •Adaptive/event-aware wait strategy
- •Status check-ins enabled
- •Artifact generation enabled
artifacts
- •
artifacts <job-id>prints final execution report - •Add
--jsonfor machine-readable output
cancel
- •
cancel <job-id ...>to stop specific workers - •
cancel --allto stop all running workers - •
--force-after <seconds>escalates from SIGTERM to SIGKILL
doctor
Check codex binary availability, state-dir health, and default model/reasoning sources.
Operational Notes
- •Default state root is
.codex-subagentsunder current working directory. - •Each job writes
meta.json, logs, prompt, final message, completion markers, and check-ins. - •
artifacts.jsonis generated from run metadata + JSON event logs. - •If context limit is not discoverable from logs and not provided explicitly, artifact value is
nullwith sourceunknown. - •Prefer
wait --interval-mode eventorautofor long tasks to avoid aggressive polling.