[BUG] context_window metrics not updated after /compact until next API interaction
Status Closed — not planned
Reported on v2.1.14
Maintainer reply None cached
Activity 11 comments · opened Jan 21, 2026 · closed Apr 29, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
After running /compact, the context_window object in the status line JSON retains pre-compaction values until the next API interaction. This affects any status line configuration that displays context usage.
What Should Happen?
After /compact completes, the context_window metrics should immediately reflect the new (reduced) context state.
Steps to Reproduce
- Have a conversation with some context built up
- Run
/compact - Observe:
context_window.used_percentagestill shows pre-compaction value - Send any message
- Observe: value now reflects actual post-compaction state
Claude Model
Opus
Is this a regression?
I don't know
Claude Code Version
2.1.14 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Entire context_window object is stale after /compact, not just used_percentage. Manual calculation from cache_read_input_tokens + input_tokens shows the same stale behavior—confirming the issue is that the context_window object isn't refreshed after compaction until the next API round-trip.
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
As far as I can tell there is no duplicate issue for this that is current and open.
For that reason, and because the other issues are closed and locked, this issue could serve to track the issue that still exists today for "/compact" as described or 15008 could be unlocked and reopened.
Confirming this issue on Linux (WSL2) with a custom statusline hook.
My setup:
Observed behavior:
After running /compact or /clear, the context_window data passed to my statusline hook is stale. The context bar continues showing the old percentage until I send the next message.
Expected behavior:
The statusline hook should receive refreshed context_window data immediately after /compact or /clear completes.
This affects any custom statusline that displays context usage - the data Claude Code provides via stdin isn't updated after these commands.
/not-stale /pls-do-not-close-bot-overlord
/add-platform linux
Hitting the same issue — custom statusline shows stale
context_window.used_percentageafter/compactuntil the next user prompt.Additional solution proposal (from #30783): A
PostCompacthook event would cleanly solve this. Currently onlyPreCompactexists and fires before compaction with no context data. APostCompacthook firing after compaction with the updatedcontext_windowobject would let users trigger a statusline cache update (or any other post-compaction logic):Alternatively, simply triggering one additional statusline invocation after compaction completes (before waiting for the next prompt) would also fix it.
Closing #30783 as duplicate in favour of this issue.
Just checked, .jsonl file only contains a preTokens line and nothing else.
This at best allows for carefully and error-pronely reconstructing the approximate context window size by summing known overhead values and one of the subsequent jsonl lines message.content's tokens.
TL;DR jsonl also doesn't contain the new context window size.
Update — behavior not observed in recent testing
Tested on Windows 10, Claude Code 2.1.63, Max plan.
I ran an A/B comparison: logged both
used_percentageand a manual calculation fromcurrent_usageraw token counts (input + cache creation + cache read, divided by context window size) across 48 statusline renders, including a compaction boundary. Both values were identical in every entry —used_percentagedropped correctly on the first post-/compactAPI call.To verify yourself, add this to a statusline script to log both values side by side:
The perceived "stale percentage" after
/compactappears to be architectural: the statusline re-executes at turn boundaries (after each assistant message), and/compactdoesn't seem to trigger one. The displayed value updates on the next message you send — typically seconds later.This may indicate the original issue was addressed in a recent release, or that it only manifests under specific conditions I didn't reproduce.
@NubeBuster's point about missing
postTokensin the JSONLcompact_boundaryentry remains valid and would be useful for any tooling that analyses transcripts directly.I've done extensive analysis on this exact problem. Using ccusage_go (open-source Claude Code usage tracker), I found that Cache Read tokens consumed 97.7% of my session costs — API actual cost was $1.47, total billed cost was $64.98 (a 44x markup). Cache also degrades instruction following in long sessions, which I documented with per-turn JSONL analysis.
Full write-up with data, community issue references, and Claude Code's own self-analysis report:
https://blog.sd.idv.tw/en/posts/2026-03-25_claude-code-cache-trap/
Tool: https://github.com/SDpower/ccusage_go
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.