claude-code - 💡(How to fix) Fix [BUG] Session exits with 'API Error: Out of memory' mid-turn on Bedrock (stop_sequence) [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#51754Fetched 2026-04-22 07:53:45
View on GitHub
Comments
1
Participants
1
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
labeled ×4closed ×1commented ×1cross-referenced ×1

Claude Code session terminates unexpectedly mid-turn with stop_sequence and the final content entry in the transcript reads API Error: Out of memory. No error is surfaced to the user in the UI — the session just exits.

Error Message

"stop_reason": "stop_sequence" "content": "API Error: Out of memory"

Root Cause

Claude Code session terminates unexpectedly mid-turn with stop_sequence and the final content entry in the transcript reads API Error: Out of memory. No error is surfaced to the user in the UI — the session just exits.

Code Example

"stop_reason": "stop_sequence"
"content": "API Error: Out of memory"
RAW_BUFFERClick to expand / collapse

Description

Claude Code session terminates unexpectedly mid-turn with stop_sequence and the final content entry in the transcript reads API Error: Out of memory. No error is surfaced to the user in the UI — the session just exits.

Steps to Reproduce

  1. Run a multi-step agentic session with many tool calls accumulating in context
  2. Session builds up significant context (~280KB transcript) over multiple tool-use rounds
  3. At some point mid-turn, the session exits with stop_sequence / API Error: Out of memory

Expected Behavior

Session should surface an error to the user (e.g., "context too large" or "out of memory") and ideally offer to compact/summarize before retrying rather than silently exiting.

Actual Behavior

Session exits without any user-facing error message. The only evidence is in the .jsonl transcript file:

"stop_reason": "stop_sequence"
"content": "API Error: Out of memory"

Environment

  • Claude Code version: 2.1.116
  • Platform: macOS (Darwin 25.4.0)
  • Model: us.anthropic.claude-sonnet-4-6 via AWS Bedrock (us-west-2)
  • Provider: AWS Bedrock (CLAUDE_CODE_USE_BEDROCK=1)

Transcript Evidence

  • Session ID: 0a80a98a-2efd-473d-8988-80fe42db6e92
  • Transcript size at exit: 284KB
  • Session duration: Active multi-turn agentic loop with ~15+ tool calls
  • Last stop_reason in transcript: stop_sequence
  • Last content in transcript: API Error: Out of memory

The session was mid-way through an agentic loop (gathering data via multiple Bash tool calls). The exit occurred after accumulating significant context across many turns.

Additional Notes

  • A prior session in the same project (e49fb48f, 1.2MB) had completed normally — the OOM occurred in a subsequent session, not on the largest transcript
  • No Stop hook fired confirming the exit was not a clean/graceful shutdown
  • The error appears to originate at the Bedrock API layer, but Claude Code does not handle or surface it gracefully

extent analysis

TL;DR

The session termination with "API Error: Out of memory" suggests that the Claude Code session is exceeding a memory limit, potentially due to the large transcript size, and a workaround or fix is needed to handle this scenario more gracefully.

Guidance

  • Investigate the memory limits imposed by the Bedrock API and AWS environment to understand if there's a specific threshold that's being exceeded.
  • Consider implementing a mechanism to monitor transcript size and proactively manage or compact it before it reaches a critical size, potentially preventing the out-of-memory error.
  • Review the Claude Code error handling to see if there's a way to catch and surface the "API Error: Out of memory" more gracefully to the user, rather than silently exiting the session.
  • Examine if there are any configuration options or environment variables (like CLAUDE_CODE_USE_BEDROCK) that could be adjusted to mitigate this issue or increase available memory.

Example

No specific code example can be provided without more context on the Claude Code and Bedrock API interactions, but a potential approach might involve periodically checking the transcript size and triggering a compaction or summary mechanism when it approaches a certain threshold.

Notes

The fact that a prior session with a larger transcript completed normally suggests that the issue might not be solely with the transcript size, and other factors such as the specific sequence of tool calls or the state of the agentic loop could be contributing to the error.

Recommendation

Apply a workaround to monitor and manage transcript size, as upgrading to a fixed version is not explicitly mentioned as an option in the provided issue context. This approach allows for immediate mitigation of the issue while further investigation into the root cause and potential long-term fixes can continue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Session exits with 'API Error: Out of memory' mid-turn on Bedrock (stop_sequence) [1 comments, 1 participants]