claude-code - 💡(How to fix) Fix [BUG] Session exits silently with 'API Error: Out of memory' mid-turn on AWS Bedrock [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#51755Fetched 2026-04-22 07:53:43
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4cross-referenced ×1

Error Message

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

Code Example

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

---

# From ~/.claude/projects/<project>/0a80a98a-2efd-473d-8988-80fe42db6e92.jsonl (tail)

{"type":"assistant","message":{"role":"assistant","stop_reason":"stop_sequence","content":"API Error: Out of memory"}}
{"type":"system","subtype":"turn_duration",...}
{"type":"last-prompt",...}
{"type":"permission-mode",...}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Claude Code session terminates unexpectedly mid-turn with no user-facing error message. The session was in the middle of an agentic loop (multiple sequential Bash tool calls) when it silently exited. The only evidence of the failure is visible in the .jsonl transcript file, where the final entries show:

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

No error dialog, no warning, no graceful shutdown — the session just disappears.

What Should Happen?

Claude Code should catch the API Error: Out of memory response from Bedrock and surface it to the user with a meaningful message (e.g., "The session ran out of memory — try /compact to reduce context size and resume"). Silently exiting leaves the user with no indication of what happened or how to recover.

Error Messages/Logs

# From ~/.claude/projects/<project>/0a80a98a-2efd-473d-8988-80fe42db6e92.jsonl (tail)

{"type":"assistant","message":{"role":"assistant","stop_reason":"stop_sequence","content":"API Error: Out of memory"}}
{"type":"system","subtype":"turn_duration",...}
{"type":"last-prompt",...}
{"type":"permission-mode",...}

No Stop hook fired, confirming the exit was not a clean/graceful shutdown.

Steps to Reproduce

  1. Start a Claude Code session on AWS Bedrock with a multi-step agentic task
  2. Run a long sequence of tool calls (15+ turns) that accumulate significant context (~280KB transcript)
  3. Observe: session exits silently mid-turn with no error shown to the user
  4. Check the .jsonl transcript at ~/.claude/projects/<project>/<session-id>.jsonl — the final entry will show stop_reason: stop_sequence and content: API Error: Out of memory

Claude Model

Sonnet (default) — us.anthropic.claude-sonnet-4-6

Is this a regression?

I don't know

Claude Code Version

2.1.116 (Claude Code)

Platform

AWS Bedrock

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

  • Session ID: 0a80a98a-2efd-473d-8988-80fe42db6e92
  • Transcript size at exit: 284KB
  • Region: us-west-2
  • A prior session in the same project (e49fb48f) was 1.2MB and completed normally — the OOM occurred in a smaller subsequent session, suggesting it may be request-size related rather than cumulative transcript size
  • Session logging hooks (SessionStart / Stop) were added after this incident; the missing Stop hook entry confirmed the exit was ungraceful
  • A duplicate issue was filed before discovering the template: #51754 (being closed in favor of this one)

extent analysis

TL;DR

The session termination is likely due to the "API Error: Out of memory" response from Bedrock, which is not being caught and surfaced to the user, causing the Claude Code session to exit silently.

Guidance

  • Investigate the stop_reason: stop_sequence and content: API Error: Out of memory entries in the .jsonl transcript file to understand the root cause of the error.
  • Consider implementing a check for the "API Error: Out of memory" response and handle it by surfacing a meaningful error message to the user, such as "The session ran out of memory — try /compact to reduce context size and resume".
  • Review the session logging hooks (SessionStart / Stop) to ensure they are correctly configured to capture and log session termination events.
  • Examine the transcript size and request size to determine if there is a correlation between the two and the occurrence of the out-of-memory error.

Example

No code snippet is provided as the issue does not contain sufficient information to create a specific example.

Notes

The issue may be related to the request size rather than the cumulative transcript size, as suggested by the fact that a prior session with a larger transcript size completed normally. Further investigation is needed to determine the root cause of the error.

Recommendation

Apply a workaround to catch and handle the "API Error: Out of memory" response, such as implementing a check for this error and surfacing a meaningful error message to the user. This will provide a better user experience and help to diagnose the root cause of the issue.

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 silently with 'API Error: Out of memory' mid-turn on AWS Bedrock [1 participants]