[BUG] Interactive mode: manual /compact fires PreCompact but never PostCompact (print mode fires both) — v2.1.214, macOS
Summary
In interactive (TUI) mode, a manual /compact fires PreCompact but never fires PostCompact when compaction completes. In print mode (claude -p) the same operation fires the full sequence (PreCompact → SessionStart(source:"compact") → PostCompact with trigger:"manual" and compact_summary). Same machine, same version, same settings.
Environment
- Claude Code 2.1.214 (also reproduced on 2.1.212)
- macOS 26.5 (Darwin 25.5.0), Apple Silicon host running x86_64 CC binary
- Hooks registered in
~/.claude/settings.jsonfor bothPreCompactandPostCompact(simplecommandhooks)
Reproduction A — print mode (works)
Project-level logging hooks (cat >> hooks-fired.log for PreCompact/PostCompact/SessionStart/Stop/UserPromptSubmit), then:
claude -p "seed some context" ; claude -p --continue "/compact"
Hooks observed during the /compact invocation (full stdin payloads captured):
SessionStartsource:"resume"PreCompacttrigger:"manual",custom_instructions:nullSessionStartsource:"compact"PostCompacttrigger:"manual",compact_summary:"..."
Reproduction B — interactive mode (broken)
Interactive session (started same day, hooks present in settings at startup), user types /compact. Hook receiver timeline (receiver process stderr, timestamps local):
| time | event |
|---|---|
| 13:34:49.983 | PreCompact received ✅ |
| 13:34:50 – 13:36:58 | compaction runs, no hook events |
| 13:36:58.621 | compact_boundary system entry written to the session transcript (compaction done) |
| — | PostCompact: never fired (checked 20s+ after completion) |
| — | SessionStart(source:"compact"): never fired either |
The session transcript entries for the compact window all carry "version":"2.1.214".
Reproduced twice on two different interactive sessions (an earlier one at 12:56–13:00 behaved identically: PreCompact only).
Expected
PostCompact (and presumably SessionStart with source:"compact") should fire on manual compaction completion in interactive mode, matching print-mode behavior and the hooks documentation.
Impact
Any tooling that reacts to compaction completing (notifications, status displays, external memory layers) silently never triggers for interactive users — manual compactions of large contexts run for minutes and end with no observable hook signal. Possibly related: #77832 (PostCompact silent-miss on Windows).
3 Comments
A data point that may narrow this down, from a different client and a newer version —
SessionStart(source:"compact")does fire here.Environment: desktop CLI
ccd-cli 2.1.229on Linux (not the macOS TUI).On a manual
/compact(compactMetadata.trigger: "manual"), mySessionStarthooks withmatcher: "compact"fired and their stdout reached the model context — three registered commands, all three delivered in the same event:So either this was fixed between 2.1.214 and 2.1.229, or it is specific to the TUI path — the client difference seems worth checking before assuming it is still broken everywhere.
On
PostCompactitself, separate from the firing problem: in this build its runner feedsuserDisplayMessage, which is on-screen text rather than model context. So even when it does fire, it cannot be used to re-inject context after compaction —SessionStartwith thecompactmatcher is the path that works. Worth documenting, because the name strongly suggests otherwise.Could not reproduce on v2.1.233 (macOS, Apple Silicon). In interactive mode a manual
/compactfired the full sequence:PreCompact→SessionStart(source: "compact") →PostCompact(trigger: "manual", withcompact_summary). Print mode behaved the same.Steps:
.claude/settings.jsonwithcommandhooks forPreCompact,PostCompact, andSessionStartthat append their stdin payload to a log file.claudeinteractively and send one prompt to seed context./compactand press Enter (repeated once more with/compact focus on the hook setup).Observed (hook log, both compactions):
The TUI also showed
PostCompact [...] completed successfullyunder the "Compacted" line.Expected: exactly this, per the hooks docs (https://code.claude.com/docs/en/hooks#postcompact) —
PostCompactwith themanualmatcher runs after/compact, in interactive and print mode alike.Assessment: your expectation is right and the docs agree —
PostCompactshould fire after a manual/compactin interactive mode. On v2.1.233 it does (interactive and print mode go through the same compaction path, and bothPostCompactandSessionStartwithsource: "compact"fire), and the comment above reportsSessionStart(compact)firing on 2.1.229 too, so this appears to have been resolved somewhere between 2.1.214 and 2.1.233. Closing as fixed. If you still seePostCompactmissing on v2.1.233 or later, please comment with the version, whether the hooks live in~/.claude/settings.jsonor project settings, and roughly how long the compaction ran, and we'll reopen. See the changelog: https://github.com/anthropics/claude-code/blob/main/CHANGELOG.mdOne clarification on the second comment:
PostCompactoutput is intentionally display-only (itssystemMessage/continuefields are ignored, per the docs). To re-inject context after compaction, use aSessionStarthook with thecompactmatcher.🤖 Generated with Claude Code
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.