[BUG] Post-compact auto-read doubles hook injections — configurable autoReadFiles needed

Resolved 💬 4 comments Opened Apr 4, 2026 by VVisher Closed May 15, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

After /compact (manual or auto), Claude Code automatically re-reads recently-used files back into context. For users with UserPromptSubmit hooks that inject project state, this creates double injection on the first post-compact turn:

  1. Compact's auto-read pulls recently-used files (configs, source files, docs)
  2. Hook system injects overlapping content (same configs, status files, project state)

Example: a hook injects TODO.md on every prompt. Compact also auto-reads TODO.md because it was recently used. The model receives it twice. With 8+ hooks (status dashboard, linter config, test results, notification feed), the first post-compact turn adds 10-20K tokens of redundant content.

Additionally, the auto-reads don't restore useful context — the model gets file contents without knowing why they were in use (e.g., it was mid-refactor on a specific function). The model typically re-reads the file anyway to orient itself, making the auto-read a pure token waste.

This compounds with cache replay (see related issue): a bloated post-compact turn also increases the chance of breaking the prompt prefix cache, causing a full replay on the next message.

What Should Happen?

The auto-read behavior should be configurable. Proposed settings:

{
  "compact": {
    "autoReadFiles": "none" | "list" | "full",
    "suppressHooksPostCompact": false
  }
}
  • "none": compact summary only, no file re-reads (best for hook-heavy setups)
  • "list": summary + file list with context hints (e.g., server.py — mid-refactor, auth middleware)
  • "full": current behavior (default, backward compatible)
  • "suppressHooksPostCompact": skip UserPromptSubmit hooks for the first post-compact turn to prevent double injection

Error Messages/Logs

No error. Observed as token bloat on the first post-compact turn.

Steps to Reproduce

  1. Configure 4+ UserPromptSubmit hooks that inject project files (status, config, task list, etc.)
  2. Work in a session until auto-compact triggers (or run /compact manually)
  3. Observe the first post-compact prompt
  4. Count injected tokens — hooks inject their files, compact auto-reads the same files

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

_N/A_

Claude Code Version

2.1.92 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

Observed in a production hook system with 8+ UserPromptSubmit hooks. The first post-compact turn should be the leanest turn in the session — instead it's frequently the most bloated.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗