claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Stack Overflow Near Maximum Context Length

Open oguzhanmeteozturk opened this issue 1 month ago • 3 comments

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

oguzhanmeteozturk avatar Jan 08 '26 00:01 oguzhanmeteozturk

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/16368
  2. https://github.com/anthropics/claude-code/issues/15340
  3. https://github.com/anthropics/claude-code/issues/14607

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Jan 08 '26 00:01 github-actions[bot]

happening to me too

davidbenhaim avatar Jan 08 '26 19:01 davidbenhaim

Seeing what may be the same root cause in #16649 - compaction fails on sessions with pasted screenshots (base64 images).

The ~467KB base64 payload from a single screenshot pushes context usage up faster, which seems to trigger this stack overflow during compaction sooner. Compaction attempts repeatedly fail at 0% with no progress.

Both issues appeared in the 2.0.76 → 2.1.x timeframe.

kmichels avatar Jan 08 '26 21:01 kmichels

Still reproducing in 2.1.2 (macOS Darwin 25.2.0, Opus 4.5).

Crash occurred during normal conversation — no long context, no unusual tool usage. Just a simple discussion about symlinks when the stack overflow hit.

RangeError: Maximum call stack size exceeded
file:///.npm/_npx/.../node_modules/@anthropic-ai/claude-code/cli.js:3362

This confirms the regression persists from 2.1.1 → 2.1.2.

kuzmeech avatar Jan 09 '26 05:01 kuzmeech

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Feb 10 '26 10:02 github-actions[bot]

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Feb 24 '26 22:02 github-actions[bot]