Skip to content

feat: observe Claude Desktop cloud Code sessions in real time - #112

Open
AuceptinFang wants to merge 2 commits into
fix/h2-bodiless-end-streamfrom
feat/desktop-code-stream
Open

AuceptinFang wants to merge 2 commits into
fix/h2-bodiless-end-streamfrom
feat/desktop-code-stream

Conversation

@AuceptinFang

@AuceptinFang AuceptinFang commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #111. Retarget to main once it merges.

Why the completed exchange is not enough

Cloud Code sessions in Claude Desktop run their model calls on Anthropic's side, so no /v1/messages exchange ever leaves the machine. Desktop sends a message with POST /v1/code/sessions/{id}/events and receives everything that follows through GET claude.ai/v1/code/sessions/{id}/events/stream. That response is a gzip SSE subscription that spans many turns and stays open until the user leaves the session or the connection drops. Each model call appears in it as the raw Messages stream events, from message_start to message_stop, keyed by api_message_id; user payloads carry the user's input and tool results. Hooks only see an HTTP exchange after its response ends, so before this change these calls were observed late or not at all. ChatGPT conversations (#107) differ here: each turn there is a POST whose SSE response ends with the turn.

Live response observation (abyss-mitm)

MitmHook::observe_http_response runs when a response head arrives. A hook that wants that response's body returns an HttpResponseObserver; every other response is forwarded exactly as before. For an observed response, the relay copies each body chunk into a bounded queue without waiting. A task owned by that response removes the content coding with the library write-side decoders (gzip, deflate, br, zstd, with the same window limit as whole-body decoding) and hands the plaintext to the observer. A full queue ends the observation instead of slowing the client or decoding across a gap. The observer and its state are dropped when the response ends, so no timeout or table of pending streams is needed. HTTP/2 and HTTP/1 bodies are both covered. Byte limits reuse the engine's capture limit, and the queue reuses the hook queue capacity. Complete-exchange hooks are unchanged.

Claude Code session dialect (abyss-agent-hook)

The session stream is detected next to ChatGPT conversations in ProtocolDetector, by path and the claude.ai host. The usage hook opts into that route through observe_http_response. Its observer frames SSE incrementally and keeps the user messages observed since the previous completed call as that call's request context. At message_stop, it assembles the response with the existing Anthropic logic and emits the call's request and response events, using usage from the call's own message events. The session ID is taken from the path, with cse_X mapped to session_X, the form Desktop uses on its other session routes. Client attribution uses the standard Harness registry. The completed exchange produces no events for this route. Design note

Verification at 2d04b37

  • Unit and integration tests cover HTTP/2 and HTTP/1 responses whose decoded records reach the observer before END_STREAM or the terminating chunk, with the client receiving identical bytes. They also cover stacked content codings, interleaved calls, chunk splits at every 7 bytes, replayed calls keeping their event_id, request-side truncation and runtime disabling.
  • Two recorded session streams were replayed by their original HTTP/2 DATA frames. Each produced three complete request/response pairs, with output usage 273, 739 and 509 and stable event_ids.
  • End to end, Claude Desktop 6.28899.6 ran through the explicit proxy of a broker built from this branch, with a fresh standalone backend. Two cloud Code sessions produced four calls, each emitted at its message_stop while the subscription was still open. They were attributed to claude-desktop with session_… IDs. A Bash tool call and its tool_result in the next call's request were paired by call ID, and cache read and write usage matched the stream.
  • cargo +nightly fmt --all -- --check, make lint and make test passed.

@AuceptinFang
AuceptinFang added this pull request to stack #113 November 24, 2026 11:58
AuceptinFang and others added 2 commits November 25, 2026 11:41
Hooks only saw HTTP traffic as a complete exchange after the response
ended. A long-lived subscription such as Claude Desktop's cloud Code
session stream never ends while it is in use, so nothing it carries
could be observed in time.

Add MitmHook::observe_http_response. When a response head arrives, a
hook may return an HttpResponseObserver for that response. The relay
copies each body chunk into a bounded queue without waiting, and a task
owned by the response decodes the content coding with the library
write-side decoders and hands the plaintext to the observer. A full
queue ends the observation rather than slowing the client or decoding
across a gap. The observer, and its state, are dropped when the
response ends. Complete-exchange hooks are unchanged.

Byte limits reuse the engine's capture limit and the queue reuses the
hook queue capacity.

Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…time

Claude Desktop runs cloud Code sessions on Anthropic's side and receives
their events through GET claude.ai/v1/code/sessions/{id}/events/stream,
a gzip SSE subscription that spans many turns. Each model call appears
in it as raw Messages stream events keyed by api_message_id.

Add the Claude Code session dialect next to ChatGPT conversations in
protocol detection. The usage hook opts into that route's response
through observe_http_response; the observer frames SSE incrementally,
keeps the user messages observed since the previous call as request
context, and emits the call's request and response events at
message_stop with the usage from its own message events. The session ID
comes from the path, with cse_ mapped to session_. The completed
exchange produces no events for this route.

Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SKTT1Ryze
SKTT1Ryze force-pushed the feat/desktop-code-stream branch from 2d04b37 to 687b549 Compare November 25, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant