Skip to content

preCompact hook prevents compacting when context limit is reached in claude code #906

@marcuswikstrom-dev

Description

@marcuswikstrom-dev

What happened?
context limit was reached and was not able to compact

What did you expect?
that the hook would run and then the context would be compacted
How to reproduce:

  1. Fully use mempalace in a claude code session
  2. Do complex tasks until context is full
  3. Try to compact

Got this error:

  ⎿  Context limit reached · /compact or /clear to continue · /model opus[1m]

✻ Crunched for 2m 53s

❯ /compact                                                                                                          
  ⎿  Error: Compaction blocked by PreCompact hook: [bash ${CLAUDE_PLUGIN_ROOT}/hooks/mempal-precompact-hook.sh]:
     COMPACTION IMMINENT (MemPalace). Save ALL session content before context is lost:
     1. mempalace_diary_write — thorough AAAK-compressed session summary
     2. mempalace_add_drawer — ALL verbatim quotes, decisions, code, context
     3. mempalace_kg_add — entity relationships (optional)
     Be thorough — after compaction, detailed context will be lost. Do NOT write to Claude Code's native auto-memory
      (.md files). Save everything to MemPalace, then allow compaction to proceed.

Seems like it should be possible to work around the always block part here.

Environment:

  • OS: Ubuntu 24.04
  • Python version: 3.1.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions