Feature request: PostCompact hook + statusline refresh after /compact

Resolved 💬 3 comments Opened Mar 4, 2026 by JayBarratt Closed Mar 4, 2026

Summary

After /compact runs, the Compact % in the statusline does not update until the first prompt submitted after compaction. This is a minor but consistent UX gap — the statusline shows stale context usage during exactly the moment the user most expects it to have updated.

Root cause (investigated)

The statusline script receives context_window.used_percentage from the JSON Claude Code pipes to stdin. Claude Code only invokes the statusline at turn boundaries (after each assistant message, permission mode change, or vim mode toggle) — not on a timer. So after /compact completes, the statusline is never called again until the next user prompt.

A PostCompact hook could solve this, but currently only PreCompact exists — and it fires before compaction and carries no context percentage data.

Requested changes (either would solve it)

Option A — PostCompact hook
Add a PostCompact hook event that fires after compaction completes, receiving at minimum:

{
  "hook_event_name": "PostCompact",
  "trigger": "manual" | "auto",
  "context_window": {
    "used_percentage": 18,
    "used_tokens": 12000,
    "available_tokens": 54000
  }
}

This would allow users to write a hook that updates a cache file, which a statusline script could read.

Option B — Trigger statusline refresh after compaction
After /compact completes, trigger one additional statusline invocation with the updated context_window data — before waiting for the next user prompt.

Why it matters

The statusline is most useful at high context usage — which is precisely when compaction happens. Showing stale data immediately after compaction undermines the statusline's value at the moment it matters most.

Environment

  • Claude Code (CLI)
  • Custom statusline script using context_window.used_percentage from stdin JSON
  • Reproduced on Windows (MINGW64) with statusLine set in ~/.claude/settings.json

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗