[BUG] "Prompt is too long" error when SessionStart hooks inject large context

Resolved 💬 3 comments Opened Dec 28, 2025 by coygeek Closed Dec 28, 2025

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?

When starting a Claude Code session with multiple SessionStart hooks that inject documentation and context, the prompt can exceed token limits before the user even types anything. The session fails immediately with "Prompt is too long" - even simple follow-up messages like "what is your session id" also fail.

The combination of:

  1. Hook-injected context (documentation TOCs from ~6MB of reference files)
  2. Project structure hook outputting directory tree
  3. Session debugging templates with jq query examples
  4. Multiple other SessionStart hooks adding incremental context

...exceeded the model's 200k context window limit at session initialization.

What Should Happen?

Claude Code should either:

  1. Graceful degradation: Automatically truncate or summarize injected context when approaching token limits
  2. Pre-flight check: Warn users before session start if the combined hook output would exceed limits
  3. Clearer error: Show which hooks contributed how much context, so users can debug

The user should be able to have a functional session even with large injected contexts.

Error Messages/Logs

Prompt is too long


(This was the only error message displayed - no additional context about token counts, which hooks contributed, or how to resolve)

Steps to Reproduce

Steps to Reproduce

. Create multiple SessionStart hooks that inject large documentation:

  • Hook injecting ~6MB of documentation TOCs (multiple large markdown files)
  • Hook injecting project directory tree structure
  • Hook injecting session debugging templates with jq examples
  1. Navigate to any directory:

``bash
cd ~/.claude
``

  1. Start Claude Code session:

``bash
claude
``

  1. Attempt any prompt:

``
can you audit of all the hooks, available, enabled, etc.
``

  1. Observe "Prompt is too long" error immediately
  1. Try a simpler follow-up:

``
what is your session id
``

  1. Observe "Prompt is too long" error again - the session is completely unusable

---

Session Details

  • Session ID: 1ebfe4e9-d4ba-4a3a-ba72-30183991294d
  • Project Directory: /Users/user/.claude
  • When: December 28, 2025 02:01 UTC

Context Contributors

| Hook | Estimated Size |
|------|---------------|
| inject_docs.py | ~6MB total (968KB Claude docs + 5.1MB Git docs + 100KB prompt engineering + 6 guides) |
| project_structure.py | 1KB-50KB (tree output, highly variable) |
| session_optimizer.py | 500B-10KB (LLM project analysis) |
| session_id_display.py | ~2.5KB (debugging template with jq examples) |

Key Observation

The /Users/user/.claude directory is not a git repository, so git-related hooks weren't a factor. The error was caused purely by SessionStart hook content injection exceeding the context limit before any user interaction.

---

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.0.76

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Suggested Improvements

  1. Token budget visibility: Show remaining token budget after hook injection, before user prompt
  2. Per-hook token accounting: Log how many tokens each SessionStart hook consumes
  3. Automatic truncation: When hooks exceed a threshold (e.g., 80% of context), automatically truncate with a warning
  4. Hook timeout/size limits: Allow users to configure max output size per hook in settings.json

Workarounds

Users experiencing this issue can:

  1. Reduce the number/size of SessionStart hooks
  2. Avoid injecting large documentation files directly (use TOCs or summaries instead)
  3. Ensure git working directory is clean before starting sessions

Related

This may be related to how Claude Code calculates available context when multiple hooks inject content simultaneously. The error provides no diagnostic information about what exceeded limits or by how much.

View original on GitHub ↗

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