Skip to content

[BUG] stop_reason not parsed from message_delta when using ANTHROPIC_BASE_URL proxy #16785

Closed as not planned

Description

@bhaskoro-muthohar

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?

When using ANTHROPIC_BASE_URL to route requests through a proxy, Claude Code fails to parse stop_reason from the message_delta streaming event. The stop_reason is logged as null even when the proxy correctly sends "stop_reason": "tool_use" in the message_delta event.

This causes tool_use responses to not trigger tool execution, making the conversation stop abruptly after the model attempts to use a tool.

Proxy chain:

Claude Code → LiteLLM (Anthropic format) → kiro-openai-gateway (OpenAI format) → Kiro

Evidence:

  • Direct Anthropic API logs show stop_reason: "tool_use" correctly (43 occurrences in one session)
  • Proxy logs show stop_reason: null with tool_use content present
  • The proxy output is identical to Anthropic's documented streaming format

Proxy streaming output (correct format):

event: message_delta
data: {"type": "message_delta", "delta": {"stop_reason": "tool_use", "stop_sequence": null}, "usage": {"input_tokens": 608, "output_tokens": 46}}

What Should Happen?

Claude Code should parse stop_reason from the message_delta event when using ANTHROPIC_BASE_URL, the same way it does when connecting directly to the Anthropic API.

Steps to Reproduce

  1. Set up a proxy that returns Anthropic-compatible streaming format (e.g., LiteLLM with anthropic_messages endpoint)
  2. Run Claude Code with ANTHROPIC_BASE_URL=http://localhost:4000 claude
  3. Send a prompt that triggers tool use (e.g., "search the web for X" with WebSearch tool enabled)
  4. Observe that the conversation stops after the model returns tool_use, without executing the tool
  5. Check conversation logs in ~/.claude/projects/ - stop_reason will be null

Claude Model

Opus (via Kiro)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.1 (Claude Code)

Platform

Anthropic API (via ANTHROPIC_BASE_URL proxy)

Operating System

macOS

Terminal/Shell

zsh

Additional Information

Tested with:

  • LiteLLM proxy converting OpenAI format to Anthropic format
  • Custom mock server sending exact Anthropic streaming format
  • Both produce the same result: stop_reason: null in logs

The proxy streaming format was verified to match Anthropic's documented format exactly, including stop_sequence: null in the delta.

Activity

  1. bhaskoro-muthohar commented on Jan 8, 2026

    @bhaskoro-muthohar
    Author

    Additional observations from continued usage:

    The issue affects multiple tool types and scenarios:

    Case 1: Single tool_use (Grep)

    • Grep tool invoked to search for a pattern in a repository
    • Response stopped midway without completing
    • Workaround: Used Bash with grep command instead, which worked
    • Retry with same Grep tool later succeeded (model may have taken different path)

    Case 2: Parallel tool_use (multiple Edit calls)

    • Task required editing 18 files across 10 GCP projects
    • Initial attempt with multiple parallel Edit calls stopped midway
    • Workaround: Split into two sequential batches (10 + 8 edits) - both completed successfully
    • Retry test with 10 parallel Edit calls (no-op) succeeded without interruption

    Pattern:

    • Not tool-specific (affects Grep, Edit, likely others)
    • Appears intermittent in practice, but likely depends on whether the model returns tool_use vs end_turn
    • Batching/sequential execution can help as a workaround
  2. bhaskoro-muthohar commented on Jan 10, 2026

    @bhaskoro-muthohar
    Author

    Case 3: Parallel tool_use (multiple Bash calls)

    • Diagnostic commands: ps aux, top, vm_stat, sysctl
    • Initial attempt with parallel Bash calls stopped midway
    • Retry with sequential execution succeeded
    • Same commands, different execution pattern

    This further confirms the issue is not tool-specific and affects parallel tool_use scenarios more frequently.

  3. github-actions commented on Feb 10, 2026

    @github-actions

    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.

  4. github-actions commented on Feb 24, 2026

    @github-actions

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

  5. github-actions commented on Mar 4, 2026

    @github-actions

    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.

  6. locked as resolved and limited conversation to collaborators on Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiarea:toolsautocloseIssue will be closed automaticallybugSomething isn't workingexternalhas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions