Skip to content

trace: leave Claude Code's local commands out of the prompt count - #333

Open
Saksham Uboweja (SakshamUboweja) wants to merge 2 commits into
microsoft:mainfrom
SakshamUboweja:pipeline/fix-E053
Open

Saksham Uboweja (SakshamUboweja) wants to merge 2 commits into
microsoft:mainfrom
SakshamUboweja:pipeline/fix-E053

Conversation

@SakshamUboweja

Copy link
Copy Markdown
Collaborator

Claude Code's local commands (/context, /usage, /clear, ...) were counted as prompts, even though the model never sees them.

  • Before: a session that only ran /context folded as 1 prompt with 0 model requests, and tool pruning counted every tool as unused in it.
  • After: a command that Claude Code marks as local is not counted, so that session folds as 0 prompts and adds no tool-pruning evidence.
  • Unchanged: typed prompts and prompt-type slash commands (such as /tokeneconomizer:status) still count. Turn counting is untouched.

Test: tests/test_trace.py::test_a_claude_local_command_is_no_prompt fails on main and passes with this change. Full suite passes.

Claude Code runs a local command (/context, /usage, /clear, ...) itself
and writes it as three user entries: a meta <local-command-caveat>, the
<command-name> entry as its child, and the command's output. `_is_prompt`
skips the first and the last but accepts the command, so a session that
only ran /context folded as one prompt with no model request, and tool
pruning counted every catalog tool as unused through it.
`claude_prompt_count` now skips an entry whose parent is such a caveat.
A prompt-type slash command (/tokeneconomizer:status) has no caveat and
still counts; `claude_prompt_turns` is unchanged.
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.

2 participants