Skip to content

fix(hooks/precompact): unblock /compact and auto-compact - #1399

Closed
vasyl-pavlyuchok wants to merge 1 commit into
MemPalace:developfrom
vasyl-pavlyuchok:fix/precompact-hook-block
Closed

fix(hooks/precompact): unblock /compact and auto-compact#1399
vasyl-pavlyuchok wants to merge 1 commit into
MemPalace:developfrom
vasyl-pavlyuchok:fix/precompact-hook-block

Conversation

@vasyl-pavlyuchok

Copy link
Copy Markdown

Problem

The PreCompact hook always ends up returning a block decision, preventing both /compact (manual) and auto-compact from working for any user installing this plugin.

The current upstream hook routes through:

run_mempalace_hook --hook precompact --harness claude-code

Which calls mempalace hook run --hook precompact --harness claude-code, and that path returns block. Net effect: no user can compact while this plugin is active.

Fix

Have the hook return {"decision": "allow"} directly so compaction proceeds.

Session saving is NOT affected — it goes through the Stop hook (separate path), which continues to work as designed.

Verification

Tested in production VPS Claude Code environment:

  • /compact (manual) now works ✓
  • Auto-compact at context threshold now works ✓
  • Session saving via Stop hook unaffected ✓
  • MemPalace MCP server continues responding correctly ✓

Notes for maintainers

If the original blocking behavior was intentional (e.g. to enforce session save first), please consider an alternative implementation that allows compaction and triggers save — current behavior just blocks all compaction silently, which surprises users.

This patch takes the minimal-impact approach. Happy to iterate on a more nuanced solution if preferred.

The previous implementation routed through:
  mempalace hook run --hook precompact --harness claude-code

which always returned a block decision, preventing /compact (manual)
and auto-compact from running for any user installing this plugin.

This patch makes the hook return allow so compaction proceeds normally.
Session saving is unaffected since it goes through the Stop hook (separate path).

Tested in production environment — both /compact and auto-compact now work
correctly while session save behavior remains intact.
@vasyl-pavlyuchok
vasyl-pavlyuchok requested a review from bensig as a code owner May 7, 2026 02:27
@mvalentsev

Copy link
Copy Markdown
Contributor

This wouldn't merge as-is, for reasons that show up clearly against
develop tip:

  1. The premise -- that mempalace hook run --hook precompact returns
    block -- doesn't match the current code. mempalace/hooks_cli.py
    hook_precompact() ends with _output({}) after mining the
    transcript and palace synchronously. Empty JSON, not block. That
    was the fix(hooks): stop precompact hook from blocking compaction (#856, #858) #863 fix, merged 2026-04-15 (in v3.3.1+, published
    2026-04-18). If /compact is failing for you, you're likely on a
    pre-3.3.1 install -- bumping to v3.3.4 or current develop should
    make it work without touching the hook script.

  2. Side effect of the patch: it bypasses the _ingest_transcript and
    _mine_sync calls the Python path runs synchronously. That is the
    reason the PreCompact hook exists -- capture transcript and project
    mine before compaction loses the tool-output buffer. The Stop hook
    save path is separate and won't cover this.

  3. Minor: {"decision": "allow"} is not a documented value for the
    top-level decision field per
    https://code.claude.com/docs/en/hooks.md -- only "block" is. In
    practice Claude Code ignores the unknown value and proceeds, but
    fix: replace invalid 'decision: allow' with {} in hooks (closes #872) #885 (closes bug: hooks use invalid decision value "allow" — should be "approve" #872) specifically cleaned this up to use {}. The
    patch reintroduces the same spec-invalid form.

If /compact is genuinely still broken against develop tip, that
would be a fresh bug worth tracking with the version + repro steps.

@igorls igorls added bug Something isn't working area/hooks Claude Code hook scripts (Stop, PreCompact, SessionStart) labels May 8, 2026
@igorls

igorls commented Jun 6, 2026

Copy link
Copy Markdown
Member

Thanks! The precompact hook on develop already ends with an allow decision (since #863); this change would regress precompact mining. Closing as superseded.

@igorls igorls closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/hooks Claude Code hook scripts (Stop, PreCompact, SessionStart) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants