Skip to content

Commit c096461

Browse files
committed
Send claude-cli User-Agent for anthropic mutate to bypass proxy cloaking
The CLIProxyAPI proxy cloaks requests from non-Claude-Code clients by replacing the system prompt with Claude Code's prompts and shoving the user's sys_msg into the first user message. Sending a User-Agent that starts with 'claude-cli' makes ShouldCloak return false, so user sys_msg passes through untouched. Only applied to the anthropic override; openai/gemini are unaffected.
1 parent 974c4d3 commit c096461

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/OpenRouterCLIProxyAPI.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ end
184184
Override providers to route through cli_proxy_api.
185185
Set `gemini=true` to also override google-ai-studio.
186186
"""
187+
# User-Agent prefix that CLIProxyAPI recognizes as real Claude Code
188+
# (see helps.ShouldCloak: `strings.HasPrefix(userAgent, "claude-cli")`).
189+
# Sending this bypasses the proxy's system-prompt cloaking so user sys_msg passes through.
190+
const CLAUDE_CLI_USER_AGENT = "claude-cli/2.1.63 (external, cli)"
191+
187192
function override_providers!(base_url::String, api_key_env_var::String;
188193
gemini::Bool=false, verbose::Bool=false)
189194
anthropic_base_url = replace(base_url, r"/v1/?$" => "")
@@ -192,7 +197,7 @@ function override_providers!(base_url::String, api_key_env_var::String;
192197
anthropic_base_url,
193198
"Bearer",
194199
api_key_env_var,
195-
Dict{String,String}(),
200+
Dict{String,String}("User-Agent" => CLAUDE_CLI_USER_AGENT),
196201
cli_proxy_model_transform,
197202
AnthropicSchema(),
198203
"anthropic (overridden to cli_proxy_api)"

0 commit comments

Comments
 (0)