Skip to content

Consolidate hooks/mempal_*_hook.sh into thin wrappers delegating to mempalace hook run #1069

@sha2fiddy

Description

@sha2fiddy

After #833 and #942 (both merged 2026-04-21), the repo carries two Stop/PreCompact hook implementations doing the same job with diverging architectures:

Path Shape Stdin parsing mempalace call
hooks/mempal_*_hook.sh (legacy) Fat bash, ~120 LoC Inline python3 -c "import json,sys; ..." + JSONL heredoc, gated on MEMPAL_PYTHON (#833) "$MEMPALACE_BIN" mine (#340)
.claude-plugin/hooks/mempal-*-hook.sh (plugin) Thin wrapper, ~23 LoC Delegated to mempalace/hooks_cli.py mempalace hook run --hook {stop,precompact} --harness claude-code with 3-tier fallback (#942)

Both are user-facing — mempalace init wires one or the other depending on install flavor.

Cost of the split:

  1. Every new knob gets written twice or applies on only one path. MEMPAL_PYTHON is inert on the plugin path; hooks.auto_save (feat: add hooks.auto_save config toggle (silent mode) #711) is only honored wherever the PR author remembers.
  2. Open fixes entrench the duplication: fix: resolve Python interpreter in hook scripts instead of hardcoding python3 #670 threads a find_python() into both paths rather than collapsing one; feat: add mempalace-mcp entry point for uv compatibility #805 explicitly leaves the legacy python3 -c calls alone.
  3. Forked test surface — tests/test_hooks_shell.py, tests/test_claude_plugin_hook_wrappers.py, tests/test_hooks_cli.py each cover a different slice.

Proposal:

Reshape hooks/mempal_*_hook.sh to match the plugin wrappers — a 3-tier run_mempalace_hook() function that calls mempalace hook run --hook {stop|precompact} --harness claude-code. All real logic (JSON parsing, exchange counting, 15-message block decision, background mine) already lives in mempalace/hooks_cli.py for the plugin path; any gaps get ported once.

Result: inline python3 -c disappears from bash (killing the three failure modes discussed on #833 for any future mempalace-importing addition), MEMPAL_PYTHON becomes obsolete, and MEMPAL_VERBOSE / hooks.auto_save / future toggles live in one place. Pure refactor — same exchange counts, same block text, same ~/.mempalace/hook_state/hook.log.

Related: #340, #513, #670, #805, #833, #942.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/hooksClaude Code hook scripts (Stop, PreCompact, SessionStart)enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions