[BUG] Interactive mode: manual /compact fires PreCompact but never PostCompact (print mode fires both) — v2.1.214, macOS

Status Fixed / completed
Reported on v2.1.214
Maintainer reply ✓ Yes — bcherny
Activity 3 comments · opened Jul 18, 2026 · closed Aug 16, 2026
💡 Likely answer: A maintainer (bcherny, collaborator) responded on this thread — see the highlighted reply below.

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.json for both PreCompact and PostCompact (simple command hooks)

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):

  1. SessionStart source:"resume"
  2. PreCompact trigger:"manual", custom_instructions:null
  3. SessionStart source:"compact"
  4. PostCompact trigger:"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).

View original on GitHub ↗

3 Comments

JhouCode · 2 months ago

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.229 on Linux (not the macOS TUI).

On a manual /compact (compactMetadata.trigger: "manual"), my SessionStart hooks with matcher: "compact" fired and their stdout reached the model context — three registered commands, all three delivered in the same event:

21:06:42  sid=df486c1d…  emitted=compact-slice1
21:06:42  sid=df486c1d…  emitted=compact-slice2
21:06:42  sid=df486c1d…  emitted=compact-slice3

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 PostCompact itself, separate from the firing problem: in this build its runner feeds userDisplayMessage, 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 — SessionStart with the compact matcher is the path that works. Worth documenting, because the name strongly suggests otherwise.

bcherny collaborator · 2 months ago

Could not reproduce on v2.1.233 (macOS, Apple Silicon). In interactive mode a manual /compact fired the full sequence: PreCompact → SessionStart (source: "compact") → PostCompact (trigger: "manual", with compact_summary). Print mode behaved the same.

Steps:

  1. In a fresh project, add .claude/settings.json with command hooks for PreCompact, PostCompact, and SessionStart that append their stdin payload to a log file.
  2. Start claude interactively and send one prompt to seed context.
  3. Type /compact and press Enter (repeated once more with /compact focus on the hook setup).

Observed (hook log, both compactions):

SessionStart  source=startup
PreCompact    trigger=manual
SessionStart  source=compact
PostCompact   trigger=manual, compact_summary present
PreCompact    trigger=manual
SessionStart  source=compact
PostCompact   trigger=manual, compact_summary present

The TUI also showed PostCompact [...] completed successfully under the "Compacted" line.

Expected: exactly this, per the hooks docs (https://code.claude.com/docs/en/hooks#postcompact) — PostCompact with the manual matcher runs after /compact, in interactive and print mode alike.

Assessment: your expectation is right and the docs agree — PostCompact should fire after a manual /compact in interactive mode. On v2.1.233 it does (interactive and print mode go through the same compaction path, and both PostCompact and SessionStart with source: "compact" fire), and the comment above reports SessionStart(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 see PostCompact missing on v2.1.233 or later, please comment with the version, whether the hooks live in ~/.claude/settings.json or 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.md

One clarification on the second comment: PostCompact output is intentionally display-only (its systemMessage/continue fields are ignored, per the docs). To re-inject context after compaction, use a SessionStart hook with the compact matcher.

🤖 Generated with Claude Code

github-actions[bot] · 12 days ago

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.