Skip to content

Conversation

@fernando234234
Copy link

@fernando234234 fernando234234 commented Jan 9, 2026

Summary

Fixes Claude Code OAuth token authentication issues by aligning the request shape with what Anthropic's API expects for OAuth tokens.

Changes

  • User-Agent alignment: Update to match Claude CLI format claude-cli/VERSION (external, cli)
  • Beta headers: Remove fine-grained-tool-streaming-2025-05-14 (incompatible with OAuth)
  • Tool name prefixing: Add oc_ prefix to tool names to bypass OAuth tool validation
  • Response handling: Strip prefix from tool names in responses for internal consistency
  • Conversation history: Prefix tool names in message history to match tool definitions

Why tool name prefixing?

Anthropic's API validates tool names against a known list when using OAuth tokens. Third-party tools get rejected. By prefixing with oc_ we can use custom tool names while maintaining compatibility.

What's preserved

  • All prompt caching functionality (prompt-caching-2024-07-31 beta)
  • Cache breakpoints on last two user messages
  • System prompt caching
  • Extended thinking support (interleaved-thinking-2025-05-14 beta)
  • Cache token tracking (read/write)

Credits

This fix was inspired by research and implementation from:

Thanks to @anomalyco for the original research.

Test plan

  • Verify OAuth authentication works with Claude Code tokens
  • Verify tool calls execute correctly (read_file, write_file, etc.)
  • Verify prompt caching still functions (check cache_read_input_tokens in responses)
  • Verify extended thinking mode works with tool use

Important

Fix OAuth compatibility by updating User-Agent, handling tool name validation with oc_ prefix, and removing incompatible beta headers.

  • OAuth Compatibility:
    • Update User-Agent in CLAUDE_CODE_API_CONFIG to claude-cli/VERSION (external, cli) for OAuth token acceptance.
    • Remove fine-grained-tool-streaming-2025-05-14 from beta headers for OAuth compatibility.
  • Tool Name Handling:
    • Add oc_ prefix to tool names in prefixToolName() and prefixToolNames() for outgoing requests in streaming-client.ts.
    • Strip oc_ prefix from tool names in responses using stripToolNamePrefix().
    • Ensure tool names in conversation history are prefixed using prefixToolNamesInMessages().
  • Miscellaneous:
    • Update terms.md with new terms of service effective January 9, 2026.

This description was created by Ellipsis for eb060a2. You can customize this summary. It will automatically update as commits are pushed.

Fixes Claude Code OAuth token authentication issues by aligning the
request shape with what Anthropic's API expects for OAuth tokens.

Changes:
- Update User-Agent to match Claude CLI format: "claude-cli/VERSION (external, cli)"
- Remove fine-grained-tool-streaming beta header (incompatible with OAuth)
- Add tool name prefixing with "oc_" prefix to bypass tool validation
- Strip prefix from tool names in responses for internal consistency
- Prefix tool names in conversation history to match tool definitions

The tool name prefixing is necessary because Anthropic's API validates
tool names against a known list when using OAuth tokens. By prefixing
with "oc_" we can use custom tool names while maintaining compatibility.

Inspired by fixes from:
- anomalyco/opencode-anthropic-auth#10
- anomalyco/opencode-anthropic-auth#11

Thanks to @anomalyco for the original research and implementation.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working Documentation Improvements or additions to documentation labels Jan 9, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 9, 2026

Rooviewer Clock   See task on Roo Cloud

Reviewed latest commit (6746b3e). The reasoning text duplication fix looks correct. Previous test issues remain unresolved.

  • Update test at streaming-client.spec.ts:17 - remove expectation for fine-grained-tool-streaming-2025-05-14 beta header
  • Update test at streaming-client.spec.ts:21 - update userAgent regex to match new claude-cli/VERSION (external, cli) format
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

"oauth-2025-04-20",
"interleaved-thinking-2025-05-14",
"fine-grained-tool-streaming-2025-05-14",
// Note: fine-grained-tool-streaming removed for OAuth compatibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this beta header breaks the existing test in streaming-client.spec.ts at line 17, which expects fine-grained-tool-streaming-2025-05-14 to be present in defaultBetas. The test needs to be updated to remove this expectation.

Fix it with Roo Code or mention @roomote and request a fix.

userAgent: `Roo-Code/${Package.version}`,
// User-Agent must match Claude Code's signature for OAuth tokens to be accepted
// Format matches opencode-anthropic-auth: "claude-cli/VERSION (external, cli)"
userAgent: `claude-cli/${Package.version} (external, cli)`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This userAgent format change breaks the test in streaming-client.spec.ts at line 21, which expects the pattern /^Roo-Code\/\d+\.\d+\.\d+$/. The test regex needs to be updated to match the new claude-cli/VERSION (external, cli) format.

Fix it with Roo Code or mention @roomote and request a fix.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 9, 2026
The thinking_complete handler was re-emitting the full reasoning text
after it had already been streamed via reasoning chunks. This caused
the reasoning content to appear twice in the UI.

Now the thinking_complete case only captures the signature for
tool use continuations without re-emitting the text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Documentation Improvements or additions to documentation Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

2 participants