Skip to content

feat(pst): PostCompact hook to recover ledger state after auto compact#65

Merged
pstaylor-patrick merged 2 commits into
mainfrom
feat/pst-post-compact-hook
Jun 20, 2026
Merged

feat(pst): PostCompact hook to recover ledger state after auto compact#65
pstaylor-patrick merged 2 commits into
mainfrom
feat/pst-post-compact-hook

Conversation

@pstaylor-patrick

Copy link
Copy Markdown
Owner

Summary

  • Adds pst-post-compact.rb wired to the Claude Code PostCompact (matcher: auto) hook event
  • After auto compact: re-inits the ledger JSON if the file was lost, emits user-visible in-flight task summary
  • Clarifies the architecture: PostCompact stdout goes to the user terminal only (not injected into Claude's context); the rule-22 nudge in pst-prompt-reminder.rb handles Claude's per-turn ledger awareness via UserPromptSubmit
  • pst-mode.rb install step now includes pst-post-compact.rb so re-arming always updates all hook binaries

Why PostCompact can't inject into Claude's context

Per the Claude Code hooks docs, PostCompact is a "context only / no blocking" event -- its output is shown to the user terminal but not to Claude. Claude regains ledger awareness on the next UserPromptSubmit via the rule-22 nudge (already implemented in the previous PR).

Test plan

  • Invoke /pst, register a task with pst-ledger.rb register, trigger a /compact, confirm the user sees in-flight summary in terminal
  • Verify pst-prompt-reminder.rb rule-22 nudge fires on the next user message post-compact

🤖 Generated with Claude Code

https://claude.ai/code/session_019BCr5Qxi8jXnG2Rr7zdkw1

pstaylor-patrick and others added 2 commits June 20, 2026 11:07
…paction

Adds pst-post-compact.rb wired to the PostCompact auto event. After an
auto compact, the hook re-inits the ledger JSON if the file was lost and
emits a user-visible summary of in-flight tasks. Claude picks up ledger
state on the next turn via the rule-22 nudge in pst-prompt-reminder.rb
(PostCompact stdout is shown to the user only, not injected into context).

Also fixes stale hook binaries: pst-mode.rb's install step now includes
pst-post-compact.rb so re-arming keeps all hooks current.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019BCr5Qxi8jXnG2Rr7zdkw1
…ocess

pst-ledger.rb resolve_sid checks ENV['CLAUDE_SESSION_ID'] first; without
it, stdin is /dev/null so resolve_sid returns '' and init exits 1 silently.
Pass the session id as an env var so the subprocess can resolve it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019BCr5Qxi8jXnG2Rr7zdkw1
@pstaylor-patrick pstaylor-patrick merged commit 9281a7e into main Jun 20, 2026
1 check passed
@pstaylor-patrick pstaylor-patrick deleted the feat/pst-post-compact-hook branch June 20, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant