brain-cli
English | 简体中文
The repo is named brain-cli; the binary command is brain.
brain is a minimalist CLI that acts as a "side brain" for host agents (Claude Code, Codex, DeepSeek Harness, etc.): it calls an LLM gateway via the OpenAI Chat Completions compatible protocol, performs one high-quality advisory/analysis call, and hands the result back to the agent cleanly. The same model reviewing its own conclusions cannot catch its own systematic bias — brain plugs in heterogeneous cross-vendor models as an independent second opinion.
Highlights
- Agent-friendly: stdout carries only the model reply; metadata/warnings/heartbeat all go to stderr. Pipes /
-f multi-file / -i image multimodal input work out of the box; multi-source inputs are wrapped in XML-style tags (<user_message>/<attachment>/<stdin>) for unambiguous context separation
- Model alias routing:
fast / reason / coding / vision aliases plus automatic failover (retry with backoff, switch along the chain, noted on stderr) — agents never memorize model names
- Parallel cross-examination:
brain compare -m a,b -m reason sends the same question to several models at once; replies concatenated under ===== model: X ===== headers (--json gives responses[]). In compare, an alias is a model-group shortcut and each leg does no failover; --blind prints anonymous Model_A/B to guard the adjudicator against brand bias
- Serial debate
brain council: N models discuss one topic over rounds — round 1 goes out blind-parallel (kills first-speaker anchoring), later rounds are serial with a growing transcript so later speakers critique earlier ones (default snake order; --order rotate|fixed changes the layout, --blind anonymizes seats as Model_A/B across prompts and output); the final round states each seat's position, what changed, and unresolved disagreements. Lenses/stances need no syntax: a seat-to-lens table written into the context is the protocol. Seats retry same-model only (a mid-council model swap would be identity fraud); absences are marked, and paid-for speeches survive early termination or SIGINT
- Decisions
brain decide: System One typed judgments — ask a set of yes/no, choice, or score questions about a state and get probabilities plus optional confidence (zero prose); stdout is the jq-ready answers JSON directly. Sub-second at roughly 1/200th of chat pricing. Classification and scoring only (reading order, investigation routing, queue triage) — judgments needing reasoning stay with ask/council; protocol is the TypeSafe wire (/v1/systemone) de-facto standard only; same-model retries, never cross-model failover (calibration baselines must not drift); images ride the --extra-body escape hatch
- Image generation
brain draw: one call, one image, auto-saved. Protocol is inferred from the model name (contains gemini → Gemini native, anything else → OpenAI Images; draw.type overrides); a separate optional draw: config section falls back to your existing base_url/api_key, and --aspect/--res are unified semantics translated per protocol. -i reference images switch to edit mode; --extra-body passes protocol-specific params through (grok's aspect_ratio etc.; top level on openai, merged into imageConfig on gemini). stdout prints exactly the saved file path; --json gives the usual single object. No auto-retry — images are billed per piece
- Optional reasoning effort & output budget:
-e low|medium|high|… and --max-output-tokens N, both passed through as-is (unset = model/gateway defaults; tiers are model-specific — e.g. Zhipu GLM-5.3 only has low/high/max)
- Generic escape hatch
--extra-body / --extra-headers: any request-body field (temperature, response_format, vendor-specific…) and HTTP header passes through as a top-level JSON assign (inline or @file, repeatable and merged in order); reserved keys are rejected to prevent self-sabotage, --dry-run shows the merged result; mirrors OpenAI SDK's extra_body/extra_headers
- Parseable: exit codes 0-7 / 130 with full semantics;
--json always emits exactly one object (jq parses unconditionally; error.code matches the exit code)
- Robust transport: SSE long connection (survives idle-link middleboxes) + in-stream error-event detection (real gateways answer HTTP 200 with a
data:{"error":…} payload) + 15s stderr heartbeat (local progress display, zero network traffic) + one overall budget (retries eat the same deadline) — verified item by item against real one-api-family gateway behavior, not textbook HTTP
- Stateless: multi-turn context is assembled by the caller
- Bilingual UI (zh/en): chosen automatically via
BRAIN_LANG > LC_ALL/LC_MESSAGES/LANG (zh* → Chinese, anything else set → English) > timezone fallback (UTC+8 → Chinese); override any time with BRAIN_LANG=zh|en
- Cross-platform: darwin / linux / windows × amd64 / arm64, released via goreleaser, ~9MB static binary
30-second start
One-line install — paste this to your agent
Install the brain skill for me: https://github.com/icheer/brain-cli
The agent opens the repo and follows the steps below — this part is written for it:
- Place the skill dir: copy (or symlink) the repo's
skills/brain/ directory into the host's skill directory — Claude Code: ~/.claude/skills/brain (user-level) or .claude/skills/brain inside a project; other hosts usually .agents/skills/brain
- Install the binary: run
bash install.sh inside that directory — downloads the platform binary from Releases into the skill dir (SHA256-verified); append --link to also symlink it into /usr/local/bin for direct terminal use
- Self-check: run
brain ping. Without a gateway configured, ping fails with fix hints — at that point have the user run brain init (interactive wizard) or brain config set by themselves in their own terminal: the key is typed by the user straight into a local 0600 file and never travels through the agent chat (conversation transcripts may be retained); never type or request plaintext keys on the user's behalf
The binary is ready in the current session; the skill itself takes effect from the next session. Manual steps below.
brain is BYOK (Bring Your Own Key): it provides no model service itself. You need the address and key of any OpenAI-compatible API — not necessarily a "gateway"; official APIs work directly, for example:
| Service |
base_url |
| OpenAI |
https://api.openai.com/v1 |
| OpenRouter (multi-vendor aggregator) |
https://openrouter.ai/api/v1 |
| DeepSeek |
https://api.deepseek.com/v1 |
| Zhipu |
https://open.bigmodel.cn/api/paas/v4 |
# Install (pick one)
bash skills/brain/install.sh # skill scenario: download the binary into the skill dir from Releases (SHA256-verified)
# append --link to also symlink it into /usr/local/bin (re-running upgrades both),
# or --global to install there only (auto-sudo if not writable)
# Primary upgrade path: just run brain update once installed — it locates the
# skill dir and delegates to install.sh (SKILL.md/installer sync
# included; --check reports versions only; exit codes programmable)
# Windows: run the same script in Git Bash (installs brain.exe; global default ~/bin) or WSL
# Re-running install.sh upgrades in place: it auto-detects your install layout (symlink /
# global / skill-dir) and refreshes SKILL.md from the same release tarball (v0.10.3+)
# Uninstall: bash skills/brain/install.sh --uninstall (removes every installed binary
# and the global link; idempotent; config file and skill docs stay)
# or grab your platform's package from https://github.com/icheer/brain-cli/releases
go install github.com/icheer/brain-cli@latest # developers
# Configure (once; the key lives only in a local 0600 file, never in any repo)
brain init # interactive wizard, or the three lines below:
brain config set base_url https://api.openai.com/v1 # any OpenAI-compatible service
brain config set api_key sk-xxxx
brain config set default_model gpt-5.6 # optional; see config.example.yaml for a full example
# First question
brain ping
brain ask -m fast "introduce yourself in one sentence" # -m also accepts literal model IDs; -e low/medium/high… tunes reasoning effort (optional)
# Multi-model cross-checks — adjudication is always yours (brain ships no built-in judge)
# Parallel: same question to N models at once, replies under ===== model: X ===== headers
brain compare -m reason -f report.md "stress-test the reasoning in this report"
brain compare -m reason -f report.md --json "stress-test the reasoning in this report" | jq -r '.responses[] | select(.ok) | .content'
# Serial debate (council): round 1 blind-parallel, then snake-serial rounds with a growing
# transcript — later speakers critique earlier ones; the final round states each seat's
# position, what changed, unresolved disagreements. Total calls = models × rounds.
brain council -m reason -m coding -f design.md "should this design adopt SQLite for storage"
# Lenses/stances are just context: write a seat-to-lens table via -s. Each seat is told its
# own model ID when it speaks, so it claims the table line that names it — that is the
# whole mapping. One hard rule: the table must spell the RESOLVED model IDs (-m panel
# expands to the chain's IDs — the alias never reaches the seats); everything else
# (separator, wording, layout) is free-form.
brain council -m panel -f design.md \
-s "seat lenses: aihub/gpt-6-astra = security & failure isolation; anti/gemini-3.8-flash = performance & delivery speed" \
"should this design ship as is"
# Decisions (System One typed judgments; stdout = jq-ready answers JSON)
brain config set decide.model jev-latest # once; TypeSafe wire /v1/systemone
brain decide --noul "is_urgent=does this convey urgency" "ticket body…" # yes/no shorthand (repeatable)
brain decide -Q '{"dept":{"type":"choice","criteria":{"billing":"money","technical":"bugs"}}}' "ticket body…"
brain decide --json --noul "q=x?" "state" | jq -r '.answers.q.noul'
# Classification and scoring only (ranking/routing); typed output does not immunize
# against well-typed wrong answers
# Image generation (auto-saves to cwd; stdout = the saved path)
brain config set draw.model gemini-3.1-flash-image # once; draw.base_url/api_key optional (fall back to top-level)
brain draw --res 1K "a cute cat wearing a tiny knitted hat, watercolor style"
brain draw -i cat.jpg "change the hat to red" # reference image -> edit mode
brain draw -m grok-imagine-image-2.0 --extra-body '{"aspect_ratio":"16:9"}' "..." # protocol-specific params
# --aspect 1:1|16:9|9:16|… and --res 1K|2K|4K translate per protocol; no auto-retry (billed per image)
For agents: copy or link skills/brain/ into .claude/skills/ (or .agents/skills/); SKILL.md teaches the host agent when to call brain, how, and when not to.
brain vs. host subagents
Host agents ship their own subagent mechanism (e.g. Claude Code's Task tool): same model, tool access, isolated context. brain complements it rather than replacing it — the crux is "swap in a different brain" vs. "spawn another copy of yourself":
| Dimension |
brain (side-brain CLI) |
host subagent |