Skip to content

feat(agent): fill Skills/MCP/Rules categories in context breakdown#2357

Draft
k11kirky wants to merge 1 commit into
posthog-code/context-breakdown-popoverfrom
posthog-code/context-breakdown-fill-categories
Draft

feat(agent): fill Skills/MCP/Rules categories in context breakdown#2357
k11kirky wants to merge 1 commit into
posthog-code/context-breakdown-popoverfrom
posthog-code/context-breakdown-fill-categories

Conversation

@k11kirky
Copy link
Copy Markdown
Contributor

@k11kirky k11kirky commented May 25, 2026

Problem

The context breakdown displayed in usage updates was missing accurate token estimates for the Rules (CLAUDE.md), Skills (slash commands), and MCP tools categories. These were left at zero even when content was present, making the breakdown unreliable for understanding what's consuming context.

Changes

Three new estimator functions were added to context-breakdown.ts:

  • estimateRulesTokens — reads the raw CLAUDE.md content and estimates its token contribution to the system prompt.
  • estimateSkillsTokens — estimates tokens for the slash-command list (name, description, hint) injected by the SDK.
  • estimateMcpTokens — estimates tokens for connected MCP tools based on their name and description.

A readClaudeMdQuietly helper reads CLAUDE.md from the project root at session initialization, falling back to undefined on any IO error, so the rules estimate is populated from the start.

A getCachedMcpTools function was added to tool-metadata.ts to expose a snapshot of the current MCP metadata cache for use by the estimator.

A updateBreakdownCategory method was introduced on ClaudeAcpAgent to safely patch a single key of the contextBreakdownBaseline without clobbering other fields. It is called after slash commands are fetched and after MCP tool metadata is loaded, so the baseline stays current as those values become available.

How did you test this?

Unit tests were added for all three new estimator functions covering zero/empty inputs, positive token counts, and scaling behavior. Existing buildBreakdown tests continue to pass.

Publish to changelog?

No

Copy link
Copy Markdown
Contributor Author

k11kirky commented May 25, 2026

@k11kirky k11kirky force-pushed the posthog-code/context-breakdown-popover branch from b68e4e4 to ebe1dbc Compare May 25, 2026 16:58
@k11kirky k11kirky force-pushed the posthog-code/context-breakdown-fill-categories branch from 923dacd to 08d0f9b Compare May 25, 2026 16:58
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