This document describes the internal JSON-RPC protocol between zcode-acp-server and the ZCode CLI.
ZCode communicates over stdio using line-delimited JSON. The message format
resembles JSON-RPC, but does not include the jsonrpc field.
Messages are classified by the presence of id and method:
| Combination | Type | Direction |
|---|---|---|
id + no method |
Response | zcode -> bridge |
id + method |
Request | bridge -> zcode or zcode -> bridge |
method + no id |
Notification | bidirectional |
{
"id": 1,
"method": "session/create",
"params": {
"workspace": {
"workspacePath": "/path/to/project",
"workspaceKey": "/path/to/project"
},
"mode": "yolo"
}
}{
"id": 1,
"result": {
"session": {
"sessionId": "sess_abc123",
"title": "your prompt text..."
}
}
}{
"id": 1,
"error": {
"message": "prompt is running",
"code": 1308
}
}{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 42,
"type": "turn.started",
"payload": {}
}
}Create a new session. Note: the bridge defers this call until a session's
first use — ACP session/new returns a local placeholder id and materializes
the backend session (this RPC) on the first prompt / config change / extension
method, so an editor startup that never sends a message leaves no session.
Request:
{
"id": 1,
"method": "session/create",
"params": {
"workspace": {
"workspacePath": "/path/to/project",
"workspaceKey": "/path/to/project"
},
"mode": "yolo"
}
}Response:
{
"id": 1,
"result": {
"session": {
"sessionId": "sess_abc123",
"title": "",
"traceId": "trace_xyz789"
}
}
}List all sessions.
Request:
{
"id": 2,
"method": "session/list",
"params": {
"workspace": {
"workspacePath": "/path/to/project",
"workspaceKey": "/path/to/project"
}
}
}Resume an existing session.
The sessionId may be a lazy session/new placeholder (the editor persists it
and resumes it after a bridge restart). The bridge resolves it before the
backend call: an in-memory or persisted (acp-lazy-sessions.json) mapping is
followed to the real backend session — resuming it, or materializing a fresh
empty one if the placeholder was never used. Real ids from session/list pass
through unchanged.
Request:
{
"id": 3,
"method": "session/resume",
"params": {
"sessionId": "sess_abc123",
"workspace": {
"workspacePath": "/path/to/project",
"workspaceKey": "/path/to/project"
}
}
}Send a prompt.
ACP resource text is merged into content. Embedded PDF/image blobs and ACP
image blocks are forwarded in an optional native attachments array, with
kind, filename, mimeType, exact sizeBytes, and dataBase64. Supplied
bytes take precedence over URI metadata. Other binary resources use kind: "file" and a private staged localPath instead of dataBase64; successful
staging survives bridge restarts so native tools can read it after resume.
See README prompt attachments for limits and
retention. These resources are advertised by promptCapabilities.embeddedContext.
Request:
{
"id": 4,
"method": "session/send",
"params": {
"sessionId": "sess_abc123",
"content": "your prompt text"
}
}Response:
{
"id": 4,
"result": {
"accepted": true
}
}Stop the current turn (fire-and-forget).
{
"method": "session/stop",
"params": {
"sessionId": "sess_abc123"
}
}Read the session state and projection.
Request:
{
"id": 5,
"method": "session/read",
"params": {
"sessionId": "sess_abc123"
}
}Response:
{
"id": 5,
"result": {
"projection": {
"status": "idle",
"contextUsed": 1234,
"contextWindow": 32000,
"totalTokenCount": 5678
},
"settings": {
"mode": { "current": "yolo" },
"model": { "current": { "modelId": "GLM-5.2" } },
"thoughtLevel": { "current": "high" }
},
"todos": [{ "content": "Implement login", "status": "pending", "priority": "high" }]
}
}Fetch the session's historical messages.
Request:
{
"id": 6,
"method": "session/messages",
"params": {
"sessionId": "sess_abc123"
}
}Subscribe to a session's event push.
Request:
{
"id": 7,
"method": "session/subscribe",
"params": {
"sessionId": "sess_abc123",
"deliveryKind": "desktop-continuous",
"includeSnapshot": true,
"afterSeq": 0
}
}Response:
{
"id": 7,
"result": {
"eventSeq": 42,
"snapshot": {
"projection": { ... },
"messages": [ ... ]
}
}
}After subscribing, zcode pushes events via session/event notifications:
The turn has started.
{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 43,
"type": "turn.started",
"payload": {}
}
}Model streaming output.
{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 44,
"type": "model.streaming",
"payload": {
"kind": "text_delta",
"delta": "this code..."
}
}
}kind can be:
text_delta: text deltareasoning_delta: reasoning text deltatool_call: tool call declaration (caches toolName and input)
Tool status update.
{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 45,
"type": "tool.updated",
"payload": {
"kind": "scheduled",
"toolCallId": "call_xyz",
"toolName": "Bash",
"input": { "command": "ls -la" }
}
}
}kind can be:
scheduled: tool scheduledstarted: tool started executingprogress: progress update (stdoutTail / stderrTail)result: tool finishederror: tool errorbatch: multiple tools finished in a batch
The turn completed.
usage carries the turn's billing-grade usage: the backend merges every model
call's usage into one object (per-turn scope, not session-cumulative). It is
omitted when no model call reported usage. The bridge forwards this object as
the ACP session/prompt result's usage field (UNSTABLE in
agent-client-protocol), with source/modelRequestCount/web request counts
riding in the result's _meta.zcode.usage.
One field is normalized: the backend's inputTokens is cache-INCLUSIVE
(OpenAI-style; verified totalTokens == inputTokens + outputTokens on live
frames), while ACP's de-facto convention (claude-agent-acp, DeepSeek's
dsh-token-meter four-bucket model) reports inputTokens EXCLUDING cache —
clients compute hit rate as cachedRead / (input + cachedRead + cachedWrite).
The bridge therefore reports inputTokens = backend inputTokens − cacheRead − cacheWrite (clamped at 0) and keeps totalTokens verbatim (the backend's
input+output sum equals the convention's four-bucket total). The untouched
backend value rides in _meta.zcode.usage.rawInputTokens — present only when
normalization actually changed the number.
{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 46,
"type": "turn.completed",
"payload": {
"resultType": "success",
"usage": {
"source": "provider",
"modelRequestCount": 2,
"inputTokens": 1100,
"outputTokens": 134,
"totalTokens": 1234,
"cacheReadTokens": 800,
"cacheWriteTokens": 90,
"reasoningTokens": 45,
"webFetchRequests": 0,
"webSearchRequests": 0
}
}
}
}The turn failed.
{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 47,
"type": "turn.failed",
"payload": {
"error": {
"code": 1308,
"message": "prompt is running"
}
}
}
}Session state update (usage, etc.).
{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 48,
"type": "session.updated",
"payload": {
"usage": {
"inputTokens": 1234
},
"contextWindow": 32000
}
}
}When a user input is steered into (queued behind) a running turn, the backend
emits a pair of lifecycle events (app-server 0.15.2+). Every drained input is
a persisted USER message upstream, so the bridge mirrors
turn.steerDrained's drainedInputs[].text to the clients as
user_message_chunk notifications (echoSteeredInputs): from the turn loop
while one is live, and from the session-scoped background listener otherwise
(gated on pendingTurns, so the two paths never double-echo). Clients that
STEERED via _session/steering are excluded from the echo
(steerEchoSuppressedRoots — they render the injected text locally, e.g.
martty keeps its Send Now cell, and would see it twice); backend-internal
guides (plan-approval feedback, workflow refine) have no steering client and
echo to everyone. turn.steerQueued
feeds the steer-swallow guard (a send accepted mid-generation is queued and
silently dropped when the turn ends — reported to the user at once) but has no
live "queued" indicator yet (see BACKLOG.md).
{
"type": "turn.steerQueued",
"payload": {
"pendingInputId": "…",
"inputPreview": "…",
"delivery": "queue",
"targetTurnId": "…",
"queueLength": 1
}
}{
"type": "turn.steerDrained",
"payload": {
"pendingInputIds": ["…"],
"targetTurnId": "…",
"injectedMessageIds": ["…"],
"drainedInputs": [{ "pendingInputId": "…", "messageId": "…", "text": "…" }]
}
}Terminal turn lifecycle event (app-server 0.15.2+). Carries a status plus
usage. The bridge currently relies on turn.completed/turn.failed instead;
documented here for completeness.
{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 49,
"type": "turn.terminal",
"payload": {
"kind": "turn.terminal",
"status": "success",
"resultType": "end_turn",
"durationMs": 12345,
"inputTokens": 1234,
"outputTokens": 567,
"totalTokens": 1801
}
}
}Requests that zcode actively sends to the bridge.
Tool permission request.
{
"id": 100,
"method": "interaction/requestPermission",
"params": {
"requestId": "req_xyz",
"sessionId": "sess_abc123",
"toolCallId": "call_xyz",
"toolName": "Bash",
"reason": "run command",
"input": { "command": "rm -rf /" },
"options": [
{ "optionId": "allow", "kind": "allow_once", "name": "Allow once" },
{ "optionId": "deny", "kind": "deny_once", "name": "Deny" }
]
}
}User input request (ExitPlanMode / AskUserQuestion).
ExitPlanMode:
{
"id": 101,
"method": "interaction/requestUserInput",
"params": {
"requestId": "req_xyz",
"sessionId": "sess_abc123",
"toolCallId": "call_xyz",
"schema": { "interaction": "plan_approval" },
"input": { "plan": "1. Implement login\n2. Implement signup" }
}
}AskUserQuestion:
{
"id": 102,
"method": "interaction/requestUserInput",
"params": {
"requestId": "req_xyz",
"sessionId": "sess_abc123",
"toolCallId": "call_xyz",
"questions": [
{
"question": "Select the files to test",
"multiSelect": true,
"options": [
{ "label": "auth.test.ts", "value": "auth" },
{ "label": "user.test.ts", "value": "user" }
]
}
]
}
}ZCode interaction/* requests are routed to different ACP interaction
mechanisms. Each request type has its OWN gate:
| Request type | Routing when the gate is OPEN | Routing when the gate is CLOSED | Gate |
|---|---|---|---|
Tool auth (interaction/requestPermission) |
session/request_permission |
session/request_permission |
none (always the same path) |
ExitPlanMode (interaction/requestUserInput + plan_approval) |
elicitation/create (approve/reject form) |
session/request_permission |
server.hasMarttyClient() |
AskUserQuestion (interaction/requestUserInput) |
elicitation/create (single form) |
per-question session/request_permission |
server.supportsElicitationForm() |
Capability detection: AskUserQuestion keys on
clientCapabilities.elicitation.form (detected at initialize via
server.supportsElicitationForm()) — structured input is the correct
elicitation use for any form-capable client. ExitPlanMode keys on
server.hasMarttyClient() instead: martty's request_permission overlay draws
only the title, so the plan needs the form's scrollable detail pane — while
editors render toolCall.content as full markdown (Zed: MarkdownElement,
code blocks and links) and draw form descriptions as plain text, so the form
would downgrade them. Zed ≥1.12 declares elicitation.form, which is why the
gate keys on the client kind, not the capability.
Reconnect resend: interaction requests are one-shot and raced across the
clients connected when they fire (first response wins). A client that was
offline at that moment never sees them — so when a client completes
session/load / session/resume (the reconnect catch-up), the bridge re-sends
that session's still-unanswered interaction requests to it (after a short
delay, so the replay renders first). The re-send joins the existing race: if
another client answers first, the reconnected client receives $/cancel_request
and should drop the dialog.
elicitation form example (AskUserQuestion):
{
"method": "elicitation/create",
"params": {
"mode": "form",
"sessionId": "sess_abc123",
"message": "Please answer 2 questions.",
"requestedSchema": {
"type": "object",
"properties": {
"q_0": {
"type": "string",
"title": "Select the files to test",
"oneOf": [
{ "const": "auth.test.ts", "title": "auth.test.ts" },
{ "const": "user.test.ts", "title": "user.test.ts" },
{ "const": "__skip__", "title": "Skip this question" }
]
},
"q_0_other": {
"type": "string",
"title": "↳ or type a custom value (overrides the selection)"
}
},
"required": []
}
}
}ACP/MCP elicitation string fields are EITHER an enum (restricted dropdown) OR
free text — the spec forbids a single field that is both. So each question is
rendered as TWO fields: q_<i> (a oneOf/anyOf enum dropdown of the model's
suggested answers, with a trailing "Skip this question" option whose const is
the __skip__ sentinel and whose title is the readable label) and
q_<i>_other (a free-text companion). On submit, a non-empty q_<i>_other
overrides the dropdown (single-select) or is appended to the picked values
(multi-select); selecting "Skip this question" or leaving both blank skips just
that question without cancelling the form.
elicitation response (accept/decline/cancel):
{
"action": "accept",
"content": { "q_0": "auth.test.ts" }
}ExitPlanMode elicitation form — sent only when a martty TUI is attached
(server.hasMarttyClient()); everyone else gets session/request_permission
with the plan in toolCall.content. The form carries the COMPLETE plan
markdown as the approval field's description (martty renders it in a
scrollable detail pane); the decision itself is a required approve/reject enum.
An accept whose content.approval is "approve" maps to the zcode accept
(answer_0: "approve"); a reject/cancel action, or "reject" in the
field, maps to a plain decline.
{
"method": "elicitation/create",
"params": {
"mode": "form",
"sessionId": "sess_abc123",
"message": "Exit plan mode",
"requestedSchema": {
"type": "object",
"properties": {
"approval": {
"type": "string",
"title": "Review the plan, then choose an action",
"description": "1. Implement login\n2. Implement signup",
"oneOf": [
{ "const": "approve", "title": "Approve — exit plan mode" },
{ "const": "reject", "title": "Reject — keep planning" }
]
}
},
"required": ["approval"]
}
}
}If the form request fails outright (no form-capable client attached any more —
capability flags are merged across clients at initialize — or a timeout), the
bridge falls back once to session/request_permission so the plan can still
be approved by a plain permission popup; only when that also fails does the
plan decline.
Fork a new session from a checkpoint. On the ACP V1 face, the method and the
advertised sessionCapabilities.fork are the ACP draft's, so the response is in
the draft's ForkSessionResponse shape: sessionId names the new session, with
the modes, configOptions and _meta a resumed session gets. modes and
configOptions are left out when the mode cannot be read. After responding, V1
announces slash commands for the forked session via available_commands_update,
matching session/new, session/resume, and session/load.
Request (sessionId is the only field the bridge requires; cwd is the
draft's, target and checkpointId are the bridge's own):
{
"id": 8,
"method": "session/fork",
"params": {
"sessionId": "sess_abc123",
"cwd": "/home/me/project",
"target": { "kind": "latestCheckpoint" }
}
}A fork continues the source conversation, so it keeps the source session's
working directory and MCP servers. This is the rule session/resume already
applies: the session root never comes from the client. cwd is accepted but
not applied. A non-empty mcpServers is remembered for the fork and re-sent
on its next load; an empty one keeps the source's servers. Both of its
spellings are taken and the list is kept in the backend's wire shape, as on
session/new; an entry the backend has no field for (an unknown type) is a
-32602 before anything is forked. On V1, cursorId,
systemPrompt and configOptions ride on capabilities the V1 face does not
advertise and are ignored (the ACP V2 face handles cursorId separately).
Response (abridged):
{
"sessionId": "sess_def456",
"modes": {
"currentModeId": "build",
"availableModes": [
{ "id": "plan", "name": "Plan" },
{ "id": "build", "name": "Build" }
]
},
"configOptions": [
{
"id": "mode",
"name": "Mode",
"category": "mode",
"type": "select",
"currentValue": "build",
"options": [
{ "name": "plan", "value": "plan" },
{ "name": "build", "value": "build" }
]
}
],
"_meta": { "zcode": {} }
}Edit-and-resend of the latest user message, and regenerate of the latest
turn, mapped onto the v4 conversation commands editUserQuery / retryTurn.
The old v3 session/rewind (and session/rewindCascade) existed up to
app-server 0.15.x; the 0.16 app-server removed them in favor of the v4
conversation API, and these two methods are that API's ACP surface.
Capability: initialize advertises agentCapabilities._meta.zcode.rewind: true when the desktop bundle is at/above the source-verified floor (3.14.3 —
the v4 rewind command set and v4/conversation/rowsRange predate that tag).
Below the floor the key is ABSENT (not false); the methods then answer a
clean error. Clients should hide edit/regenerate when the flag is missing and
degrade to quote-to-composer.
Request (edit):
{
"id": 8,
"method": "session/edit_user_message",
"params": {
"sessionId": "sess_abc123",
"messageId": "<_meta.zcode.mid of the user message>",
"newText": "replacement text"
}
}Request (retry; messageId optional — omitted retries the latest turn):
{
"id": 9,
"method": "session/retry_turn",
"params": {
"sessionId": "sess_abc123",
"messageId": "<_meta.zcode.mid of the assistant message>"
}
}Result (both): { "ok": true, "rewoundMessageId": "<the mid that was rewound>" }
Semantics:
- Only the latest turn is addressable (upstream guards
latestQueryEditOnly/latestAssistantRetryOnly); a stale/non-matchingmessageIdanswers-32602before any backend round trip. Workspace files are never touched (workspaceMode: "preserve"always — file rewind stays a desktop-app concern). - The ack returns at ADMISSION: the rewound history is already committed, and
the replacement turn runs next. Clients should refetch history
(
session/load) on the ack; the replacement turn itself streams to every attached client asagent_message_chunkupdates, and the session reports busy ($/zcode/turnState) until it terminates. - Other clients' cached tails are stale until their next replay (v1: single user, edit happens on the viewed client).
_meta.zcode.mid: every REPLAYED update that renders as a message
(user_message_chunk, agent_message_chunk, agent_thought_chunk, and
replayed tool_calls) carries _meta: { zcode: { mid: "<store message id>" } }
on both session/load and session/load_earlier pages — the value the
rewind methods address (it equals the store row's v4 entityId). Live echo
chunks (uprompt_/chunk_ ids) deliberately do NOT carry it.
Read / set / replace / clear the goal.
Request:
{
"id": 10,
"method": "session/goal",
"params": {
"sessionId": "sess_abc123",
"action": "set",
"objective": "Refactor the auth module"
}
}action can be: show, set, replace, clear, pause, resume
Compact the conversation history.
Request:
{
"id": 11,
"method": "session/compact",
"params": {
"sessionId": "sess_abc123"
}
}session/steer existed up to app-server 0.15.x. The 0.16 app-server removed
it from its RPC dispatch (verified against 0.16.3: -32601 Method not found);
steering moved to the v4 command/conversation API. The bridge's
session/steer ACP extension and the /steer slash command were removed
accordingly. Queued inputs still surface as turn.steerQueued /
turn.steerDrained events (see above).
The successor, wired onto the v4 command API (v4/command sendText with
requestedDelivery:"guide" | "queue"). The method name and reply shape follow
the cross-adapter convention introduced by @agentclientprotocol/codex-acp
and @agentclientprotocol/claude-agent-acp; the agent advertises it via
InitializeResponse._meta.steering ({ supported: true, timings: ["now", "next"] } — timings is this bridge's additive field).
Request:
{
"id": 14,
"method": "_session/steering",
"params": {
"sessionId": "sess_abc123",
"prompt": [{ "type": "text", "text": "use the other approach" }],
"_meta": { "steering": { "priority": "now" } }
}
}prompt— text blocks only (multi-block joins with newlines); the v4 steer channel carries no attachments._meta.steering.priority—"now"(default) injects into the live turn (guide);"next"queues the text for the next turn boundary._meta.steering.idleBehavior— only"promptRequired"is accepted; this bridge never auto-starts a turn from a steering request.
Reply — one outcome object:
{ "outcome": "injected" }— the text joined the running turn.{ "outcome": "queued" }— delivered at the next boundary (explicitnext, or the backend demoted guide to queue because the turn kind cannot take live injection).{ "outcome": "promptRequired", "reason": "noRunningTurn" }— the session is idle; the client should send a normalsession/promptinstead.{ "outcome": "startedNewTurn" }— the turn ended between the bridge's liveness check and the backend's admission, and the steer text started a new turn (race window, reported honestly).
Steering a turn owned by another client (the desktop app) works — the liveness fallback reads the session projection when no bridge turn is registered.
Switch the session mode.
Request:
{
"id": 13,
"method": "session/setMode",
"params": {
"sessionId": "sess_abc123",
"mode": "build"
}
}Set the thought level.
Request:
{
"id": 14,
"method": "session/setThoughtLevel",
"params": {
"sessionId": "sess_abc123",
"thoughtLevel": "max"
}
}When the model dispatches a sub-agent via the Agent (or Task) tool, the
backend keeps producing events on the same session stream — both while the
sub-agent runs and after the main turn ends. The bridge forwards a curated
subset to the ACP client:
The Agent tool blocks until the sub-agent finishes. Its internal tool calls
(Read, Bash, …) arrive as ordinary tool.updated events on the main stream
and are forwarded as regular tool_call cards. The Agent card itself carries
structured metadata in _meta.subagent (parsed from the result content):
{
"sessionUpdate": "tool_call_update",
"toolCallId": "call_xxx",
"status": "completed",
"_meta": {
"claudeCode": { "toolName": "Agent" },
"subagent": {
"agentId": "agent_73c7c63d-...",
"tokens": 40904,
"toolUses": 1,
"durationMs": 10559
}
}
}The Agent tool returns immediately with a launch acknowledgement (result
content contains agentId + output_file + "working in the background"). The
main turn then completes, but the backend continues to push the task's
lifecycle on the same stream:
1. Status changes — session.updated carries a taskId and status:
{
"method": "session/event",
"params": {
"sessionId": "sess_abc123",
"seq": 16,
"type": "session.updated",
"payload": {
"taskId": "agent_88a44529-...",
"toolCallId": "call_orig",
"toolName": "Agent",
"status": "running",
"description": "Read README first heading",
"outputPath": "/.../output.txt",
"terminalId": "agent_88a44529-...",
"startedAt": "2026-07-18T09:06:45.929Z"
}
}
}The bridge's session-scoped BackgroundTaskListener turns these into a
dedicated ACP tool card ([background] <description>) plus status updates:
| Backend event | ACP notification |
|---|---|
first session.updated (status running) |
tool_call (new card, kind:"other", status:"in_progress") |
session.updated (status completed) |
tool_call_update (status:"completed") |
session.updated events WITHOUT a taskId (e.g. usage updates) are ignored by
the background listener — they remain owned by the turn loop.
2. Completion notification turn — when the background task finishes, the
backend auto-triggers a new turn whose turn.started carries
inputSource:"background_task":
{
"type": "turn.started",
"payload": {
"inputSource": "background_task",
"inputVisibility": "model-only",
"input": "<task-notification>\n <task-id>agent_...</task-id>\n <status>completed</status-status>\n ...\n</task-notification>",
"turnId": "turn_95197b25-..."
}
}The background listener forwards that turn's model.streaming text_delta as
agent_message_chunk so the user sees the background result. The per-prompt
turn loop defers this entire turn (drops its events) to avoid double-
forwarding and to keep it from prematurely ending the user's real turn.
The Bash tool launched with run_in_background: true returns immediately
with a launch acknowledgement (result content: "Command running in background
with ID: exec_…"). Like the Agent sub-agent, the backend keeps pushing the
task's lifecycle on the same stream via session.updated events that carry
the originating toolCallId:
{
"type": "session.updated",
"payload": {
"taskId": "exec_ac3a5053-...",
"toolCallId": "call_e282b4ec...",
"toolName": "Bash",
"status": "running",
"pid": 22410,
"outputPath": "/.../call_...-stdout.log",
"outputTail": "done\n"
}
}Card reuse, not duplication. Unlike an Agent sub-agent (which mints a fresh
bg_* card), a background Bash task reuses the launch card — the very
terminal card the dispatcher created when Bash was scheduled. This keeps the
lifecycle on a single card instead of producing a duplicate [background] card
that the editor would show alongside the closed launch card.
The mechanism:
- Launch turn — the dispatcher tags the
ToolCallNew/ToolCallUpdatewithbackground: true(threaded from the cachedinput.run_in_backgroundflag) and, on the launchresult, skipsterminal_exitso the launch card staysin_progress. It seeds an empty marker interminalSentDatafor thetoolCallId— this is the signal the background listener uses to recognise "this is a tracked launch card". - Lifecycle (
session.updated) — theBackgroundTaskListenerresolves thetoolCallId, sees it interminalSentData, and routes status updates back to the launch card. Onstatus:"completed", it emits the finaloutputTailviaterminal_output(iff launch text wasn't already streamed) and closes the terminal UI withterminal_exit(exit code 0, or 1 onfailed), then clears theterminalSentDataentry. - Fallback — if the
session.updatedlacks atoolCallId, or thetoolCallIdis unknown toterminalSentData(sub-agent case), the listener falls back to minting a freshbg_*card — the Agent sub-agent path above.
| Backend event | ACP notification (background Bash) |
|---|---|
first session.updated (status running) |
tool_call_update on the launch card (status:"in_progress") |
session.updated (status completed, with outputTail) |
terminal_output (final output, if not already streamed) + tool_call_update with terminal_exit (status:"completed") |
session.updated (status failed) |
tool_call_update with terminal_exit (status:"failed", exit_code 1) |
session/cancelBackgroundTask for a background Bash task additionally emits
terminal_exit with _meta.backgroundTask.cancelled = true so the terminal
UI closes on cancellation.
When a background task finishes, the backend's notification turn (the model
summarising the result) holds the session's prompt lock for its whole
duration — a fresh session/send during that window answers busy:
{ "code": -32010, "message": "A prompt is already running for this session" }(observed live against desktop 3.12.3 / app-server 0.16.5, 2026-09-18). The
prompt path's busy-retry normally gives up after 30s, but a notification turn
is a real model turn and easily outlives that budget. While the session's
BackgroundTaskListener has a notification turn active
(server.notifyTurnActiveSince), the bridge extends the busy budget to 180s
instead of failing the user's prompt — the send is guaranteed accepted once
the notification turn drains.
New in app-server 0.16.5 (verified live + schema-checked against the desktop 3.12.3 bundle): the backend pushes authoritative conversation-title changes.
{
"type": "session.titleUpdated",
"payload": {
"previousTitle": "",
"source": "generated",
"title": "Fix the login bug",
"messageID": "msg_…"
}
}source is one of default (nothing meaningful), first_input (the literal
first prompt), generated (the backend's LLM-generated title, landing after
the first turn), or custom (a user rename from another surface, e.g. the
desktop app over the same session store).
The bridge's session-scoped SessionTitleListener (registered alongside the
background-task listener) adopts generated and custom pushes — updating
sessionTitles for every ACP alias of the conversation, the session summary,
the tasks-index, the martty terminal tab title, and broadcasting an ACP
session_info_update to attached clients per alias.
Auto naming happens exactly once: the first-prompt provisional seed may be
replaced by the first generated push (server.autoTitleFinalized freezes the
phase after it); every later generated push — a deferred sidecar result, the
resume re-emission after the stored title event rotated out of the retention
window — is ignored. Only a manual rename may change the title afterwards: the
/rename slash command, the remote rename endpoint, or a custom push
(another surface's rename, e.g. the desktop app). Manual renames are pinned in
server.titleUserSetBy (all aliases), and the durable title_overridden flag
in tasks-index.sqlite is consulted for renames that predate the bridge
process — later generated pushes never override them. default/
first_input pushes are ignored — the bridge already seeds the first-prompt
form itself (see "one-shot session title" in the handlers).
A manual rename also reaches the BACKEND store via the v4 renameSession
command (titleSource=custom, sticky — the backend's own auto generation is
skipped from then on), so session/list reads, resume title re-emission, and
the desktop app's v4 projection all converge on the user's title.
adoptStoredTitle (load/resume) is pin-first: a sibling alias's known title,
then the durable title_overridden title, and only then the backend's stored
title (asked session/list {sessionIds:[id]} — the bare listing is only the
50 most recent sessions across all workspaces, so older conversations need the
by-id lookup; backends that reject the key fall back to the bare listing).
The /resume slash command additionally broadcasts the adopted title as a
session_info_update: editors derive a thread title from the first prompt —
which for an adopting thread is the /resume command itself — and only a
pushed title replaces that provisional name.
Cancels a background task. The bridge additionally marks the corresponding ACP
tool card as failed with _meta.backgroundTask.cancelled = true.
| ZCode CLI version | session/subscribe | Extension methods | Notes |
|---|---|---|---|
| >= 0.16.0 | Supported | All except steer/rewind | session/steer, session/rewind, session/rewindCascade removed upstream (v4 API); bridge dropped its passthroughs and /steer, /rewind slash commands |
| >= 0.15.0 | Supported | All supported | Full functionality |
| >= 0.14.8 | Supported | Partially supported | workspace/* unavailable |
| 0.14.5 ~ 0.14.7 | Not supported | Not supported | Incompatible with this project |
The backend exposes more RPC methods than the bridge uses (sub-agent listing,
event pull, session usage/close, automation, workspace config, MCP/plugins).
These have no ACP-side counterpart yet. See BACKLOG.md for
the full list and which are candidates for future support.
When ZCODE_ACP_REMOTE=1 is enabled, the bridge accepts additional ACP clients
over WebSocket (via the machine-level hub) alongside the stdio editor. All
clients share the same backend sessions; the rules below define how one agent
serves many clients.
| Aspect | Behaviour |
|---|---|
session/update notifications |
Broadcast to every connected client. A client that never saw a session (e.g. an editor receiving a phone-created session) simply ignores the update. |
session/request_permission, elicitation/create |
Sent to every client; the first response wins. Losing requests are aborted, which emits $/cancel_request so the losing client dismisses its dialog and replies RequestCancelled. |
| Capabilities | OR-merged across clients at each initialize (booleans union, _meta shallow-merged). A capability any client declares is enabled for interaction routing. |
Concurrent session/prompt on one session |
Serialized by the per-session preempt lock — identical to the single-client case; a second client's prompt preempts or queues the same way. |
session/cancel |
Affects the shared turn regardless of which client sent it. |
| Process lifetime | Follows the stdio client: when the editor disconnects, the bridge (and every remote attachment) exits. Remote clients never extend the lifetime. |
Transport details (hub discovery API, token auth, tunnel notes) live in the Remote Access section of the README.