Repository navigation
trace: leave Claude Code's background-task notifications out of the prompt count - #208
Open
Muhammad Abdullah Butt (1AbdullahButt) wants to merge 1 commit into
Conversation
…rompt count Claude Code tells the model a background task finished in a user entry of its own (`origin.kind` "task-notification"). `_is_prompt` accepted it, so `claude_prompt_count` counted it as a prompt the person gave, and tool pruning's prompt evidence ran ahead of what was typed. The notification still starts a turn, so `claude_prompt_turns` is unchanged. Fixes microsoft#207 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #207
When a background task finishes, Claude Code tells the model in a
userentry of its own, markedorigin.kind: "task-notification"(2.1.317)._is_promptaccepted it, soclaude_prompt_countcounted it as a prompt the person gave. That count is the session'spromptsin the fold. Tool pruning adds it to each unused tool's prompt streak, so a session that ran background commands moved a deny list closer than the prompts typed in it. History import reads the same count for itsno_promptandheadlesschecks.This PR adds
_is_notification, which readsorigin.kind, and leaves those entries out ofclaude_prompt_count._is_promptis unchanged, soclaude_prompt_turnsstill starts a turn at a notification. The model answers it in a turn of its own, and merging that into the earlier prompt's turn would change the loop guard's envelope.The test is in
tests/test_trace.py, next to the existing prompt-count test. One typed prompt, then a notification shaped like the ones 2.1.317 writes. The test checks that the count is 1 and that the log still reads as two turns.How it was produced: Claude Code, an AI coding agent, found the bug by running the trace readers over the Claude Code logs on my machine. It also wrote the fix and the test. I directed the work.
What was checked, on Windows 11 with Python 3.10, on
mainat81e32e5:tests/test_trace.pyandtests/test_history_import.pypass.testsrun:python -m pytest testsreports 888 passed, 24 skipped and 0 failed. The skips need tools this machine does not have. I did not runexperiments/tests.origin.kind == "task-notification", and nothing else changes.🤖 Generated with Claude Code