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

[BUG] Partial output when using the non-interactive mode

Open BarreiroT opened this issue 1 year ago • 8 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • Claude CLI version: 1.0.48 (Claude Code)
  • Operating System: macOS 15.5
  • Node version: v22.12.0
  • Terminal: kitty

Bug Description

Hey, When working on an integration, I've noticed that Claude Code sometimes exits before outputting valid messages. I've added handling on partial data, but I've noticed the same behavior when using the Claude Code SDK. I suspect the cause might be an unflushed buffer before exiting, but I am not sure if it's just the request failing.

Steps to Reproduce

  1. Start a new request with a significantly large context and using the stream-json output format. In my case, I am using a 47460 bytes long system prompt and a 221264 bytes long prompt.

Expected Behavior

The output is piped entirely to stdout or a proper error indication is returned.

Actual Behavior

The SDK throws an error when it fails to parse JSON:

SyntaxError: Unterminated string in JSON at position 8000 (line 1 column 8001)
    at JSON.parse (<anonymous>)
    at Query.readMessages (file:///test/node_modules/@anthropic-ai/claude-code/sdk.mjs:255:32)

Additional Context

When this does happen, the output is consistently either 8 or 10k characters long. The partial chunk is mostly the result one. I am using the latest version of Claude Code and of the SDK, but I have noticed it in all the versions I tested since the release.

BarreiroT avatar Jul 11 '25 20:07 BarreiroT

Same here, except that mines happens at position 2000: Unterminated string in JSON at position 2000 (line 1 column 2001)

brian-lou avatar Jul 12 '25 04:07 brian-lou

I'm unable to implement the workaround mentioned in #2904 because I am using the TS SDK, which handles the JSON parsing under the hood. Would really appreciate a followup to this!

brian-lou avatar Jul 14 '25 17:07 brian-lou

Will we ever get a fix for this?

gustavhartz avatar Sep 30 '25 05:09 gustavhartz

Sad to see no attention to this.

ben-vargas avatar Oct 16 '25 04:10 ben-vargas

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 Dec 08 '25 10:12 github-actions[bot]

Sad to see no attention to this.

I think so, too.

tatsuo48 avatar Dec 10 '25 02:12 tatsuo48

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

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

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Jan 17 '26 14:01 github-actions[bot]