Skip to content

feat(hooks): configurable save_interval via config + env var - #1345

Open
rusel95 wants to merge 1 commit into
MemPalace:developfrom
rusel95:feat/hooks-save-interval
Open

feat(hooks): configurable save_interval via config + env var#1345
rusel95 wants to merge 1 commit into
MemPalace:developfrom
rusel95:feat/hooks-save-interval

Conversation

@rusel95

@rusel95 rusel95 commented May 4, 2026

Copy link
Copy Markdown

😤 The problem

The stop hook fires every 15 messages. Always. No way to change it without editing source code or uninstalling the plugin.

For long coding sessions this is fine. For a quick 3-message task it is noise. For a CI/automation context it is a blocker.

✅ What this does

Makes the interval configurable — via config file or env var:

// ~/.mempalace/config.json
{"hooks": {"save_interval": 30}}
# Or via env var (takes precedence)
MEMPALACE_HOOKS_SAVE_INTERVAL=30   # save every 30 messages
MEMPALACE_HOOKS_SAVE_INTERVAL=0    # disable stop hook entirely

Priority: env var > config file > default (15)

Setting save_interval: 0 disables the stop hook without uninstalling it. Negative values are clamped to 0.

🔑 Key design decision

save_interval controls only the stop hook. The precompact hook is independent (see PR #1346). Disabling periodic saves does not disable the last-chance save before context compression.

🧪 Tests

All 104 existing hook and config tests pass.

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

Closes #494.

Replaces hardcoded SAVE_INTERVAL = 15 with hooks.save_interval in config.

Config (~/.mempalace/config.json):
    {"hooks": {"save_interval": 30}}

Env var (takes precedence):
    MEMPALACE_HOOKS_SAVE_INTERVAL=30
    MEMPALACE_HOOKS_SAVE_INTERVAL=0   # disable stop hook

Priority: env var > config file > default (15). Negative values clamped to 0.

Closes MemPalace#494.
@rusel95
rusel95 force-pushed the feat/hooks-save-interval branch from 4844e70 to 5fca8dc Compare May 4, 2026 11:43
@rusel95

rusel95 commented May 4, 2026

Copy link
Copy Markdown
Author

✅ End-to-end testing completed

Verified against the real MempalaceConfig class and hook_stop() function — no mocks for the config path.

Tests verified:

  • Default interval = 15 ✅
  • MEMPALACE_HOOKS_SAVE_INTERVAL=50 → interval = 50 ✅
  • MEMPALACE_HOOKS_SAVE_INTERVAL=0 → hook disabled ✅
  • MEMPALACE_HOOKS_SAVE_INTERVAL=-5 → clamped to 0 ✅
  • Config file {"hooks": {"save_interval": 30}} → interval = 30 ✅
  • Independence: save_interval=0 does NOT affect precompact
python -m pytest tests/test_hooks_cli.py tests/test_config.py -v
104 passed in 0.65s

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
marcoaperez added a commit to Taiko-Solutions/mempalace that referenced this pull request Aug 15, 2026
…lace#1441

Upstream replaced mapfile with sed -n 'Np' specifically so these hooks
run on macOS /bin/bash 3.2 (see comments in both hook files) — the
exact problem our custom #!/opt/homebrew/bin/bash shebang worked around.
Verified: no mapfile usage remains, both hooks pass `bash -n` under
plain /bin/bash.

SAVE_INTERVAL=25 override kept — upstream still hardcodes 15 with no
env var, PR MemPalace#1345 never landed.

Part of Proyectos/Taiko/MemPalace/18-Estrategia-Upgrade-v3.7.0.md (Pista B4).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@igorls

igorls commented Aug 15, 2026

Copy link
Copy Markdown
Member

Thanks for this contribution, and apologies for the slow turnaround.

develop has moved a fair way since this was opened and the branch no longer merges cleanly. If you're still interested in landing it, could you rebase onto current develop? Once it merges cleanly and CI is green I'll get it reviewed for the 3.8.0 cycle.

If you'd rather not pick it back up, no problem at all — just say so and I'll close it out, and thanks either way for taking the time to send it.

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.

Feature Request: Add a "Silent Mode" / Background Processing for the Stop Hook (Auto-save)

2 participants