Docs
Architecture
Three processes and a directory of files. The brain is the only component that holds policy.
Pieces
- Terminal. TUI that asks the brain which leg should answer. Bare prompts included.
- Brain. Go service on loopback (127.0.0.1:14097). Director plan, value ranking, dispatch, assess, record.
- Runtimes. opencode serve for remote models, or vendor CLIs (claude -p, codex exec, cursor-agent -p) as subprocesses.
- Files. ~/.captaincode/ holds the ledger, run logs, registry overlay, priors, and per-folder state.
One task, end to end
- Triage. Deterministic class and domain heuristics, with a lightweight model check when confidence is low.
- Route. Routine tasks use value ranking; high-complexity tasks and explicit team requests can use a director plan.
- Fit the prompt. Prune deterministically, summarise only if still over budget, re-attach the first instruction.
- Dispatch. An opencode session pinned to the project directory, or a vendor CLI subprocess.
- Watch. First-event, idle, and stall timers plus a hard cap.
- Handle failure. Eligible provider failures can reroute; useful partial output is preserved and labeled instead of blindly rerunning. Rate limits, outages and harness faults are recorded separately.
- Record. One ledger line and one scorecard update.
Value ranking
value(leg, class) = w_q·quality/10 − w_c·cost/cost_ref − w_l·latency/lat_ref
Candidates must clear a quality bar τ for the class. Cost and latency are normalised against absolute references. Subscription legs carry pressure inferred from observed rate limits instead of price. This is not an exact remaining-quota meter. If no candidate clears the bar, the implementation can fall back to a configured ladder.
Workspaces
One brain serves every terminal on the machine. Each terminal is open in one folder (workspace). Workers run there; that folder's activity feed and loops are the ones its sidebar shows. Leg cooldowns and the scorecard are shared: a rate limit is per account, not per folder.
OpenAI-compatible surface
captain brain exposes /v1/chat/completions where the model id is a leg name. Anything that can talk to an OpenAI endpoint can drive it. Control surfaces (/team, /parallel, /repeat, /context, /oss, /deterministic, /btw, /interrupt, /captain) are intercepted before dispatch. /btw <note> posts out-of-band to /v1/btw and steers a running turn via the Steer handle for claude (stdin stream-json) and opencode legs (session merge); unsupported legs receive it as the next turn. /interrupt stops the in-flight worker and keeps a handoff or marked partial. /oss and /deterministic narrow the worker pool (open weights, or ADI-green serving tuples with OpenRouter pin); see ADI. Bare user prompts use Captain’s routing path; routine turns can skip the director model.