# Coding agents (/docs/integration/coding-agents)

> For AI agents, the [documentation index](https://bitrouter-docs-staging.up.railway.app/llms.txt) lists all pages. Append .md to a documentation URL to read its Markdown.

BitRouter separates the **agent harness** that drives the loop from the **model source** that supplies tokens. Connect the agent you already use, then select its BitRouter route in the native model controls. The harness retains its sessions, history, compaction, tools, permissions, and schedules.

## Persistent native connections \[#persistent-native-connections]

> **info**
>
> `bro connect` is documented here from [BitRouter PR #1016](https://github.com/bitrouter/bitrouter/pull/1016), currently a development CLI capability. Use a build containing that command and check `bro connect --help`. These instructions do not establish availability in an older installed binary or replace the separately captured CLI reference.

`bro connect` configures a persistent native provider. No self-driving extension, separate classifier, or BitRouter-managed agent session is required. After setup, open the native application normally and select the connected route.

```bash
bro connect
```

Choose a client in the menu, review the destination files, and confirm the connection. For a local gateway, prepare working inference sources first with [Quickstart](https://bitrouter-docs-staging.up.railway.app/docs/overview/quickstart). Setup can start that local gateway after confirmation. It does not install the native client.

| Client                                                                                              | Direct setup                   | Configuration scope                                             |
| --------------------------------------------------------------------------------------------------- | ------------------------------ | --------------------------------------------------------------- |
| [DeepSeek Harness](https://bitrouter-docs-staging.up.railway.app/docs/integration/deepseek-harness) | `bro connect deepseek-harness` | Selected initialized profiles in one Harness home               |
| [Hermes Agent](https://bitrouter-docs-staging.up.railway.app/docs/integration/hermes-agent)         | `bro connect hermes`           | The selected home/current profile, or explicitly named profiles |
| [OpenClaw](https://bitrouter-docs-staging.up.railway.app/docs/integration/openclaw)                 | `bro connect openclaw`         | One Gateway state root and its agent catalogs                   |
| [OpenCode](https://bitrouter-docs-staging.up.railway.app/docs/integration/opencode)                 | `bro connect opencode`         | One native configuration file                                   |
| [Pi](https://bitrouter-docs-staging.up.railway.app/docs/integration/pi)                             | `bro connect pi`               | One Pi agent directory                                          |

These five adapters add an independent BitRouter provider and retain existing startup defaults. Select BitRouter in the native picker after the required reload. Codex and Claude are also available in the connector menu; their client-specific configuration and restoration differ.

BitRouter is the provider; Automatos is its default router model. The default gateway wire ID is `bitrouter/automatos`. `--model` chooses another exact ID already advertised by the target gateway's `/v1/models`; it does not create a model, strategy, or alias. Display labels and native selection IDs can differ from the wire ID, as described in each client guide.

### Connect an existing gateway \[#connect-an-existing-gateway]

For Cloud or another existing gateway, supply its root URL or `/v1` URL and its gateway credential. For example, after replacing the model placeholder with an exact ID advertised by your Cloud endpoint:

```bash
export BITROUTER_API_KEY='your-bitrouter-gateway-key'
bro connect hermes --base-url https://api.bitrouter.ai \
  --model 'exact-advertised-model-id' --dry-run
bro connect hermes --base-url https://api.bitrouter.ai \
  --model 'exact-advertised-model-id'
```

The explicit endpoint path configures the native client without reading a local BitRouter config or starting a daemon. Remote URLs require HTTPS; HTTP is allowed on loopback. The saved gateway credential is separate from upstream provider keys. For unattended writes, choose an explicit client and add `--yes`.

The default `bitrouter/automatos` must also be advertised before setup succeeds. Availability depends on the chosen gateway configuration and deployment. A callable selector that is absent from `/v1/models` does not pass this connector's catalog check.

### Request context and routing \[#request-context-and-routing]

The connected client sends its normal model request: the selected wire ID, submitted conversation context, and supported tool declarations/results. BitRouter can apply the selected route to that request. The harness determines what is submitted after its own context loading and compaction.

Persistent connection does not export the complete native session store or install a lifecycle observer. It does not itself configure tool permissions, context-profile switching, automatic approvals, or workload learning. Optional self-driving extensions have a separate host-side resource-management role and are not prerequisites for model routing.

### Strategies and workflows \[#strategies-and-workflows]

Define model combinations and routing behavior in BitRouter using [Strategies](https://bitrouter-docs-staging.up.railway.app/docs/routing/strategies) and [Virtual Models](https://bitrouter-docs-staging.up.railway.app/docs/models-routing/virtual-models). Select a registered gateway route through the harness's own agent, profile, session, or job model settings. The harness remains the owner of those workflow bindings.

For these five independent-provider clients, repeat `--model` to register an ordered collection of exact advertised selectors under one provider. The first retains the existing primary alias/display-name behavior; additional entries use their exact IDs as labels. Duplicate IDs and conflicting native keys are refused. Setup and `--check` validate every ID. Codex and Claude retain their single-model connector contract.

For example, if the gateway advertises both IDs, register them together:

```bash
bro connect hermes --model bitrouter/automatos --model team/background
```

Then choose a registered route in the native workflow settings. Hermes' cron defaults/per-job pins and OpenClaw's per-job model overrides remain harness-owned; `bro connect` does not provide a workflow-binding wizard or rewrite those settings. See the [Hermes](https://bitrouter-docs-staging.up.railway.app/docs/integration/hermes-agent#chat-and-scheduled-work) and [OpenClaw](https://bitrouter-docs-staging.up.railway.app/docs/integration/openclaw#agent-and-automation-routes) guides.

A label such as `background` or `flex` does not activate an inference type. The selected gateway must implement the intended policy and support its model/protocol requirements. See [Inference Types](https://bitrouter-docs-staging.up.railway.app/docs/market/inference-types) for the market capacity types.

### Manage a connection \[#manage-a-connection]

For these five independent-provider clients, replace `hermes` with the intended client and retain any custom `--instance`:

```bash
bro connect hermes --dry-run
bro connect hermes --status
bro connect hermes --check
bro connect hermes --update
bro connect hermes --remove
```

* `--dry-run` previews files and effects without starting a daemon or writing configuration.
* `--status` checks saved configuration offline. `--check` also verifies the exact gateway model using the saved credential. Neither submits inference or tool calls, and neither proves that a running client has reloaded.
* `--update` replaces the managed provider. Supplying model flags replaces the complete selector list; omitting them preserves it. Supply the full remaining list to drop a selector. Other omitted settings retain the saved connection; an omitted key is reused only for an unchanged endpoint. An update can restore the earlier native startup selection, so reselect BitRouter afterward if desired.
* `--remove` removes owned settings and restores earlier selections only where the connected model is still selected. Later unrelated preferences remain. Saved job/session bindings are not migrated when routes are removed, so change those bindings in the native harness as needed. Edits to owned fields are conflicts to resolve before retrying.

Close config-writing clients during updates or removal. Private connection receipts contain restoration data and credentials; keep them private. For Desktop/Web attached to a different backend, configure that backend on its own host. Each client guide describes reload requirements and state outside the connector's ownership.

After a catalog check, verify inference separately: select BitRouter in the native client, send a small request, exercise any required tool roundtrip, and inspect [request receipts](https://bitrouter-docs-staging.up.railway.app/docs/cli/request-receipts). Native default context/cost metadata is not proof of route capacity, actual pricing, or model quality.

## Choose the interface \[#choose-the-interface]

| Goal                                               | Command                 | Interface owner                                        |
| -------------------------------------------------- | ----------------------- | ------------------------------------------------------ |
| Add a persistent native provider (development CLI) | `bro connect <client>`  | Native client configuration; BitRouter gateway routing |
| Run one turn from a script                         | `bro run <agent> "..."` | BitRouter, headless                                    |
| Use the harness's own terminal UI                  | `bro launch <agent>`    | The harness                                            |
| Let another ACP client launch the adapter          | `bro acp serve <agent>` | The ACP client                                         |

```bash
bro codex
bro run claude "Review the current diff" --format quiet
bro launch opencode
```

`bro connect` changes persistent native configuration. `bro run` and `bro acp serve` use ACP adapters. `bro launch` starts the harness's native interface with process-local routing overrides and leaves normal harness configuration in place. These are separate capabilities; connecting or launching a native client does not create a BRO Goal.

The captured [command reference](https://bitrouter-docs-staging.up.railway.app/docs/usage/cli#bro-code) documents the released ACP conversation interface. Check native launch and ACP connectivity separately for the adapter and version you use.

## Supported agents \[#supported-agents]

Run `bro agents list` for the catalog shipped by your installed version. Alpha.31 includes local ACP adapters for Claude, Codex, Gemini CLI, OpenCode, Pi, Hermes, and OpenClaw.

| Friendly id  | ACP adapter  | Native launch                       |
| ------------ | ------------ | ----------------------------------- |
| `claude`     | `claude-acp` | `bro claude` or `bro launch claude` |
| `codex`      | `codex-acp`  | `bro codex` or `bro launch codex`   |
| `opencode`   | `opencode`   | `bro launch opencode`               |
| `pi`         | `pi-acp`     | `bro launch pi`                     |
| `hermes`     | `hermes-acp` | `bro launch hermes`                 |
| `openclaw`   | `openclaw`   | `bro launch openclaw`               |
| `gemini-cli` | `gemini-cli` | ACP only in the bundled catalog     |

Use `bro agents check <agent>` before a long task. It verifies that the adapter can initialize and reports whether its model traffic can be routed through BitRouter.

## What launch changes \[#what-launch-changes]

See [bro \[harness\]](https://bitrouter-docs-staging.up.railway.app/docs/integration/bro-harness) for the shared setup workflow, launch configuration, and command options.

For Claude and Codex, BitRouter passes temporary environment variables or command-line overrides. For OpenCode, Pi, Hermes, and OpenClaw, it writes a generated profile under the working tree's self-ignoring `.bitrouter/launch/` directory and points only the child process at it.

```bash
bro launch pi --model bitrouter/auto
bro launch codex --check
bro launch claude -- --permission-mode plan
```

Arguments after `--` belong to the harness. BitRouter options such as `--model`, `--base-url`, and `--check` must come before it.

Supported native harnesses also receive the aggregate [MCP gateway](https://bitrouter-docs-staging.up.railway.app/docs/routing/configuration#agents-and-mcp) when they expose a compatible injection mechanism. The launch summary states what was actually routed or injected; Pi and some other harnesses do not expose an MCP injection surface.

## Other harnesses \[#other-harnesses]

If a harness is not in the catalog, configure it as a normal API client:

| Protocol             | Local base URL             | Cloud base URL                |
| -------------------- | -------------------------- | ----------------------------- |
| OpenAI-compatible    | `http://127.0.0.1:4356/v1` | `https://api.bitrouter.ai/v1` |
| Anthropic-compatible | `http://127.0.0.1:4356`    | `https://api.bitrouter.ai`    |

Use a `provider/model` id where the harness accepts a model name. Product-specific configuration keys belong to that harness's documentation; BitRouter only owns the endpoint and routing contract.

## Claude Code \[#claude-code]

Claude Code owns the agent loop and tools. BitRouter supplies its model route, fallback, policy, and metering.

### Pick a mode \[#pick-a-mode]

```bash
bro run claude "Summarize this repo"   # headless ACP turn
bro claude                              # Claude Code's native interface
```

`bro launch claude` is the generic spelling of `bro claude`. Both use temporary environment variables for the child process and do not edit Claude Code's user or project settings.

Before launching, verify the executable, daemon, and route:

```bash
bro launch claude --check
```

If the Claude executable is missing, the launcher can offer Claude's official installer. Use `--no-install` when an automated environment should fail instead.

### Select a Claude model \[#select-a-claude-model]

Pin a daemon-routable model before the `--` separator:

```bash
bro claude --model bitrouter/auto
bro launch claude --model anthropic/claude-sonnet-4-6
```

Arguments after `--` go directly to Claude Code:

```bash
bro launch claude -- --permission-mode plan
```

### Configure Claude Code manually \[#configure-claude-code-manually]

Use manual environment variables only when Claude Code must start outside `bro launch`. Claude Code appends `/v1/messages`, so the base URL is the host root:

```bash
export ANTHROPIC_BASE_URL=http://127.0.0.1:4356
export ANTHROPIC_AUTH_TOKEN=local-placeholder
export ANTHROPIC_MODEL=bitrouter/auto
claude
```

For Cloud, use `https://api.bitrouter.ai` and set `ANTHROPIC_AUTH_TOKEN` to a BitRouter key. An authenticated self-hosted daemon likewise requires a valid BitRouter key instead of the placeholder.

### Use a Claude subscription \[#use-a-claude-subscription]

Use [BYOK & Subscriptions](https://bitrouter-docs-staging.up.railway.app/docs/models-routing/byok-subscriptions#use-a-claude-subscription) for login, explicit subscription routes, and logout. The subscription source is independent of the harness interface.

## Codex \[#codex]

Codex owns the agent loop and tools. BitRouter supplies its model route, fallback, policy, and metering.

### Pick a mode \[#pick-a-mode-1]

```bash
bro run codex "Summarize this repo"   # headless ACP turn
bro codex                              # Codex's native interface
```

`bro launch codex` is the generic spelling of `bro codex`. It injects a temporary `bitrouter` model provider into the child process and does not edit `~/.codex/config.toml`.

Verify the executable, daemon, and route before a long run:

```bash
bro launch codex --check
```

### Select a Codex model \[#select-a-codex-model]

Pin a daemon-routable model with BitRouter's option:

```bash
bro codex --model bitrouter/auto
bro launch codex --model openai/gpt-5-codex
```

Arguments after `--` go directly to Codex. Avoid forwarding Codex `-c` or `--config` overrides that replace the injected provider; `bro launch` rejects known conflicting shapes.

### Configure Codex permanently \[#configure-codex-permanently]

Use a permanent provider block only when Codex must start outside `bro launch`:

```toml
model_provider = "bitrouter"

[model_providers.bitrouter]
name = "BitRouter"
base_url = "http://127.0.0.1:4356/v1"
wire_api = "responses"
# env_key = "BITROUTER_API_KEY"
```

For Cloud, use `https://api.bitrouter.ai/v1`, set `env_key = "BITROUTER_API_KEY"`, and export a BitRouter key. An authenticated self-hosted daemon requires the same.

> **warning**
>
> Codex model-provider configuration belongs in the user-level `~/.codex/config.toml`. Project-local Codex configuration does not define model providers.

### Use a Codex subscription \[#use-a-codex-subscription]

Use [BYOK & Subscriptions](https://bitrouter-docs-staging.up.railway.app/docs/models-routing/byok-subscriptions#use-a-codex-subscription) for login, explicit subscription routes, and logout. The subscription source is independent of the harness interface.

## Model sources \[#model-sources]

A model source is where inference runs and how it is authenticated. BitRouter puts each source behind the same model ids and routing policy, so the calling agent does not need source-specific code.

| Source                       | Authentication                     | Setup                                                                |
| ---------------------------- | ---------------------------------- | -------------------------------------------------------------------- |
| Claude or Codex subscription | Provider OAuth                     | `bro providers login <provider>`                                     |
| Built-in BYOK provider       | Environment variable or stored key | Export its key or use `bro providers login <provider> --api-key ...` |
| Custom hosted API            | API key                            | Add a `providers:` entry                                             |
| Local inference server       | Usually loopback; optional key     | Add a `providers:` entry                                             |

Subscription providers do not need a YAML block. Other sources use the same minimal shape:

```yaml
providers:
  my-source:
    api_base: https://example.com/v1
    api_key: ${MY_SOURCE_API_KEY}
    api_protocol:
      - "*": chat_completions
    models:
      - id: example/model
```

Use the upstream's actual served model id in `models`. Keep secrets in environment variables rather than committing them to the file.

### Verify a source \[#verify-a-source]

```bash
bro config validate
bro models --provider my-source
bro route my-source:example/model
bro start
```

* `config validate` catches malformed configuration and unsafe upstream URLs.
* `models` confirms the source is in the resolved catalog.
* `route` previews resolution without making an inference request.
* The provider-qualified form pins one source; the bare model id lets BitRouter select among every source that serves it.

To combine sources, define a [virtual model](https://bitrouter-docs-staging.up.railway.app/docs/models-routing/virtual-models#define-a-virtual-model) or fallback chain. A common pattern is local inference first and a hosted source second.

* [Local Models](https://bitrouter-docs-staging.up.railway.app/docs/models-routing/local-models) — Connect Ollama, vLLM, Unsloth, or another OpenAI-compatible server.

* [BYOK & Subscriptions](https://bitrouter-docs-staging.up.railway.app/docs/models-routing/byok-subscriptions) — Add a hosted API or provider account with a key.

* [Run & Inspect](https://bitrouter-docs-staging.up.railway.app/docs/cli/run-inspect) — Operate the router and inspect routed requests.

* [ACP command reference](https://bitrouter-docs-staging.up.railway.app/docs/usage/cli#agents-acp-and-mcp) — Inspect adapter commands and their options.