## Problem
With workflows on (`CLAUDE_CODE_WORKFLOWS=1`), the prompt fails when a
workflow agent asks for permission while the main agent's turn is open:
```text
RequestError: Internal error: Claude ended the turn without returning results for tool calls: toolu_…
data: { errorKind: "incomplete_tool_call" }
```
Seen in a client running workflows in default mode: the main agent
starts a background workflow and keeps working, a workflow agent runs a
quick Bash command after the user allows it, and the main agent's turn
then ends with this error. The workflow itself finishes fine.
## Cause
Claude Code calls `canUseTool` for a workflow agent with an `agentID`
that no `task_started` announces. The workflow's own `task_started`
names the Workflow call, and the agent's tool_use and tool_result never
stream on the root query. `toolUseOwner` finds no parent (the adapter
logs "No parent tool_use recorded for subagent a…; sending the Bash
permission request unattributed"), so `ensureToolCallEmitted` sees no
`parentToolUseId` and the root session id, and records the call as the
turn's foreground work:
```ts
if (!parentToolUseId && notificationSessionId === sessionId && toolName !== "SandboxNetworkAccess") {
recordForegroundToolCall(session, toolCallId);
}
```
The call is still open when the turn's result arrives. The permission
path also recorded it as dispatched, so `settleActive` counts it as
stuck and fails the prompt. A command that runs a few seconds gets a
`task_started`, and `registerLiveTask` forgets the call, so only quick
commands hit this.
## Fix
`ensureToolCallEmitted` takes `canUseTool`'s `agentID`, and a call with
an `agentID` is not recorded as foreground work:
```ts
if (!agentID && toolName !== "SandboxNetworkAccess") {
recordForegroundToolCall(session, toolCallId);
}
```
`toolUseOwner` finds a parent or a child session only for a set
`agentID`, so the two dropped conditions are implied by `!agentID`, and
the result changes only for a subagent with neither. That is a workflow
agent, or a Task subagent whose request beats its `task_started`; the
latter's call was already unlisted by its streamed frame.
`foregroundToolCallIds` feeds only the end-of-turn check. Both callers,
the permission request and the AskUserQuestion elicitation, pass
`agentID`.
v2 is not affected: it never fails a turn for an open tool call, and it
emits a permission's tool call early only for SandboxNetworkAccess.
## Tests
- `v1/incomplete-tools.test.ts`: "does not claim a workflow agent's
permission tool as a foreground tool". The stream is what the CLI sends:
a Workflow tool_use, its `local_workflow` `task_started` and launch
result, then the agent's `canUseTool` with an `agentID` no
`task_started` announced, then the result. It fails without the fix with
"Claude ended the turn without returning results for tool calls:
unfinished-bash".
- `npm run check`, `npm run build` and `tsc --noEmit` pass. `npm run
test:run`: 4179 passed, 36 skipped, 1 failed. The failure is
`acp-scenarios.test.ts` "replaces only the version of this adapter and
the path of this Node binary", which fails the same way on `main` on my
machine.
- Real repro: an ACP client spawning the adapter with Claude Code
2.1.325, default mode, permissions allowed after 1.5s. The main agent
starts a workflow whose one agent runs `date > stamp.txt; cat
stamp.txt`, then goes on with its own work:
| Build | Main turn ends | Result |
| --- | --- | --- |
| `main` (7d9e1f6) | ~27s after the workflow's command | failed 2/2 |
| this branch | ~27s after the workflow's command | clean 4/4 |
| `main` (7d9e1f6) | ~1s after the command is allowed | failed 3/3 |
| this branch | ~1s after the command is allowed | clean 3/3 |
0.101.1 fails the same way (2/2), and this change alone makes it clean
(2/2).
## Not covered
- The workflow agent's tool call still never closes in the client:
nothing streams its result on the root query. That was already the case
when the main turn ended before the request. A probe shows the adapter's
PostToolUse hook does fire for it, with the call's `tool_use_id`, its
`agent_id` and `agent_type: "workflow-subagent"`, so a follow-up could
close it from there.
- The "No parent tool_use recorded" log now fires on every workflow
agent's request, not only on a lost race with `task_started`. Its
comment says so; it is still only `logger.log`.
- `npm run test:integration` was not run.
Related: #1501 hits the same check through the same eager permission
call, for a root `confirm_<uuid>` question with no `agentID`. This PR
does not change it.
Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
ACP adapter for the Claude Agent SDK
Use Claude Agent SDK from ACP-compatible clients!
This tool implements an ACP agent by using the official Claude Agent SDK, supporting:
- Context @-mentions
- Images
- Tool calls (with permission requests)
- Compact file changes through the negotiated AIR diff patch extension
- Following
- Edit review
- TODO lists
- Nested subagent transcripts
- Interactive (and background) terminals
- Custom Slash commands
- Client MCP servers, including the ones that the client serves over the ACP connection (MCP-over-ACP,
"type": "acp") - An Ultracode session config option, which turns on Claude Code's dynamic workflows for every task. It appears when dynamic workflows are enabled and the model supports ultracode (any model with
xhigheffort) /mcpin the chat: the MCP server status as a list. The adapter runs/mcp reconnect,/mcp enable, and/mcp disablethrough the SDK control API, because Claude Code refuses them in SDK mode. A reconnect of an ACP server that needs authentication starts MCP OAuth through URL elicitation- Session-scoped long-running goals for AIR through the goal extension under
_meta.jetbrains.air.goal - Structured errors, recovery, and warnings through the opt-in session failure extension
- Concrete model and effort defaults through the opt-in recommended config value extension
- Tool permission presentation, editable choices, and durable effects through the permission extension
- One fact per field in every tool call report, as the ACP tool call contract defines
- All AIR extensions, capabilities, and
_metakeys: AIR extensions
Learn more about the Agent Client Protocol.
To try changes that have landed on main but are not released yet, install from the
preview channel — every push to main publishes one. See
docs/RELEASES.md.
npm install @agentclientprotocol/claude-agent-acp@preview
Standalone executables
Each release attaches archives for Linux (glibc and musl), macOS and Windows, on
x64 and arm64, to its GitHub release.
They need no Node.js install. Each holds two files: claude-agent-acp, and the
Claude CLI (claude) it runs. Keep them in the same directory; a symlink to
claude-agent-acp elsewhere works. To use a Claude CLI you already have
instead, set CLAUDE_CODE_EXECUTABLE. On Alpine, install libgcc and
libstdc++ first.
To build one for your machine (needs Bun) and check it:
npm run build:binary
npm run smoke:binary # add `-- --full` to drive a real session; needs a Claude login
Experimental ACP v2
The adapter also serves the draft ACP v2:
a client that asks for protocol version 2 or later in initialize gets v2, and every other client
gets v1. The draft can still change, and this surface changes with it.
CLAUDE_AGENT_ACP_PROTOCOL limits the adapter to one version. With v1, a client that asks
for v2 is negotiated down to v1. With v2, the adapter rejects the initialize of a v1 client.
auto, the default, serves both.
On v2 the adapter serves the session baseline (session/new, session/list, session/resume
with replay, which replay_complete ends, session/close, session/prompt, session/cancel), session/delete,
session/fork, session/status, session/options (with initial configOptions on session/new,
session/resume and session/fork), session/set_title, additional directories, config options (the mode is one), plans, notices,
compaction, display terminals for commands, permission requests, elicitation, providers, auth, and
subagents. Steering is v1 only for now.
v2 is served by the v2 agent in src/v2/, which runs straight on Claude
Code instead of translating to v1. A v2 client that declares JetBrains AIR
(_meta.jetbrains.air) also gets the AIR extensions that ACP v2 does not cover.
Contribution Policy
This project does not require a Contributor License Agreement (CLA). Instead, contributions are accepted under the following terms:
By contributing to this project, you agree that your contributions will be licensed under the Apache License, Version 2.0. You affirm that you have the legal right to submit your work, that you are not including code you do not have rights to, and that you understand contributions are made without requiring a Contributor License Agreement (CLA).