[BUG] Stack Overflow Near Maximum Context Length

Resolved 💬 7 comments Opened Jan 8, 2026 by oguzhanmeteozturk Closed Feb 24, 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?

Claude Code CLI crashes with a RangeError: Maximum call stack size exceeded when the session approaches maximum context length. The crash occurs during tool execution and message processing, making the CLI completely unusable as sessions get longer.

The error happens after streaming tool results have begun processing, and the application terminates without gracefully handling the situation.

What Should Happen?

The CLI should handle sessions approaching maximum context length gracefully without crashing. It should continue to function normally even as context accumulates.

Error Messages/Logs

RangeError: Maximum call stack size exceeded
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js v20.19.3

**Stack trace location:**
- File: `/@anthropic-ai/claude-code/cli.js`
- Line: 3437

**Related functions in stack:**
- `yF1()`, `GZ7()`, `ZZ7()` - Tool execution and result processing
- `yN()` - Main query function (async generator)
- Post-tool hooks and context modification handlers

Steps to Reproduce

  1. Start a Claude Code session and begin working on a task
  2. Execute multiple tool operations and continue the conversation
  3. Build up the conversation context over multiple turns
  4. Continue until the session approaches maximum context length
  5. Execute additional tools or request further processing
  6. Application crashes with stack overflow error

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.0.76

Claude Code Version

2.1.1

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

The recursive nature of the yN async generator function (main query loop) causes deep call stacks when:

  • Processing recursive queries with tool results
  • Managing context modifications across nested tool calls
  • Operating near maximum context length where additional recursion depths are accumulated

The recursion depth accumulates with each:

  • Tool execution cycle
  • Message attachment/hook processing
  • Recursive yN call for continued processing

At maximum context length, the overhead of context management + recursive tool processing exceeds Node.js's call stack limit.

Related Code Paths

The crash occurs in the interaction between:

  • Main async generator that recursively calls itself for continued processing
  • Context compaction and autocompact logic
  • Message queuing and hook processing

🤖 Generated with Claude Code

View original on GitHub ↗

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