fix(claude): remap Bifrost custom tools for OAuth cloaking#3214
fix(claude): remap Bifrost custom tools for OAuth cloaking#3214etnperlong wants to merge 4 commits intorouter-for-me:devfrom
Conversation
|
This pull request targeted The base branch has been automatically changed to |
There was a problem hiding this comment.
Code Review
This pull request improves the identification of Claude built-in tools by checking tool types against a known list, including versioned suffixes. It also updates the OAuth tool remapping logic to remove the type field from custom tools to prevent processing issues. Comprehensive tests were added to verify these behaviors. The review feedback suggests optimizing the IsClaudeBuiltinToolType function to avoid unnecessary string allocations during prefix checks.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 024ae66885
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
024ae66 to
59fc564
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59fc564d36
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
efb9aa7 to
2395d50
Compare
Treat only Anthropic built-in tool types as builtins so type:"custom" tools still get Claude Code name remapping. This keeps OAuth cloaking consistent across Anthropic Messages clients and prevents custom tools from being skipped.
Recognize newer builtin tool types so OAuth cloaking does not strip their type fields or rewrite valid builtin names as custom tools.
Precompute Claude builtin type prefixes so hot-path builtin detection no longer concatenates strings for every tool check.
Only strip synthetic type:"custom" wrappers during Claude OAuth cloaking so opaque typed tools keep their definitions and names across remap and prefix handling.
2395d50 to
842e524
Compare
Summary
This fixes Claude OAuth tool cloaking for Anthropic Messages requests that pass through Bifrost.
When Bifrost forwards custom tools, it normalizes them into Anthropic-style entries such as:
{ "type": "custom", "name": "bash" }CLIProxyAPI was treating any tool with a non-empty
typeas a Claude built-in tool. That worked for real Anthropic built-ins likeweb_search_20250305, but it also caused Bifrost-shaped custom tools to be skipped by the OAuth tool remapping logic.As a result, requests forwarded through Bifrost could still expose lowercase third-party tool names like
bash,read, andglob, even though direct Claude Code / OpenCode-style traffic would be remapped toBash,Read, andGlob.Why this matters
For Claude OAuth traffic, tool naming is part of the request fingerprint.
This project already remaps third-party tool names to Claude Code-style names to avoid that fingerprint. But the previous logic broke down once an upstream proxy rewrote custom tools into
type: "custom"entries.In practice, this meant:
That made the behavior inconsistent across Anthropic Messages clients and proxy paths.
What changed
This patch makes the built-in detection stricter:
type: "custom"tools are still handled as third-party custom toolsFor Bifrost-shaped custom tools, the request is now normalized back into the form expected by the existing OAuth cloaking flow:
bash->Bash, etc.)type: "custom"field is removed before forwarding upstreamTests
Added regression coverage for:
type: "custom"tools still receiving Claude OAuth tool prefix/remap handlingtype: "custom"and unknown typed tools staying out of the built-in registryValidation
Tested with focused executor and helper package tests.
This was also verified against real traffic: after rebasing and deploying the patch, OpenCode requests forwarded through Bifrost were handled correctly by the Claude OAuth cloaking path.
CLIProxyAPI was treating any typed tool as a Claude built-in tool. That was too broad. Real built-ins such as
web_search_20250305should be preserved, but Bifrost-shaped custom tools should still go through the OAuth remapping path.Because of that misclassification, forwarded requests could skip remapping for custom tools like
bash,read, andglob, even though direct traffic would correctly becomeBash,Read, andGlob.Changes
type: "custom"tools in the third-party remap flowtype: "custom"before forwarding upstreamtype: "custom"and other unknown typed tools from entering the built-in registryWhy this is needed
For Claude OAuth traffic, tool names are part of the client fingerprint. This project already rewrites third-party tool names to match Claude Code behavior, but that protection was bypassed when a proxy rewrote custom tools into
type: "custom"entries.This patch restores consistent cloaking behavior for both direct and Bifrost-forwarded Anthropic Messages requests.
Tests
Added regression tests covering:
type: "custom"tools