Skip to content

fix: stop hooks from making agents write in chat — save tokens#786

Merged
igorls merged 1 commit intodevelopfrom
pr/hooks-dont-write-in-chat
Apr 13, 2026
Merged

fix: stop hooks from making agents write in chat — save tokens#786
igorls merged 1 commit intodevelopfrom
pr/hooks-dont-write-in-chat

Conversation

@igorls
Copy link
Copy Markdown
Member

@igorls igorls commented Apr 13, 2026

Summary

Hooks stop interrupting the agent with save directives. All filing continues to happen in the background via python3 -m mempalace mine invoked inside the hooks. Authored by Milla (MSL).

What changes

Behavior change on both hooks:

Before After
mempal_save_hook.sh decision: block + "Save key topics, decisions, quotes..." decision: allow + "saved in background, no action needed"
mempal_precompact_hook.sh decision: block + "COMPACTION IMMINENT. Save ALL..." decision: allow + "saved verbatim in background, compaction can proceed"

Plus a small hooks/README.md update noting that hooks require a session restart after install.

Why

Every character in a block-hook reason becomes a system message in the conversation that retransmits on every subsequent turn. On long sessions that cost ~$1/session in wasted tokens and cluttered the chat. The core design principle in CLAUDE.md already commits to "Background everything — Nothing interrupts the user's conversation. Zero tokens spent on bookkeeping in the chat window." — this PR brings the hooks in line with that.

The background mining (python3 -m mempalace mine) is already running before the JSON emit in both hooks, so verbatim content is captured without agent participation.

Test plan

  • Full suite: 687/687 pass (2 version-consistency tests deselected — they're a pre-existing develop bug, pyproject=3.2.0 vs version.py=3.1.0)
  • bash -n syntax check on both hook scripts
  • Manual verification on a live Claude Code session — confirm no visible hook prompts and that background mining fires

Callouts for reviewers

  1. Functional change, not just cosmetic: agents no longer self-curate saved content via explicit tool calls. The background pipeline captures everything verbatim — which matches the "verbatim always" principle — but means agent-driven entity/KG curation via mempalace_kg_add etc. no longer happens at hook time. If KG enrichment depends on agent participation, it needs to move to a background step.
  2. Cherry-pick had trivial conflicts on both hook files because develop's reason text drifted slightly since the commit's base. Resolved by taking the new allow-decision bodies. Original authorship preserved.
  3. Three files, +15/-8 — tight surface area.

@igorls igorls added the P0 critical label Apr 13, 2026
@jphein
Copy link
Copy Markdown
Collaborator

jphein commented Apr 13, 2026

Great to see this addressed officially. Our #673 takes a complementary approach — instead of removing the save directive from the hook response, it switches the hook to call tool_diary_write() directly via Python ("silent mode"), bypassing the AI entirely. This makes saves deterministic and zero-token. The two approaches aren't mutually exclusive — #673's silent mode handles the save itself, so the agent never sees a save directive at all. Happy to align if there's a preferred direction.

The save hook and precompact hook were telling the agent to write
diary entries, add drawers, and add KG triples IN THE CHAT WINDOW.
Every line written stays in conversation history and retransmits on
every subsequent turn — ~$1/session in wasted tokens.

Fix: hooks now say "saved in background, no action needed" and use
decision: allow instead of block. The agent continues working without
interruption. All filing happens via the background pipeline.

Also updated hooks README with:
- Known limitation: hooks require session restart after install
- Updated cost section: zero tokens, background-only

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@igorls igorls force-pushed the pr/hooks-dont-write-in-chat branch from 10cf62e to a3b7988 Compare April 13, 2026 19:43
@igorls igorls merged commit c9fbf7c into develop Apr 13, 2026
@igorls igorls deleted the pr/hooks-dont-write-in-chat branch April 13, 2026 22:25
igorls added a commit that referenced this pull request Apr 14, 2026
Main had 9 commits that never back-merged into develop after the v3.2.0
release cycle. Resolving conflicts as follows:

- mempalace/version.py: keep develop (3.3.0 release target)
- README.md: keep develop (Milla's #835 audit is authoritative — main
  had stale 19 tools / 170 tokens / "30x lossless" / v3.0.0 label)
- hooks/mempal_{save,precompact}_hook.sh: keep develop (#786 reversed
  the #666 "decision=block" behavior intentionally to stop hooks from
  making agents write in chat)
- pyproject.toml: auto-merged — keeps develop's 3.3.0 and picks up
  main's chromadb upper-bound removal (#690)
- CONTRIBUTING.md, mempalace/hooks_cli.py: auto-merged cleanly —
  picks up main's improvements (fork-first clone, more detailed
  block reason strings that name MemPalace and specific tools)
- integrations/openclaw/SKILL.md: bumped 3.2.0 → 3.3.0 (version
  tracks the package per #761 convention)
- CHANGELOG.md: manual merge — kept develop's preamble + Unreleased
  v3.3.0 section + footer links; folded main's richer v3.2.0 entries
  (Packaging section for #690/#761; Bug Fixes #685/#677/#716/#707/
  #755/#757; Documentation #734/#733) into the v3.2.0 section;
  deduped the split Documentation sections that auto-merge produced
@igorls igorls mentioned this pull request Apr 14, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 critical

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants