🎬 New — watch the 2-minute guide videos →
Documentation

BharatRouter Code (brcode)

brcode is a Codex-/Claude-Code-style coding agent CLI, routed through BharatRouter. One br- key drives six harnesses; your org's profile (default model, MCP connectors, rules) follows every teammate with a single command; and everything a coding agent does is metered, budgeted, and audited on the gateway.

This is the full guide. For the short pitch see the product page; for the HTTP endpoints behind the CLI see the API reference. Migrating? From Codex · from Claude Code — and read Context & memory for what carries over.

Install

Homebrew (macOS / Linux):

brew install bharatrouter/tap/brcode

Or one line (no Homebrew):

curl -fsSL https://bharatrouter.com/install/brcode.sh | bash

Both give you brcode (and the br alias). The engine (OpenCode, MIT) is installed on first brcode init; Node is the only prerequisite (Homebrew installs it for you). Update with brew upgrade brcode. Windows: use WSL.

Quickstart

brcode login   # browser opens, key lands in the CLI — zero paste
brcode init    # engine + your org's profile (model, MCP connectors, rules)
brcode         # start coding

That's the whole onboarding — init pulls the org profile from GET /v1/me/profile, so a new teammate inherits the lead's exact setup. A lead pushes their local setup up with brcode export.

Command reference

CommandWhat it does
brcodeLaunch the agent (runs init first if needed). brcode "fix the failing test" passes a prompt straight through.
brcode loginZero-paste login: opens the browser, catches the key on a localhost loopback (paste fallback). Key stored 0600 at ~/.config/bharatrouter/env.
brcode initInstall the engine, pull the org profile, write configs, smoke-test the route.
brcode export(Leads) push your local model + MCP connectors to the org profile. Connector definitions carry env-var names only — never secret values.
brcode doctorReachability, key, and routing checks — run this first when anything misbehaves.
brcode modelList or switch the default model (persisted; applies to every harness). Includes Sangam consensus variants.
brcode routeRouting collections: pick a preset (cost / speed / reliability / quality / auto), auto-build a provider failover chain from live route health, or build a custom weighted chain. Every collection is probed live before it's saved.
brcode sangamConsensus routing — list Sangam variants or set one as your model.
brcode alertsRoute-health + spend warnings (also shown on the launch splash).
brcode usageOrg spend/requests/tokens with per-model and per-agent breakdowns — the enterprise audit view.
brcode logsLocal per-machine tool-use audit (written by the default PostToolUse hook).
brcode identityPer-machine agent identity: on / off / revoke / status / budget <₹|off>. See below.
brcode sandboxon / strict / off / status — contain what the agent can touch. See below.
brcode memoryEdit this repo's AGENTS.md (mirrored to CLAUDE.md) — shared context for every harness.
brcode ideWire the agent into Zed (ACP), VS Code, JetBrains, Continue, or any editor via ide watch.
brcode claudeSwitch harness: launch the real Claude Code CLI, routed through BharatRouter.
brcode aider|goose|crush|qwenMore harnesses — same key, same gateway, same routing.
brcode agents|commands|hooks(Re)install the default subagents (@review, @explore), the in-agent slash commands, and the hooks plugin.
brcode acpRun as an ACP stdio server (what brcode ide zed wires up).

Per-launch overrides: BHARATROUTER_MODEL=glm-4.7 brcode wins for one session; BRCODE_FULL=1 restores the engine's full TUI.

In-agent commands & shortcuts

Slash commands (typed inside the running TUI): /login, /doctor, /brprofile. The engine's leader key is ctrl+x:

KeysAction
ctrl+x n / ctrl+x lNew session / list sessions
ctrl+x mModel list — switch models mid-chat (brcode bakes the full catalog in)
tab / shift+tabCycle agents (e.g. the @review, @explore subagents)
ctrl+pCommand palette
escapeInterrupt the agent
ctrl+x hToggle help/tips
ctrl+cExit

Full list: OpenCode keybinds. Other harnesses (brcode claude etc.) keep their own native keymaps.

Harnesses — one key, your choice of agent

HarnessLaunchBest for
OpenCode (default engine)brcodeCodex-style TUI; subagents, skills, hooks, themes — the most deeply integrated path.
Claude Codebrcode claudeIf you already live in Claude Code — it's the real CLI, just BR-routed. Your skills and CLAUDE.md keep working.
Aiderbrcode aiderGit-native pair programming; also powers brcode ide watch (edit-comment triggers from any editor).
Goosebrcode gooseBlock's agent; session-based workflows.
Crushbrcode crushCharm's TUI agent.
Qwen Codebrcode qwenGemini-CLI lineage.

Harness choice is launch-time; the model is switchable everywhere (persisted via brcode model, mid-chat via the TUI model list). All harnesses share the same repo context (AGENTS.md) and the same gateway-side governance.

Agent identity & ₹ budgets

brcode identity on          # this machine codes as its own agent (agt_…)
brcode identity budget 500  # cap it at ₹500/month
brcode identity status      # spend + cap per agent
brcode identity revoke      # kill-switch: every live token dies

With identity on, each coding session swaps the shared org key for a short-lived per-agent token (minutes-long ES256 JWT — nothing durable to leak). You get per-agent ₹ attribution in brcode usage and on the dashboard, one-command revocation, and per-agent monthly budgets: once a capped agent exhausts its ₹, its calls are denied with 429 agent_budget_exceeded until you raise or clear the cap. No identity infrastructure to stand up — BharatRouter provisions everything behind the scenes.

Sandbox

brcode sandbox on      # project-scoped policy
brcode sandbox strict  # + macOS OS-level write-jail
brcode sandbox status
  • on — permission rules pinned into the engine config: paths outside the project ask first; sudo and rm -rf on / or ~ are denied; git push asks. Everything else flows.
  • strict — every edit/command/fetch asks, and on macOS the engine runs inside a Seatbelt profile that physically cannot write outside the project directory, temp, and its own caches — even a call that slips past policy can't touch your dotfiles or ~/.ssh. Linux stays policy-only for now.

Scope: the OpenCode engine (brcode, brcode acp). Other harnesses keep their own native permission systems (Claude Code's permission modes, etc.). Reads are not jailed in v1 — policy still asks on external paths.

Context & memory — what carries, what doesn't

The question everyone asks when switching tools. The honest breakdown:

LayerWhere it livesCarries over?
Repo contextAGENTS.md (+ mirrored CLAUDE.md) in the repo, edited via brcode memoryYes, fully — travels with git; every harness reads it, exactly like Codex and Claude Code.
Org rules & connectorsOrg profile on the gateway (/v1/me/profile)Yes — one brcode init per machine pulls it.
Skills~/.config/opencode/skills/, project .opencode/skills/, and ~/.claude/skills/Yes — Claude Code skill packs are read unchanged.
Chat historyPer-harness session store (e.g. ~/.local/share/opencode)No — chat sessions never cross harnesses, the same as switching between Codex and Claude Code today. Finish or summarise long-running threads (paste the summary into AGENTS.md) before switching.

So: durable context (repo memory, rules, skills, connectors) carries; ephemeral conversation state doesn't — and never did, in any of these tools.

Config files

FileWhat
~/.config/bharatrouter/envYour br- key (0600). Never committed, never in IDE settings.
~/.config/bharatrouter/configPersisted settings (model, route, identity, sandbox mode). Precedence: process env > this file > org profile > default.
~/.config/opencode/opencode.jsonEngine config brcode manages: provider → BharatRouter, model catalog, theme, MCP connectors, permission block (sandbox).
~/.config/opencode/hooks.jsonClaude-Code-style PreToolUse/PostToolUse rules — a PreToolUse non-zero exit blocks the tool. Project override: .opencode/hooks.json.
./AGENTS.md · ./CLAUDE.mdRepo memory (mirrored pair) — see Context & memory.

Troubleshooting

  • Start with brcode doctor — it checks the engine, key, and live routing in one shot.
  • HTTP 000 / timeouts on a corporate network — a TLS-inspecting proxy (Zscaler and friends) may block api.bharatrouter.com; doctor flags this. Ask IT to exempt the domain.
  • Rotated your key? brcode login again. A running session keeps its startup credentials — restart brcode to pick up the new key.
  • "agent_budget_exceeded" — this machine's identity hit its monthly cap: brcode identity budget 1000 to raise, or off to clear.
  • Agent stuck at BUILD / "Bad Gateway" on a Sangam model — a consensus ensemble (bharatrouter/auto, sangam, open-sangam, glm-sangam) can't arbitrate tool calls, which coding agents need on every step. The gateway now serves a tool-bearing request on a single tool-capable GLM instead (the x-br-auto-delegate response header names it), so agents just work. If you still see this, the gateway predates the fix — brcode model default switches you to the org-default model.
  • Engine updatesbrcode init is idempotent; rerun it any time to repair configs.

Not affiliated with OpenAI ("Codex") or Anthropic ("Claude Code" / "Claude"). Built on OpenCode (MIT); Aider, Goose, Crush and Qwen Code are independent open-source projects — brcode launches your installed copy, routed through BharatRouter.