You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Session.contextBreakdown(): claude's /context categories and items, read on demand #262
Ferry (for @xxchan) wants the context window broken down the way Claude Code's /context shows it: Messages, System tools, MCP tools, Skills, System prompt, Memory files, Autocompact buffer, Free space, and the tokens of each MCP tool and memory file. Session.contextUsage() gives only the total and the window.
Evidence
claude 2.1.292 answers the get_context_usage control request (OAR already sends it with detail: "summary" for the skills inventory). With detail: "full" it returns, without a model call and also mid-turn (answered in 0.5 s while a Bash tool ran):
categories[]: {name, tokens, kind: used | deferred | buffer | free} in claude's words (System prompt, System tools, System tools (deferred), MCP server instructions, MCP tools, MCP tools (deferred), Memory files, Skills, Custom agents, Messages, Autocompact buffer, Free space). The non-deferred categories sum to maxTokens; the used ones sum to totalTokens.
No other runtime itemizes its context: codex, pi and the ACP runtimes report a total and a window at most.
Decided
An optional on-demand query, like resources():
contextBreakdown?(): Promise<ContextBreakdown|null>;// absent where the runtime cannot itemize (all but claude)interfaceContextBreakdown{tokens: number;contextWindow: number;categories: ContextCategory[]}interfaceContextCategory{name: string;tokens: number;kind: "used"|"deferred"|"reserved"|"free"|"unknown";items?: {name: string;tokens: number}[]}
Category names stay the runtime's own words; OAR does not rename them. kind is OAR's: claude buffer is reserved; an unrecognized kind is unknown and kept, never dropped.
Items hang under the category they make up: memory files (by path), MCP tools (loaded under MCP tools, deferred under MCP tools (deferred)), skills, custom agents.
Read now, never recorded (local paths, and it is a live reading like resources()); null once the process has exited.
The member's presence is the capability: a host shows the breakdown only where it exists, else contextUsage().
Activity
chore: release v0.46.0 (#269)
fix(claude): complete recorded limit-reset onboarding defaults (#880)