Skip to content

feat(hooks): add PreCompact hook to auto-trigger /ce:compound#250

Closed
mvanhorn wants to merge 1 commit intoEveryInc:mainfrom
mvanhorn:osc/95-feat-pre-compact-hook
Closed

feat(hooks): add PreCompact hook to auto-trigger /ce:compound#250
mvanhorn wants to merge 1 commit intoEveryInc:mainfrom
mvanhorn:osc/95-feat-pre-compact-hook

Conversation

@mvanhorn
Copy link
Contributor

Summary

  • Add a PreCompact prompt hook that checks if the session contains compoundable knowledge before context compaction
  • Uses type: "prompt" so the AI evaluates whether /ce:compound is warranted - skips silently if nothing significant was solved
  • Placed in plugins/compound-engineering/hooks/hooks.json which is auto-loaded by the parser's default path convention

Fixes #95

How it works

When Claude Code is about to compact context, the hook injects a prompt asking the AI to:

  1. Check if the session contains a solved problem, debugging insight, or discovered pattern
  2. If yes, run /ce:compound to capture it in docs/solutions/
  3. If nothing significant, skip silently (no disruption to user)

This ensures knowledge gets captured at the optimal moment - when full context is still available, before compaction loses the details.

Test plan

  • Install plugin and work through a debugging session
  • Trigger context compaction and verify the hook fires
  • Verify it skips silently when no significant problems were solved
  • Verify it triggers /ce:compound when a problem was solved

This contribution was developed with AI assistance (Claude Code).

Adds a PreCompact prompt hook that checks if the current session
contains a solved problem or debugging insight worth documenting.
If so, it triggers /ce:compound to capture the knowledge before
context compaction loses it.

The hook uses the "prompt" type so the AI evaluates whether compounding
is warranted - it skips silently if nothing significant was solved.

Fixes EveryInc#95

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tmchow
Copy link
Collaborator

tmchow commented Mar 13, 2026

@mvanhorn The main idea here is good to auto capture knowledge before it's lost. However, a PreCompact hook integration feels like the wrong triggers point. Lots of sessions have multiple compaction points so it'll be disruptive to flow, and compaction occurring doesn't necessarily mean knowledge is lost. Compaction mid-session might be the wrong time to actually try to compound.

Lastly, if context is about to be compacted, it means context is nearly full. Running ce:compound at that point may itself trigger compaction or fail due to limited remaining context.

@tmchow tmchow closed this Mar 13, 2026
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.

Add pre-compact hook to auto-trigger /compound workflow

2 participants