Skip to content

Session.contextBreakdown(): claude's /context categories and items, read on demand #262

Closed

Description

@xxchan

Need

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.
  • per-entry lists: memoryFiles[] {path, type, tokens}, mcpTools[] {name, serverName, tokens, isLoaded}, skills.skillFrontmatter[] {name, source, tokens}, agents[] {agentType, source, tokens}.

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)
interface ContextBreakdown { tokens: number; contextWindow: number; categories: ContextCategory[] }
interface ContextCategory { 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

  1. added a commit that references this issue on Oct 9, 2026
    c588d4d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions