Skip to content

PreCompact hook blocks compaction permanently — should use systemMessage instead #941

@dkfedalv

Description

@dkfedalv

Bug

hook_precompact in hooks_cli.py returns {"decision": "block", "reason": ...} (line 216). This permanently prevents compaction in Claude Code — both manual (/compact) and automatic.

The intent is to remind the AI to save session content before context is lost. But decision: "block" prevents the compaction from ever happening, which defeats the purpose.

Reproduction

  1. Install mempalace with Claude Code hooks (Stop + PreCompact)
  2. Run /compact in Claude Code
  3. Result: "Compaction blocked by PreCompact hook" — compaction never occurs
  4. Auto-compaction also never fires — same code path

Fix

In hooks_cli.py, hook_precompact function (~line 216):

# Before (blocks compaction permanently)
_output({"decision": "block", "reason": PRECOMPACT_BLOCK_REASON})

# After (injects save instructions without blocking)
_output({"systemMessage": PRECOMPACT_BLOCK_REASON})

systemMessage injects the save instructions into the AI's context so it can act on them, while allowing compaction to proceed. This is the correct Claude Code hook contract for "do something before this event" vs "prevent this event".

The Stop hook already handles this correctly — it uses decision: "block" intentionally for the two-pass save cycle (block → AI saves → AI stops again → stop_hook_active lets it through). PreCompact has no such two-pass mechanism, so blocking is always permanent.

Versions

  • mempalace 3.3.0
  • Python 3.14
  • Claude Code (current)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions