Repository navigation
feat: Session.contextBreakdown(), claude's context categories read on demand - #264
Merged
Merged
Conversation
… demand (#262) claude's get_context_usage (detail full) over the control channel: categories in claude's words and order, memory files, skills, custom agents and MCP tools as items, consumed before the projection so it enters no record. Absent on every other runtime. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…under the category claude has Lookout's inspection of #264: a read during a dispose wrote to the ended stdin and crashed the host (ERR_STREAM_WRITE_AFTER_END); with tool search off every MCP tool says isLoaded false under the only category, MCP tools, so its items were lost. Also document the count_tokens requests each read sends, so hosts read on demand. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…once stdin ended Lookout's recheck of #264: the abort fallback's kill also ends claude's stdin without a dispose, and a read in that window crashed the host. The reader returns null once stdin has ended, LineProcess.write drops writes after kill(), and stdin gets an error listener so an EPIPE from a child already gone is not an unhandled error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
xxchan
added a commit
that referenced
this pull request
Oct 9, 2026
Release OAR and CLI 0.46.0. This PR changes only the two package version fields. **Added: `Session.contextBreakdown()`** (#264, closes #262) - What fills the context window, by the runtime's own categories, read on demand and never recorded: `{ tokens, contextWindow, categories: [{ name, tokens, kind, items? }] }`. `kind` is `used | deferred | reserved | free | unknown`; names stay the runtime's words. - claude only (`get_context_usage`, `detail: "full"`): System prompt, System tools, MCP tools, Memory files, Skills, Custom agents, Messages, Autocompact buffer, Free space, with memory files, skills, agents and MCP tools itemized. Every other session has no `contextBreakdown` member; show `contextUsage()` there. - Each read makes claude send the provider a batch of `count_tokens` requests (16 to 28 for a small setup), so read when the user asks, never poll. Null from the start of a dispose and after the exit. **Added: a request the runtime withdrew leaves `pendingRequests`** (#266, closes #263) - New event `app_request_cancelled { requestId }`, read off claude `control_cancel_request` (claude cancels a pending MCP elicitation when the turn is interrupted) and codex `serverRequest/resolved`. SessionView drops the request from `pendingRequests` and marks its `app_request` part `cancelled: true`. - `appRequestText(type, body)` beside `appRequestKind`: what a question asks, or the tool or command an approval is for, read off the native body; undefined where OAR does not know. **Behavior changes** - `RuntimeEventBody` has a new kind, `app_request_cancelled`: an exhaustive `switch` over event kinds needs a case for it. - The `app_request` view part now carries the native `body` (it was declared but never filled). - The root process exit now empties `pendingRequests`; the parts stay as they were. - `LineProcess.write` drops writes once `kill()` has ended stdin, and stdin gets an error listener, so a write racing a dying child (the abort fallback's kill) no longer crashes the host with `ERR_STREAM_WRITE_AFTER_END` or `EPIPE`. Validation: all 13 checks passed on #264's final head (`2fa106c`) and #266's final head (`270bc8c`); each merged tree equals its CI tree. Lookout inspected both against claude 2.1.292 and codex 0.160.1. After this PR passes CI and merges, tag its exact squash commit as `v0.46.0` to trigger npm trusted publishing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: exe.dev user <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Closes #262.
What
Session.contextBreakdown?(): Promise<ContextBreakdown | null>: what fills the context window, by the runtime's own categories, asked of the runtime now and never recorded. Only claude has it; on every other session the member is absent and a host showscontextUsage().contracts/context-breakdown.ts):{ tokens, contextWindow, categories: [{ name, tokens, kind, items? }] }. Names stay the runtime's words;kindisused | deferred | reserved | free | unknown(claudebufferisreserved; an unrecognized kind is kept asunknown, never dropped).runtimes/claude/context-breakdown.ts):get_context_usagewithdetail: "full"over the control channel. Memory files (by path), skills, custom agents and MCP tools (loaded under MCP tools, deferred under MCP tools (deferred)) itemize their categories. The answer is consumed before the projection, like the privateget_settingsreadback, so it enters no record. Concurrent calls share the read in flight; a refusal rejects with claude's words; after the exit the answer is null; 10 s bound.Evidence
claude 2.1.292 on xxwork: answered with no model call, and mid-turn in 0.5 s while a Bash tool ran (one short turn spent on the existing login). The fixture is that answer's shape, trimmed; the used categories sum to
totalTokensand all but the deferred ones tomaxTokens, and the test asserts both.Tests
tests/claude/claude-context-breakdown.test.ts: projection (order, words, kinds, items, sums), the request sent, the shared read, nothing recorded, refusal, null after exit. Mutation-checked: letting the answer through to the projection, mappingbuffertoused, and not settling on exit each fail a test.🤖 Generated with Claude Code