Repository navigation
feat: observe Claude Desktop cloud Code sessions in real time - #112
Open
AuceptinFang wants to merge 2 commits into
Open
AuceptinFang wants to merge 2 commits into
AuceptinFang wants to merge 2 commits into
Conversation
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
force-pushed
the
feat/desktop-code-stream
branch
from
November 25, 2026 03:41
2d04b37 to
687b549
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #111. Retarget to
mainonce 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/messagesexchange ever leaves the machine. Desktop sends a message withPOST /v1/code/sessions/{id}/eventsand receives everything that follows throughGET 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, frommessage_starttomessage_stop, keyed byapi_message_id;userpayloads 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_responseruns when a response head arrives. A hook that wants that response's body returns anHttpResponseObserver; 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 theclaude.aihost. The usage hook opts into that route throughobserve_http_response. Its observer frames SSE incrementally and keeps theusermessages observed since the previous completed call as that call's request context. Atmessage_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, withcse_Xmapped tosession_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 noteVerification at
2d04b37event_id, request-side truncation and runtime disabling.event_ids.message_stopwhile the subscription was still open. They were attributed toclaude-desktopwithsession_…IDs. ABashtool call and itstool_resultin 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 lintandmake testpassed.