Statusline JSON contains stale context_window metrics after compaction
Description
After /compact (manual compaction), the statusline JSON file contains stale context_window metrics on the first user prompt submission. The used_percentage, total_input_tokens, and other context window fields reflect the pre-compaction state, not the post-compaction state.
Fresh metrics only appear after the agent's first response post-compaction.
Reproduction
- Start a session, reach ~47% CW usage
- Monitor statusline JSON for changes (poll file mtime + parse
used_percentage) - Run
/compact - Submit a prompt
Expected: Statusline JSON reflects post-compaction CW% (~26% in test)
Actual: Statusline JSON shows pre-compaction CW% (47% in test)
Empirical Data
[13:26:05.875] pct=47 input=37220 <- last pre-compact update
<- /compact runs, NO statusline push
[13:29:34.671] pct=47 input=37223 <- first post-compact user submit (STALE)
[13:30:07.684] pct=26 input=37656 <- after agent response (FRESH)
- The JSON file IS written on the first post-compact prompt (mtime changes), but the context_window object contains pre-compaction values
- The entire context_window object is stale, not just
used_percentage - After the agent's first response, metrics refresh correctly
Impact
Any tooling that reads the statusline JSON (hooks, monitoring, statusline displays) receives incorrect CW state on the first turn after compaction. This can cause incorrect decisions based on CW pressure (e.g., a hook that triggers session-end behavior based on CW%).
Environment
- Claude Code version: 2.1.49
- OS: Ubuntu 22.04
- Model: claude-opus-4-6
Related
- #25885 (statusline model data not updated after /model switch - fixed)
- #22643 (output_style.name not updating - open)
- Pattern: statusline JSON not refreshing after state-changing operations
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗