devin-subagent
# devin-subagent
An MCP server that makes [Devin](https://devin.ai) a native subagent for **Claude Code** and **Codex**: the lead agent starts a Devin session with one tool call, waits with one long call, and gets Devin's last message back verbatim, even if the connection to Devin drops in between.
- **Keyless by default.** Talks to the Devin CLI over ACP (`devin acp --cloud`, or `devin acp --process-model in-process` for local runs) and uses your existing `devin` login. No API key is needed.
- **Status from the session itself.** `session/list` gives the status, `session/load` replays the history to read the last message without starting a turn.
- **Rules layer.** Every task gets "push only to your own branch, only once at the end" and "the first line of the last message is `SORU:` or `BİTTİ:`". Branches must start with `devin/`. Pushes outside the prefix are reported as `VIOLATION` (never reverted).
> **Note:** Devin makes commits and pushes under the identity of the Devin account owner (the user logged in to the `devin` CLI), not under the identity of whoever runs Claude Code or Codex.
## Requirements
- Node.js 20 or newer.
- The Devin CLI on `PATH`, logged in (`devin` must work in a terminal). Run `devin` once and log in if needed.
- `git` on `PATH` (for the remote-branch comparison).
## Install
There are two install paths: the Claude Code plugin (nothing to build), or a manual MCP setup for Claude Code or Codex from a local build.
### 1. Claude Code plugin via the marketplace (zero steps)
```text
/plugin marketplace add MrMerkus/devin-subagent
/plugin install devin-subagent@devin-subagent
```
Or, from a local checkout: `claude --plugin-dir ./plugin`.
The plugin ships the compiled server as a single file, so nothing is built or downloaded at install time and no `node_modules` are needed. The plugin contains:
- `plugin/.mcp.json`: the MCP server, started as `node ${CLAUDE_PLUGIN_ROOT}/server/index.js`. The marketplace entry's `source` is `./plugin`, so `${CLAUDE_PLUGIN_ROOT}` is the installed copy of the `plugin/` directory.
- `plugin/server/index.js`: the bundled MCP server (built from `src/` with `npm run bundle`).
- `plugin/agents/devin.md`: a thin `devin` agent whose only tools are this MCP server's tools. Use it as `subagent_type: "devin"`.
The agent's model is `haiku` by default. To change it, edit `model:` in `agents/devin.md` (for example `sonnet`, or `inherit` to use the lead's model), or copy the file to `.claude/agents/devin.md` in your project and edit it there.
The agent does not summarize: the MCP writes the result to `sonuc.md` and the agent returns that path plus Devin's last message verbatim. If Devin asks a question (`question`) or ends its turn without a marker (`idle`), the agent ends its report with `SORU:` and stops (it adds no extra `SORU:` line when Devin's message already starts with one). When you name a model, the agent always passes it to `devin_run`; "same model" means the model named earlier. Wake it with `SendMessage`; it forwards your answer with `devin_message` and waits again.
### 2. Manual MCP setup (Claude Code or Codex)
Build a local checkout:
```sh
git clone https://github.com/MrMerkus/devin-subagent.git
cd devin-subagent
npm ci && npm run build
```
Claude Code (use the absolute path of your checkout):
```sh
claude mcp add --scope user devin -- node /abs/path/devin-subagent/dist/index.js
```
Codex: see [Codex](#codex) below.
### Permissions
Allow the MCP tools without prompting, in `.claude/settings.json` (or `~/.claude/settings.json`). This also avoids the auto-mode "Unsanctioned Communication" denial that was observed in a real run when the lead sends messages to Devin. See `plugin/permissions.example.json`:
```json
{
"permissions": {
"allow": ["mcp__plugin_devin-subagent_devin", "mcp__devin"]
}
}
```
`mcp__plugin_devin-subagent_devin` covers the plugin install, `mcp__devin` covers `claude mcp add devin`.
`devin_wait` blocks for up to `wait_default_seconds` (600 s). If your client's MCP tool timeout is shorter, raise it (Claude Code: `MCP_TOOL_TIMEOUT` in milliseconds) or pass a smaller `seconds`.
### Codex
After the build above, add to `~/.codex/config.toml` (use the absolute path of your checkout):
```toml
[mcp_servers.devin]
command = "node"
args = ["/abs/path/devin-subagent/dist/index.js"]
startup_timeout_sec = 60
# devin_wait blocks for minutes; keep this above wait_default_seconds.
tool_timeout_sec = 900
```
## Known limitations
- `devin_run` has no base-branch field yet. Put the base branch in the task text (for example "start from branch `main`").
- `acu_cap` is advisory in ACP mode: `devin acp` may ignore it and keep the account's own limit (see [Configuration](#configuration)).
- The npm registry package is not published yet; install with the plugin or from a local build.
## Tools
| Tool | What it does |
| --- | --- |
| `devin_run(task, mode, model?, repo, branch, schema?, acu_cap?, pre_command?)` | Starts a session and returns in one response: `id`, `url`, `model`, `branch`, `push_permission`, `result_path`, `acu_cap`, `max_acu_limit`, `acu_cap_note`. `model` is checked against `devin models` (unknown names are rejected), passed as `devin acp --model <model>`, and the reported `model` is the one the session says it uses. `pre_command` is prepended to the task as "first run this" (the MCP does not set up the environment). `mode` is `cloud` or `local`; local runs are sequential (a lock). |
| `devin_wait(id, seconds?)` | Blocks until the status changes (default 600 s) and returns it with the branch tip, VIOLATION lines and the last message. Disconnects are retried internally; when the retry cap is exceeded the result is `error`. |
| `devin_status(id)` | Read-only: status and last message. Sends nothing to the session. |
| `devin_message(id, text)` | Sends a message (e.g. the answer to a `SORU:`). The session keeps its own model. |
| `devin_stop(id)` | Cancels the current turn and waits (up to 5 s) for Devin to end it; `cancel_confirmed` says whether it did. |
| `devin_list(mode?, limit?)` | Recent sessions with a coarse status. |
Statuses:
| Status | Meaning |
| --- | --- |
| `running` | Devin is working (the report includes the current tip of the branch). |
| `question` | The last message starts with `SORU:`, the session has a pending request, or the listing has `userActionRequired` (e.g. `Answer question`, reported as `user_action_required`). |
| `idle` | The turn finished and the last message has no marker (full text returned). |
| `done` | The turn finished and the last message starts with `BİTTİ:`. A push alone never means done. |
| `error` | The session failed, or the connection could not be re-established within the cap. |
| `stopped` | Stopped with `devin_stop`. |
How the status is decided, in order:
1. The `session/list` `_meta` says the turn is over: `statusEnum` is `finished`, `error`, `stopped` or `blocked` with no `pendingRequest`, or `sessionStatus` is `suspended` or `finished`. This wins over a prompt that still looks in flight, because in cloud mode the `session/prompt` response can be lost when the connection drops. A prompt left in flight this way is dropped (and a local lock released).
2. The transcript is loaded with `session/load` and the last agent message decides: `BİTTİ:` is `done`, `SORU:` or a non-null `userActionRequired` is `question`, anything else is `idle`. `done`, `question` and `idle` are never returned without the message: if the history has no final agent message yet (it can lag behind the listing), or the last agent message is older than the last prompt, the history is loaded again with backoff (1 s, doubling up to `poll_interval_seconds`) until the wait window ends, and then the result is `running` with `timed_out: true`.
A history that does not show the last prompt yet counts as stale (`running`) only for 120 s after the prompt and only while the listing's `updatedAt` is not later than the prompt, so a cloud history that omits a prompt cannot keep a session `running` forever.
3. Otherwise the session is `running`: a prompt is in flight, `currentActivity` is set (read from `session/list` and from `session/update` `_meta["cognition.ai/session"]`), or `statusEnum` has another value. Unknown values and fields are tolerated.
Real traces after a finished turn showed `statusEnum: "blocked"` with `currentActivity: "finish_executing_actions"`, and later `sessionStatus: "suspended"` with `statusEnum: "finished"`. The `running` and `question` signals are still inferred.
VIOLATION: a branch outside `branch_prefix` that appeared or moved between the start and the end of the run. It is reported, never reverted, and labelled "possibly by another actor" because the remote does not say who pushed. Deleted branches are not reported. When the remote cannot be read, the result says `remote_check: "unavailable"` with `remote_check_error`, and `violations` is `null` (not checked).
`devin_wait` and `devin_status` return two content blocks: a JSON report, then the last message verbatim. The same information is written to `<state_dir>/results/<id>/sonuc.md`; for `done`, `question` and `idle` it contains Devin's last message verbatim.
## Configuration
Optional JSON file at `$DEVIN_SUBAGENT_CONFIG`, else `$XDG_CONFIG_HOME/devin-subagent/config.json` (default `~/.config/devin-subagent/config.json`). All keys are optional:
```json
{
"backend": "acp",
"devin_command": ["devin"],
"acu_cap": 10,
"bypass_approval": false,
"branch_prefix": "devin/",
"default_model": null,
"poll_interval_seconds": 15,
"wait_default_seconds": 600,
"wait_max_seconds": 3600,
"request_timeout_seconds": 120,
"reconnect": { "max_attempts": 5, "max_seconds": 300, "initial_backoff_ms": 1000 },
"state_dir": "~/.local/state/devin-subagent",
"task_rules": []
}
```
- `acu_cap`: default ACU cap; `devin_run(acu_cap)` overrides it. In ACP mode it is advisory: it is sent as `cognition.ai/maxAcuLimit` in `session/new` `_meta`, but `devin acp` has been seen to ignore it and keep the account's own limit. The MCP does not enforce a cap itself. `devin_run` and the reports return the session's effective `max_acu_limit` as reported by Devin, and `acu_cap_note` says whether it matches `acu_cap`.
- `bypass_approval`: when `false` (default), permission requests from Devin are always answered with a reject option.
- `repo` must be an `https://` or `ssh://` URL, `user@host:path`, `owner/name` or an existing local directory. Values starting with `-` and transport helpers such as `ext::` are rejected, and git runs with `-c protocol.ext.allow=never` and `--` before the remote.
- `branch_prefix`: `devin_run` rejects branches that do not start with it; pushes to other branches are reported as `VIOLATION`.
- `task_rules`: extra rule lines appended to every task.
- `state_dir` (or `$DEVIN_SUBAGENT_STATE_DIR`): run records, `sonuc.md` files and the local-run lock.
### API v3 backend (optional, not implemented in v0.1)
`"backend": "api"` selects the Devin API v3 backend, which needs `DEVIN_API_KEY` in the environment. The key is only read from the environment and is never written to any file. In v0.1 this backend is only an interface: every tool returns a "not implemented" error. Enabling it depends on the maintainer's approval.
## How it works
- Transport: JSON-RPC 2.0 over the `devin acp` child process's stdio, one JSON object per line. `initialize` needs no login step (`authMethods: []`).
- `devin_run`: records the remote branch heads (`git ls-remote --heads`), then `session/new` + `session/prompt` with the task and the rules. The prompt runs in the background.
- `devin_wait`: polls `session/list` (cheap) and reads `cognition.ai/statusEnum`, `currentActivity` and `pendingRequest`. Only when the turn looks finished, it calls `session/load` (which replays the whole history and is not called in a tight loop) to read the last `agent_message_chunk`, then compares the remote branch heads with the ones recorded at the start.
- Requests from Devin to the client are always answered: permission requests with a reject option (or `cancelled`), anything else with JSON-RPC error `-32601 "not supported"`.
## Development
```sh
npm ci
npm run build
npm test
```
After changing `src/`, run `npm run bundle` to rebuild the plugin's single-file server (`plugin/server/index.js`, built with esbuild) and commit it. `npm test` fails when the committed bundle is stale.
The tests never start the real `devin`: they run against `test/fake-acp.mjs`, a fake ACP agent that speaks the same protocol over stdio and keeps its sessions in a state file so they survive restarts (like cloud sessions survive a dropped connection).
## License
MIT, see [LICENSE](LICENSE).
TDQS
Scored across 6 tools
Each tool maps to a distinct action in the session lifecycle (start, block-wait, snapshot status, list, message, cancel), and the descriptions explicitly contrast the overlapping pair devin_wait vs devin_status (blocking vs read-only). The wait/status distinction still requires careful reading and is the one place misselection is plausible.
All tools share a predictable `devin_` prefix and are short snake_case, which is easy to scan. Minor deviations: most are verbs (wait, run, list, message, stop) but `devin_status` is a noun, and `devin_list` omits its object (sessions).
Six tools is a tight, well-scoped set for orchestrating a single subagent session: launch, observe, converse, and cancel. No tool appears redundant or gratuitous.
The start/monitor/message/stop lifecycle is fully covered, including both blocking and non-blocking observation. Minor gaps: no way to fetch the full transcript or diff/branch contents, and `devin_list` only gives coarse status.