openclaw - ✅(Solved) Fix Make CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS configurable (256KB hardcoded limit aborts long claude-cli turns) [1 pull requests, 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
openclaw/openclaw#70766Fetched 2026-04-24 05:53:55
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

The claude-cli runtime in execute.runtime-rara7Weg.js hardcodes a 256KB stdout buffer limit (CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS = 256 * 1024). When claude-cli emits a single stream-json line larger than this — common with extended thinking on Opus 4.7 / xhigh / max — the live session is aborted with "Claude CLI stdout buffer exceeded limit." and falls back to the next configured model. From the user's perspective this looks like a timeout.

Root Cause

The claude-cli runtime in execute.runtime-rara7Weg.js hardcodes a 256KB stdout buffer limit (CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS = 256 * 1024). When claude-cli emits a single stream-json line larger than this — common with extended thinking on Opus 4.7 / xhigh / max — the live session is aborted with "Claude CLI stdout buffer exceeded limit." and falls back to the next configured model. From the user's perspective this looks like a timeout.

Fix Action

Workaround

Setting agents.defaults.thinkingDefault: "adaptive" on Opus 4.7 (Anthropic's recommended setting per the extended thinking docs — fixed budgets were removed in 4.7) reduces the frequency, but does not eliminate the underlying issue: any large turn can still exceed 256KB.

PR fix notes

PR #70828: fix(cli-runner): make claude-cli stdout buffer limit configurable (#70766)

Description (problem / solution / changelog)

Summary

Closes #70766.

When a claude-cli turn on claude-opus-4-7 with high/xhigh/max thinking emits a single stream-json line above the hard-coded 256KB ceiling, handleClaudeStdout / parseClaudeLiveJsonLine abort the live session with Claude CLI stdout buffer exceeded limit. and fall back to the next configured model. Users see inconsistent voice / model + perceived timeouts.

Change

  • Introduce OPENCLAW_CLAUDE_CLI_MAX_STDOUT_BYTES env var. Values are parsed via Number.parseInt(..., 10):
    • unset / empty / non-numeric / zero / negative → default 256KB (current behavior, fully backward-compatible)
    • positive integer → that many characters
  • Include the actual line/buffer length and current limit in both abort messages so operators can see how much headroom they need.

Single file, ~25 lines net.

Test plan

  • pnpm oxlint src/agents/cli-runner/claude-live-session.ts → 0 warnings, 0 errors
  • Manual: set OPENCLAW_CLAUDE_CLI_MAX_STDOUT_BYTES=4194304 (4MB), restart gateway, re-run previously aborting turn → no abort. Unset or set to 0 / "abc" → falls back to 256KB default (no behavior change).

Out of scope

  • Exposing this via openclaw.json (agents.defaults.runners.claude-cli.maxStdoutBufferChars) — deferred; env var alone is enough to unblock operators today.
  • Raising the default — kept at 256KB to stay zero-surprise. Once the bundled runtime execute.runtime-*.js lands the same knob, the default can be bumped in a follow-up.

Changed files

  • src/agents/cli-runner/claude-live-session.ts (modified, +27/-3)

Code Example

{"event":"model_fallback_decision","decision":"candidate_failed",
 "candidateProvider":"claude-cli","candidateModel":"claude-opus-4-7",
 "reason":"format","status":400,
 "errorPreview":"Claude CLI stdout buffer exceeded limit.",
 "nextCandidateProvider":"openai-codex","nextCandidateModel":"gpt-5.5"}

---

const CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS = 256 * 1024; // line 306

// handleClaudeStdout, line ~601
if (session.stdoutBuffer.length > CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS) {
  closeLiveSession(session, "abort", createOutputLimitError(session, "Claude CLI stdout buffer exceeded limit."));
  return;
}

// parseClaudeLiveJsonLine, line ~532
if (trimmed.length > CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS) {
  closeLiveSession(session, "abort", createOutputLimitError(session, "Claude CLI JSONL line exceeded output limit."));
  return null;
}
RAW_BUFFERClick to expand / collapse

Summary

The claude-cli runtime in execute.runtime-rara7Weg.js hardcodes a 256KB stdout buffer limit (CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS = 256 * 1024). When claude-cli emits a single stream-json line larger than this — common with extended thinking on Opus 4.7 / xhigh / max — the live session is aborted with "Claude CLI stdout buffer exceeded limit." and falls back to the next configured model. From the user's perspective this looks like a timeout.

Repro

  • Provider: claude-cli/claude-opus-4-7
  • agents.defaults.thinkingDefault: "high" (also reproduces with xhigh / max)
  • Trigger: any turn where the assistant emits a large thinking block; we see this most often on multi-tool, multi-step turns

Observed today

8 overflow aborts in a single day on one host, all on claude-opus-4-7. Every abort triggered a fallback to openai-codex/gpt-5.5 (or xai/grok-4), so the user-visible symptom was inconsistent model/voice + perceived timeouts.

{"event":"model_fallback_decision","decision":"candidate_failed",
 "candidateProvider":"claude-cli","candidateModel":"claude-opus-4-7",
 "reason":"format","status":400,
 "errorPreview":"Claude CLI stdout buffer exceeded limit.",
 "nextCandidateProvider":"openai-codex","nextCandidateModel":"gpt-5.5"}

Source

execute.runtime-rara7Weg.js:

const CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS = 256 * 1024; // line 306

// handleClaudeStdout, line ~601
if (session.stdoutBuffer.length > CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS) {
  closeLiveSession(session, "abort", createOutputLimitError(session, "Claude CLI stdout buffer exceeded limit."));
  return;
}

// parseClaudeLiveJsonLine, line ~532
if (trimmed.length > CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS) {
  closeLiveSession(session, "abort", createOutputLimitError(session, "Claude CLI JSONL line exceeded output limit."));
  return null;
}

Both checks share the same constant, so a single big assistant-message event with embedded thinking is enough to trip it.

Ask

Expose this as a config knob, e.g. agents.defaults.runners.claude-cli.maxStdoutBufferChars (or via env var OPENCLAW_CLAUDE_CLI_MAX_STDOUT_BYTES), with a sensible default bump (1–4 MB) for Opus 4.7-era thinking outputs. Would also help to log the actual line/buffer size on overflow so operators can tune.

Workaround

Setting agents.defaults.thinkingDefault: "adaptive" on Opus 4.7 (Anthropic's recommended setting per the extended thinking docs — fixed budgets were removed in 4.7) reduces the frequency, but does not eliminate the underlying issue: any large turn can still exceed 256KB.

Environment

  • OpenClaw 2026.4.22 (00bd2cf)
  • Node 22.22.2
  • Linux
  • Runner: claude-cli (cli)

extent analysis

TL;DR

Increase the CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS limit to a higher value, such as 1-4 MB, to prevent the claude-cli runtime from aborting due to exceeded buffer limits.

Guidance

  • Identify the current value of CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS (256KB) and consider increasing it to a higher value, such as 1-4 MB, to accommodate larger thinking outputs from Opus 4.7.
  • Implement a configuration option, such as agents.defaults.runners.claude-cli.maxStdoutBufferChars, to allow operators to adjust the buffer size limit without modifying the code.
  • Log the actual line/buffer size on overflow to help operators tune the buffer size limit.
  • Consider setting agents.defaults.thinkingDefault: "adaptive" as a temporary workaround to reduce the frequency of buffer overflows, but note that this does not eliminate the underlying issue.

Example

No code snippet is provided as the issue is more related to configuration and buffer size limits.

Notes

The current buffer size limit of 256KB may not be sufficient for Opus 4.7-era thinking outputs, and increasing this limit can help prevent the claude-cli runtime from aborting due to exceeded buffer limits. However, the optimal buffer size limit may vary depending on the specific use case and requirements.

Recommendation

Apply a workaround by increasing the CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS limit to a higher value, such as 1-4 MB, to prevent buffer overflows and allow for larger thinking outputs from Opus 4.7. This can be done by implementing a configuration option or by modifying the code to increase the buffer size limit.

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

openclaw - ✅(Solved) Fix Make CLAUDE_LIVE_MAX_STDOUT_BUFFER_CHARS configurable (256KB hardcoded limit aborts long claude-cli turns) [1 pull requests, 1 participants]