[BUG] "Prompt is too long" error when SessionStart hooks inject large context
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:
- Hook-injected context (documentation TOCs from ~6MB of reference files)
- Project structure hook outputting directory tree
- Session debugging templates with jq query examples
- 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:
- Graceful degradation: Automatically truncate or summarize injected context when approaching token limits
- Pre-flight check: Warn users before session start if the combined hook output would exceed limits
- 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
- Navigate to any directory:
``bash``
cd ~/.claude
- Start Claude Code session:
``bash``
claude
- Attempt any prompt:
````
can you audit of all the hooks, available, enabled, etc.
- Observe "Prompt is too long" error immediately
- Try a simpler follow-up:
````
what is your session id
- 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
- Token budget visibility: Show remaining token budget after hook injection, before user prompt
- Per-hook token accounting: Log how many tokens each SessionStart hook consumes
- Automatic truncation: When hooks exceed a threshold (e.g., 80% of context), automatically truncate with a warning
- Hook timeout/size limits: Allow users to configure max output size per hook in
settings.json
Workarounds
Users experiencing this issue can:
- Reduce the number/size of SessionStart hooks
- Avoid injecting large documentation files directly (use TOCs or summaries instead)
- 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗