[BUG] `stop_reason` not parsed from `message_delta` when using `ANTHROPIC_BASE_URL` proxy
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] 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: nullwithtool_usecontent 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
- Set up a proxy that returns Anthropic-compatible streaming format (e.g., LiteLLM with
anthropic_messagesendpoint) - Run Claude Code with
ANTHROPIC_BASE_URL=http://localhost:4000 claude - Send a prompt that triggers tool use (e.g., "search the web for X" with WebSearch tool enabled)
- Observe that the conversation stops after the model returns tool_use, without executing the tool
- Check conversation logs in
~/.claude/projects/-stop_reasonwill benull
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: nullin logs
The proxy streaming format was verified to match Anthropic's documented format exactly, including stop_sequence: null in the delta.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗