Files
claude-agent-acp/docs/subagent-sessions.md
Ben Brandt b1c198754d fix: update to @agentclientprotocol/sdk 2.7.0 (#1629)
Updates `@agentclientprotocol/sdk` from 2.6.0 to 2.7.0 (schema v1.32.0
and v2.0.0-alpha.16), and follows the two protocol changes that affect
what the adapter already serves.

The SDK's runtime is unchanged apart from an SSE BOM fix. The rest of
the release is schema and doc comments, so I read the protocol docs and
RFDs between the two schema tags for behavior changes.

## Changes

### `configOptions` on `session/fork` (v1 and v2)

`ForkSessionRequest` now has `configOptions`, and clients may send it to
an agent that advertises `options`. The adapter advertises `fork` and
`options`, so both cores accept it:

- Two entries with the same `configId` fail with `-32602` before the
transcript is copied. On v2, so does a value type that
`session/set_config_option` does not take.
- The entries are set on the started fork, in list order, over what the
copy starts with. An entry that the session refuses is skipped, as on
`session/new`.
- No update goes out for them. The response carries the options.

This was the only compile break: `v1ForkSessionRequest` passed the v2
entries on to the v1 request.

### `replay_complete` on v2

v2 now requires a `replay_complete` update after the history replay of a
`session/resume` with `replayFrom`, and allows only replayed history
between the request and that update.

- The adapter sends it on the resumed session after the last replayed
update, also for an empty history. It does not send it without
`replayFrom`, or when the resume fails.
- Each subagent session that the replay announces gets its own
`replay_complete`, also one without history.
- A replayed child's `state_update` now follows the child's
`replay_complete`, and the notice that subagent history is missing
follows the root's. Neither is history.
- AIR's `loadReplayEnd` update is still sent to a v2 client that
declares it, right after `replay_complete`.

### Holding live updates during a replay (new mechanism)

From the request to `replay_complete`, a session can only send its
replay. An active session keeps working while it is resumed, and a
session that starts sends its first updates while the transcript is
read. So the adapter needs a place to hold them. No existing mechanism
did this.

`src/v2/replay-hold.ts` holds every update of the session and of its
subagent sessions that is not the replay, and their permission requests
and elicitations, and sends them after `replay_complete` in the order
they were sent. `V2Agent.send` is the one place where v2 session updates
leave the agent, so the hold sits there.

The replay runs in one synchronous step, so what a session sends during
that step is its replay. Nothing else tells the two apart. The comment
in the module says so.

A resume of an active session now reads the transcript before its other
steps, so the history ends as close to the request as it can.

## Already compliant, checked

- Initial config values: no notice or mode update before the setup
response, and a value that Claude Code refuses is skipped.
- `auth/logout` is idempotent, because `claude auth logout` is.
- A `tool_call/cancel` or `terminal/cancel` sent again after the item
ended gets `-32602`.
- The subagent clarifications: no assumed `senderSessionId`, session
references sent again with new tool call content, and `unknown` for a
child that can no longer be observed.
- `thought_level` values go from lowest to highest. This rests on Claude
Code's order, which a comment now says.

## Not covered

- An active session that streams while it is resumed with a replay: if
Claude Code writes a block to the transcript during the few milliseconds
of the read, the held chunks of that block reach the client twice. I
found no cheap way to close that window.
- The new RFD features are left for separate PRs: the `speed` config
category for Fast mode, `prompt_suggestions_update`, v2 skills, and
`path` on markdown plans (the `file` plan type is gone, and the adapter
never sent it).
- I did not run the integration tests against the real CLI.

## Tests

- `create-session-options.test.ts` (v1) and `v2.test.ts` (v2): a fork
sets its `configOptions`, and rejects duplicates before the copy.
- `v2.test.ts`: `replay_complete` for an empty history and none without
`replayFrom`. What an active session sends during a replay goes out
after `replay_complete`, a permission request too, and goes out without
one when the replay fails. The same for a live subagent's session.
- The existing replay tests and the `session-load-replay` golden file
now include `replay_complete`.

`npm run build`, `npm run check` and `npm run test:run` pass (4142
tests).
2026-11-14 16:36:26 +00:00

7.7 KiB

Subagent sessions

A client that declares clientCapabilities.subagents, other than JetBrains AIR, gets each Agent or Task subagent as its own child session, following the subagents RFD:

  • subagent_update on the parent announces the child before any of its traffic, with the parent's title and description for it, and reports its work state: running, requires_action while one of its requests is open (and running again when the last one ends, unless a cancel withdrew it: the child is stopping then), and idle when its work ends, with end_turn or cancelled when the SDK gives the reason. A failure is idle with the error stop reason and the SDK's error text as its error. The child keeps its session for every delegation to it.
  • A child that still works when Claude Code starts a fresh conversation, such as for /clear, is unknown, and loses its cancel capability. Claude Code can keep such a child running, but the adapter forgets the children of the old conversation, so it reports nothing more for it and cannot stop it. Its unfinished tool calls keep their status. An idle child keeps its state.
  • A child that runs outside its parent's working directory, such as an Agent call with isolation: "worktree", gets its cwd on subagent_update before its first tool call. The adapter takes it from the cwd of the child's own hooks: its SubagentStart hook runs before its first model request. It sends cwd: null when the child is back in its parent's directory. A child in its parent's directory gets no cwd, and no child gets additionalDirectories: Claude Code gives a subagent the session's additional directories, so it inherits them. A replay announces a child with the cwd that its transcript recorded, and clears it after the response when that directory no longer exists.
  • Session messages replace the Agent or Task call that launches the child, which its parent is not shown:
    • The launch's prompt is a session_message in both transcripts: the parent's outgoing view and the child's incoming one. Both use the launch's tool use id, and each names the other with the RFD's recipientMessageId and senderMessageId.
    • A foreground child's answer, from the launch's result, is the child's session_message to the parent. In Claude Code's hand-back mode, the child's SubagentHandback call is its message to the parent instead, in both transcripts and linked the same way.
    • A launch whose child is never exposed is shown as a tool call after all, with its final status.
  • A SendMessage call that resumes the child is not shown either. Its message is a session_message in both transcripts, the sender's outgoing view and the child's incoming one, linked like a launch's prompt. A SendMessage call whose message resumes no announced child, such as one to the parent, is shown as a tool call, with its final status.
  • Every message is one whole session_message. The adapter sends no session_message_chunk: it has each message's full text before it reports it, from the input or the result of the tool call that sent it.
  • A tool call that the client is shown and that operates on an announced child of another session carries the RFD's session content, { "type": "session", "sessionId": "<child>" }, after its other content: a TaskStop call whose task_id, or a SendMessage call whose to, is the child's agent id; a SendMessage call that resumed the child and stays shown because a permission request showed it first; and, on v1, an Agent or Task call that stays shown for the same reason. A tool_call_update without content carries none, since it would replace the content the client holds. A call that names the child by its name gets no reference: Claude Code resolves the name, and the adapter cannot tell which agent it picked.
  • session/cancel on the parent interrupts Claude Code, which stops the foreground children that the turn waits on. Background children keep running, as the RFD prefers; a client stops one with its own cancel. Each stopped child reports idle with cancelled from Claude Code's own events, and its open requests are withdrawn. The adapter ends no child at a cancel itself, so a child that keeps running keeps its open requests and its open tool calls. To spare background children, the adapter declares the SDK option perTaskStopAffordance, which a client can turn off in _meta.claudeCode.options. That option spares background workflows too, which a client cannot stop, so the adapter stops them after the interrupt, as Claude Code did without it. Background commands keep running after a cancel either way. A tool call of a stopped child that Claude Code reports no result for, such as the command it was running, ends in the child's session before the cancelled prompt resolves. When Claude Code stops a background child after that, or while no prompt runs, the tool call ends right after the child reports idle. A child that still runs when Claude Code exits is idle, since its work ended with the process: with no stop reason on v1, and on v2 with the error stop reason and the error that ends the root's work.
  • A child whose parent is not yet known when it ends is not exposed, since the RFD forbids guessing its parent.
  • A replay restores each child under its live session id, from its own transcript, with the same session messages and session references as live, and its end is an idle before the response. Each replayed child's current state follows the response. A launch without Claude Code's metadata file for the child stays an ordinary tool call of the parent, and a notice, for a client that takes notices, says that subagent history is missing.
  • After a load or resume, with or without replay, a SendMessage that resumes an agent from before it runs that agent in its session from before. Before the agent's traffic, each of its ancestors that the client was not told about in this connection is announced, parent before child and with no work state, as the RFD requires. An agent whose launch the session's history does not record stays unexposed.
  • Each running child is announced with the cancel capability. session/cancel with the child's session id stops that child's current work, through the SDK's Query.stopTask, and not its parent's: Claude Code also stops the foreground children it waits on, and the parent's turn goes on. Each stopped child reports idle with cancelled from Claude Code's own events, and its requests that the stop withdraws report no running first. A replayed child, which no longer runs, gets no capabilities. A client cannot prompt or otherwise change a child.

An ACP v2 client gets the same without declaring anything, since subagents are part of v2's baseline. Each child also reports its work state as its own state_update, right after the parent's copy. A replay ends each child's history with a replay_complete on the child's session, before the child's idle. The notice that subagent history is missing follows the parent's replay_complete.

JetBrains AIR keeps the earlier draft of the RFD (subagent_spawned, subagent_state_update), which it enables with nativeSubagentSessions in _meta.jetbrains.air.capabilities. See AIR extensions.

Without either signal, Agent and Task stay ordinary tool calls and child interactions stay on the root session. Clients that use the historical _meta["subagent-transcript"] capability or the forwardSubagentText session option retain the flattened child transcript.