[BUG] Hooks cause RangeError: Invalid string length crash on every prompt (v2.0.76)
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?
Any hook defined in .claude/settings.json causes Claude Code to crash with RangeError: Invalid string length on the first prompt. The crash occurs even with specific matchers and without @ file references. Only removing hooks entirely fixes the issue.
Initial error also showed: "Hook contains malformed recursive/nested prompt structure. The prompt argument contains escaped copies of the entire hook invocation, creating nested recursion."
What Should Happen?
Hooks should process normally without causing infinite string expansion or crashes.
Error Messages/Logs
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
RangeError: Invalid string length
at JSON.stringify (<anonymous>)
at file:///C:/Users/[username]/AppData/Roaming/npm/node_modules/@anthropic-ai/claude-code/cli.js:4593:161
at runNextTicks (node:internal/process/task_queues:64:5)
at process.processImmediate (node:internal/timers:472:9)
Steps to Reproduce
- Create
.claude/settings.jsonin a project folder:
{
"hooks": {
"UserPromptSubmit": [
{
"matcher": "(?i)check the plan",
"hooks": [
{
"type": "prompt",
"prompt": "Check follow-ups.md for time-sensitive items."
}
]
}
]
}
}
- Start Claude Code in that folder:
claude - Type any message (e.g., "hi there")
- Crash occurs with RangeError
Note: Tried empty matcher, specific matcher, with/without @ file references - all crash. Only removing hooks entirely fixes it.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.76
Platform
Other
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
- Project has CLAUDE.md (23KB) and rules files (~36KB total) in .claude/rules/
- Workaround: Remove hooks from settings.json and manually invoke the intended behavior
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗