Skip to content

feat(hooks): independent precompact toggle via config + env var#1346

Open
rusel95 wants to merge 1 commit intoMemPalace:developfrom
rusel95:feat/hooks-precompact-toggle
Open

feat(hooks): independent precompact toggle via config + env var#1346
rusel95 wants to merge 1 commit intoMemPalace:developfrom
rusel95:feat/hooks-precompact-toggle

Conversation

@rusel95
Copy link
Copy Markdown

@rusel95 rusel95 commented May 4, 2026

🚫 The problem

You are in a long session. Context fills up. You type /compact. Nothing happens.

The precompact hook is blocking compaction. You cannot disable it without also disabling the stop hook. You are stuck.

This was the #1 reported issue after the initial precompact hook shipped. PR #863 fixed the hard-block by making precompact always return {} — but that dropped the save nudge entirely. Users now get no signal that compaction is imminent.

✅ What this does

Adds an independent toggle for the precompact hook:

// ~/.mempalace/config.json
{"hooks": {"precompact": false}}
# Or via env var
MEMPALACE_HOOKS_PRECOMPACT=false

When disabled, /compact proceeds immediately — no mine, no delay.

🔑 Why independent controls matter

Scenario save_interval precompact
Normal use 15 (default) true (default)
Quiet mode — fewer interruptions 50 true
Precompact causing issues 15 false
Fully silent 0 true

Disabling save_interval does not disable precompact. Disabling precompact does not disable the stop hook. They are independent by design — so you can fix one without breaking the other.

🧪 Tests

All 104 existing hook and config tests pass.

python -m pytest tests/test_hooks_cli.py tests/test_config.py -q
104 passed

Depends on: #1345 (save_interval config, same config.py property pattern)
Closes #949. Closes #906.

Adds hooks.precompact boolean (default true). Setting false lets /compact
proceed without the pre-compaction mine, independent of save_interval.

Config (~/.mempalace/config.json):
    {"hooks": {"precompact": false}}

Env var (takes precedence):
    MEMPALACE_HOOKS_PRECOMPACT=false

Disabling save_interval does NOT disable precompact and vice versa.

Closes MemPalace#949. Closes MemPalace#906.
@rusel95
Copy link
Copy Markdown
Author

rusel95 commented May 4, 2026

✅ End-to-end testing completed

Verified against the real MempalaceConfig class and hook_precompact() function.

Tests verified:

  • Default precompact = true ✅
  • MEMPALACE_HOOKS_PRECOMPACT=false → disabled ✅
  • MEMPALACE_HOOKS_PRECOMPACT=true → enabled ✅
  • Independence test: save_interval=0 + no precompact env → precompact still true ✅

This is the critical test — it proves the two controls are truly independent. Disabling periodic saves does not silently disable the last-chance save before compaction.

python -m pytest tests/test_hooks_cli.py tests/test_config.py -v
104 passed in 0.59s

Full suite: 0 regressions.

@igorls igorls added enhancement New feature or request area/hooks Claude Code hook scripts (Stop, PreCompact, SessionStart) labels May 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) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PreCompact hook blocks indefinitely — no escape condition preCompact hook prevents compacting when context limit is reached in claude code

2 participants