| 1 | # Run other agents in Codewhale |
| 2 | |
| 3 | > [简体中文](zh_hans/OTHER_AGENTS.md) |
| 4 | |
| 5 | An external-agent session runs on an agent CLI installed on the computer |
| 6 | hosting Codewhale. Codewhale keeps the thread, transcript and approval |
| 7 | history; the other agent runs the turn and uses its own account, model and |
| 8 | tools. Codewhale connects over [Agent Client Protocol (ACP)](https://agentclientprotocol.com/) |
| 9 | when available and can fall back to direct non-interactive CLI mode (`cli`) for |
| 10 | `antigravity` (`agy`), `claude`, `codex`, and `grok` (or custom CLI entries) |
| 11 | when no ACP adapter is installed. |
| 12 | This is not a Codewhale provider or sub-agent. To connect an editor **to** |
| 13 | Codewhale instead, see [Codewhale as an ACP agent](RUNTIME_API.md#acp-stdio-adapter-codewhale-serve---acp). |
| 14 | |
| 15 | ## Install and sign in |
| 16 | |
| 17 | 1. Install an agent on the computer that runs Codewhale, not just on the |
| 18 | device you connect from. See the |
| 19 | [agent registry](../crates/engine/src/fleet/agents.rs) for recognized agents, |
| 20 | minimum versions and upstream install links. |
| 21 | 2. Sign in or configure a model in the agent's own CLI. For example, run |
| 22 | `opencode auth login` for OpenCode. A provider key saved in Codewhale is |
| 23 | not passed to the other agent. |
| 24 | 3. Make sure the agent executable is on the server's `PATH`. For Claude Code, |
| 25 | Codex or Muse Code, install the corresponding ACP adapter on `PATH` for full |
| 26 | ACP transport. When an ACP adapter is not installed, `antigravity` (`agy`), |
| 27 | `claude`, `codex`, and `grok` still run via direct CLI transport without |
| 28 | downloading an adapter. Codewhale does not download either executable. |
| 29 | |
| 30 | For Google personal accounts, use Antigravity CLI. The Gemini CLI entry can |
| 31 | discover an existing installation with supported access. [Google account migration](https://developers.google.com/gemini-code-assist/docs/deprecations/code-assist-individuals) |
| 32 | |
| 33 | | Agent | Install the adapter | |
| 34 | | --- | --- | |
| 35 | | Claude Code | `npm i -g @agentclientprotocol/claude-agent-acp` | |
| 36 | | Codex | `npm i -g @agentclientprotocol/codex-acp` | |
| 37 | | Muse Code | `npm i -g @bex-co/muse-code-acp` | |
| 38 | |
| 39 | ## Start a session |
| 40 | |
| 41 | ### From the terminal |
| 42 | |
| 43 | Open `/model` in the TUI to choose either a Codewhale model or an installed external ACP agent under **Other agents (ACP)**. Agents that are installed but not ready show why (for example, a missing adapter or older version) alongside their sign-in command. |
| 44 | |
| 45 | For scripts or direct launch, pass `--agent <id>` (and optionally |
| 46 | `--agent-transport <acp|cli>` to pin the transport): |
| 47 | |
| 48 | ```bash |
| 49 | codewhale --agent opencode |
| 50 | codewhale --agent claude --agent-transport cli |
| 51 | codewhale exec --agent opencode "Summarize this project without changing files." |
| 52 | codewhale exec --agent claude --agent-transport cli --output-format stream-json "Summarize this project." |
| 53 | ``` |
| 54 | |
| 55 | ## Configure custom external agents |
| 56 | |
| 57 | In addition to `CODEWHALE_CUSTOM_ACP_AGENTS`, you can declare custom external |
| 58 | agents in `config.toml` using `[[external_agents]]`: |
| 59 | |
| 60 | ```toml |
| 61 | [[external_agents]] |
| 62 | id = "local-agent" |
| 63 | name = "Local agent" |
| 64 | binary = "local-agent" |
| 65 | args = ["acp"] |
| 66 | transport = "acp" |
| 67 | website = "https://example.com/local-agent" |
| 68 | ``` |
| 69 | |
| 70 | Set `transport = "cli"` for a direct non-interactive CLI wrapper. Entries in |
| 71 | `CODEWHALE_CUSTOM_ACP_AGENTS` override `[[external_agents]]` entries with the |
| 72 | same `id`. |
| 73 | |
| 74 | ## Use external agents in Fleet workers |
| 75 | |
| 76 | Fleet profiles (`[fleet.profiles.<name>]`) and Fleet task specs (`worker`) can |
| 77 | pin an external agent and optional transport: |
| 78 | |
| 79 | ```toml |
| 80 | [fleet.profiles.claude-reviewer] |
| 81 | slot = "reviewer" |
| 82 | role = "reviewer" |
| 83 | external_agent = "claude" |
| 84 | external_agent_transport = "cli" |
| 85 | ``` |
| 86 | |
| 87 | Task-level `worker.external_agent` and `worker.external_agent_transport` |
| 88 | override profile-level values. External-agent workers bypass Codewhale's native |
| 89 | provider-model catalog check (the external agent owns its own models), honor |
| 90 | read-only authority via `--permission-mode plan`, and stream structured |
| 91 | `stream-json` progress and terminal receipts back into the Fleet ledger. |
| 92 | |
| 93 | ### From the Runtime API |
| 94 | |
| 95 | You can also start the session directly through the Runtime API. In a Bash shell |
| 96 | inside the project folder, start the local server. Keep the token private. |
| 97 | |
| 98 | ```bash |
| 99 | export CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)" |
| 100 | codewhale app-server --http --host 127.0.0.1 --port 7878 & |
| 101 | server_pid=$! |
| 102 | |
| 103 | base=http://127.0.0.1:7878 |
| 104 | api() { curl -sS --fail-with-body -H @<(printf 'Authorization: Bearer %s\n' "$CODEWHALE_RUNTIME_TOKEN") "$@"; } |
| 105 | # Run after the server has started. |
| 106 | api "$base/v1/agents/external" |
| 107 | ``` |
| 108 | |
| 109 | The helper hands curl the header through a file descriptor, so the token never |
| 110 | appears in a command line that other users could read in the process list. It |
| 111 | needs bash or zsh and curl 7.55 or newer. |
| 112 | |
| 113 | To list another installed ACP agent, export `CODEWHALE_CUSTOM_ACP_AGENTS` |
| 114 | in the shell that starts Codewhale. Give it a JSON array of commands. Each |
| 115 | entry needs a unique `id`, a display `name` and a `binary` on PATH or at an |
| 116 | absolute path. Put command arguments in `args` as separate strings. |
| 117 | For example, `[{"id":"local-agent","name":"Local agent","binary":"local-agent","args":["acp"]}]` |
| 118 | adds a local command to discovery. Keep credentials in the agent's own login. |
| 119 | |
| 120 | Pick an `id` whose row says `"runnable": true`. This confirms discovery, not |
| 121 | sign-in. The example below uses OpenCode and `jq` to build the JSON safely, |
| 122 | including when the project path contains spaces. |
| 123 | |
| 124 | ```bash |
| 125 | agent=opencode |
| 126 | thread=$(api "$base/v1/threads" -H 'Content-Type: application/json' \ |
| 127 | -d "$(jq -n --arg workspace "$PWD" --arg agent "$agent" \ |
| 128 | '{workspace:$workspace, permission_posture:"ask", executor:{kind:"acp", agent_id:$agent}}')") |
| 129 | thread_id=$(jq -er .id <<< "$thread") |
| 130 | api "$base/v1/threads/$thread_id/turns" -H 'Content-Type: application/json' \ |
| 131 | -d '{"prompt":"Summarize this project without changing files."}' |
| 132 | api -N "$base/v1/threads/$thread_id/events" |
| 133 | ``` |
| 134 | |
| 135 | The event stream stays open for updates. Stop watching with Ctrl+C; this does |
| 136 | not cancel the turn. Inspect the turn and any pending approvals at |
| 137 | `GET /v1/threads/{id}`. To answer a pending approval, send `{"decision":"allow"}` |
| 138 | or `{"decision":"deny"}` to `POST /v1/approvals/{approval_id}`. To cancel a |
| 139 | running turn, use `POST /v1/threads/{id}/turns/{turn_id}/interrupt`. |
| 140 | Stop the server when done with `kill "$server_pid"`. To reopen a session, |
| 141 | restart the server with the same Codewhale and agent state and call |
| 142 | `POST /v1/threads/{id}/resume` with the saved thread ID. |
| 143 | |
| 144 | Leave the model unset to use the agent's default. To pick a model when an |
| 145 | agent offers that choice, query `GET /v1/agents/external/{id}/options?cwd=...` |
| 146 | with the URL-encoded absolute project path and set `executor.config.model` |
| 147 | to the agent's offered value when creating the thread. It is not a Codewhale |
| 148 | model ID. |
| 149 | |
| 150 | ## What Codewhale controls |
| 151 | |
| 152 | - **Approvals:** Ask displays requests the agent sends through ACP. If an |
| 153 | agent has its own allow rules, it may act without sending a request. |
| 154 | Codewhale does not sandbox the agent's tools. Configure permissions in the |
| 155 | agent itself and only run agents you trust. |
| 156 | - **Resume:** Codewhale reopens the same agent session when the agent supports |
| 157 | ACP resume or load. Otherwise it reports that it cannot reopen the session; |
| 158 | it does not start a replacement. |
| 159 | - **Limits:** External sessions do not support steering, compaction, forks, |
| 160 | image input or per-turn model changes through Codewhale. Usage is shown only |
| 161 | when the agent reports it; Codewhale does not know the cost. |
| 162 | |
| 163 | ## If the agent won't start |
| 164 | |
| 165 | | Code | What to do | |
| 166 | | --- | --- | |
| 167 | | `not_installed` | Install the CLI and check the server's `PATH`. | |
| 168 | | `adapter_missing` | Install the required ACP adapter and check the server's `PATH`. | |
| 169 | | `below_min_version` | Update the CLI to the version shown or newer. | |
| 170 | | `no_acp` | Check the CLI or adapter version and whether it can start in ACP mode. | |
| 171 | | `needs_sign_in` | Sign in through the agent's own CLI, then retry. | |
| 172 | |
| 173 | For request fields, permission policies and events, see the |
| 174 | [Runtime API contract](RUNTIME_API.md#sessions-on-other-agents-external-agent-threads). |
| 175 |