From 0233e2c310f5eda03fcf45d30cc3a8acdbc7f093 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Thu, 22 Oct 2026 21:30:17 -0700 Subject: [PATCH] Accept Claude Code's command_lifecycle stream events --- docs/claude-protocol.md | 1 + internal/claude/session.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/claude-protocol.md b/docs/claude-protocol.md index cc3648b..b8166de 100644 --- a/docs/claude-protocol.md +++ b/docs/claude-protocol.md @@ -27,6 +27,7 @@ NDJSON both ways: one JSON object per line on stdin and stdout. Non-JSON stdout - User turn, written to stdin: `{"type":"user","message":{"role":"user","content":"..."},"parent_tool_use_id":null,"session_id":"..."}`. With images, `content` is an array of Anthropic content blocks instead: `{"type":"image","source":{"type":"base64","media_type":"image/png","data":"..."}}` for each image, then `{"type":"text","text":"..."}`. - Stdout events: `system` (subtype `init` carries `session_id`, `model`, tools, MCP server status), `assistant` and `user` (Anthropic message content blocks: `text`, `tool_use`, `tool_result`), `result` (ends a turn; `subtype` is `success` or `error_during_execution` after an interrupt, with cost, duration, turn count). - `--include-partial-messages` adds `stream_event` lines wrapping the raw API stream (`message_start`, `content_block_start`, `content_block_delta` with `text_delta`, `content_block_stop`, `message_delta`, `message_stop`), each with `parent_tool_use_id` (set inside subagents). The complete `assistant` event for a block still arrives, before that block's `content_block_stop`. +- Newer CLIs also send `command_lifecycle` lines (`command_uuid`, `state` such as `completed`). byre drops them, as it does `keep_alive`. - The `init` event arrives with the first turn, not at launch, so the session ID is unknown until the first message is sent. - While a tool runs, `tool_progress` lines with `"heartbeat": true`, the tool's `elapsed_time_seconds`, and a `parent_tool_use_id` naming the tool call arrive every 30 seconds. A Bash call also brings `system` `task_started` and `task_notification` lines around it. - Subagents (the `Agent` tool, listed in `init` tools as `Task`): `system` `task_started` (`task_type` `local_agent`, `tool_use_id` naming the `Agent` call, `subagent_type`, `description`, `prompt`, `is_backgrounded`), `task_progress` (`description` of what it is doing), `task_updated` (by `task_id` only), and `task_notification` (`status`, `summary`). `assistant` and `user` lines from inside the subagent carry `parent_tool_use_id` set to the `Agent` call's ID, plus `agent_id`, `subagent_type` and `task_description`. A foreground subagent (`run_in_background: false`) sends only its prompt this way, as a `user` text block, and its final report arrives as the `Agent` call's `tool_result`. A background one (the default) streams all its assistant and tool-result lines; the `Agent` call's `tool_result` comes back at once saying it launched, the turn can end with its own `result` while the subagent runs, and when the subagent finishes the CLI starts another turn by itself, ending in a second `result` carrying `origin.kind` `task-notification`. diff --git a/internal/claude/session.go b/internal/claude/session.go index 9046f90..b4df6d9 100644 --- a/internal/claude/session.go +++ b/internal/claude/session.go @@ -56,6 +56,7 @@ var knownTypes = map[string]bool{ "control_response": true, "control_cancel_request": true, "keep_alive": true, + "command_lifecycle": true, } type Event struct { @@ -585,7 +586,7 @@ func (s *Session) handleLine(line []byte) { } return - case "keep_alive": + case "keep_alive", "command_lifecycle": return }