Skip to content

feat: align CC Compatible requests with Claude CLI parity - #1419

Merged
diegosouzapw merged 3 commits into
cheaper-inference:release/v3.6.9from
rdself:coder/cc-compatible-claude-cli-parity
Apr 19, 2026
Merged

diegosouzapw merged 3 commits into
cheaper-inference:release/v3.6.9from
rdself:coder/cc-compatible-claude-cli-parity

Conversation

@rdself

@rdself rdself commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • align CC Compatible auth and header fingerprinting with the current Claude CLI API-key profile
  • preserve Claude-native messages, system, tools, thinking, output_config, metadata, and max_tokens instead of injecting bridge-owned billing/context blocks
  • keep the connection-level 1M toggle while validating real Claude Code traffic against anyrouter and openclaudecode

Details

  • switch CC Compatible auth to Authorization: Bearer ... and trim the default beta set to the stable Claude CLI API-key profile
  • keep upstream stream=true, but stop rewriting the request body with synthetic billing headers, CWD/date system prompts, and context_management
  • reuse caller-provided Claude-native thinking, output_config, metadata, and max_tokens wherever possible, only filling required defaults when they are absent
  • recognize modern claude-cli/... (external, sdk-cli) user agents in cache preservation logic so Claude Code cache markers survive deterministic routes

Validation

  • npx prettier --check open-sse/config/cliFingerprints.ts open-sse/services/claudeCodeCompatible.ts open-sse/utils/cacheControlPolicy.ts tests/unit/cache-control-policy.test.ts tests/unit/cc-compatible-provider.test.ts tests/unit/chatcore-translation-paths.test.ts tests/unit/claude-code-compatible-helpers.test.ts tests/unit/claude-code-compatible-request.test.ts tests/unit/executor-default-base.test.ts
  • npx eslint open-sse/config/cliFingerprints.ts open-sse/services/claudeCodeCompatible.ts open-sse/utils/cacheControlPolicy.ts tests/unit/cache-control-policy.test.ts tests/unit/cc-compatible-provider.test.ts tests/unit/chatcore-translation-paths.test.ts tests/unit/claude-code-compatible-helpers.test.ts tests/unit/claude-code-compatible-request.test.ts tests/unit/executor-default-base.test.ts
  • npm run typecheck:core
  • node --import tsx/esm --test tests/unit/claude-code-compatible-helpers.test.ts tests/unit/claude-code-compatible-request.test.ts tests/unit/cache-control-policy.test.ts tests/unit/executor-default-base.test.ts tests/unit/cc-compatible-provider.test.ts tests/unit/chatcore-translation-paths.test.ts tests/unit/provider-validation-specialty.test.ts
  • replayed a captured Claude Code request through CC Compatible against https://anyrouter.top with context1m=true -> 200 OK
  • replayed the same captured Claude Code request through CC Compatible against https://www.openclaudecode.cn with context1m=true -> 200 OK

@rdself
rdself requested a review from diegosouzapw as a code owner April 19, 2026 08:48
Copilot AI review requested due to automatic review settings April 19, 2026 08:48

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Claude Code compatibility layer to align with the latest Claude CLI (v2.1.113) wire image. Key changes include switching from x-api-key to Authorization: Bearer headers, hardcoding the Accept header to application/json, and refactoring request body construction for metadata, thinking, and output configuration. The dynamic billing header and several built-in system blocks were removed to match the official client's behavior. Feedback includes a suggestion to remove a redundant function call for effort resolution and a note regarding the potential impact of removing the hash truncation for the device ID.


return {
...outputConfig,
effort: resolveClaudeCodeCompatibleEffort(sourceBody, normalizedBody, model) || effort,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The call to resolveClaudeCodeCompatibleEffort is redundant here. The effort variable passed into this function is already the result of that same calculation performed in the caller (buildClaudeCodeCompatibleRequest at line 242). You can simplify this to just use the effort parameter directly.

Suggested change
effort: resolveClaudeCodeCompatibleEffort(sourceBody, normalizedBody, model) || effort,
effort: effort,

metadata.user_id = JSON.stringify({
device_id: createHash("sha256")
.update(String(cwd || ""))
.digest("hex"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The .slice(0, 24) was removed from the device_id generation. This changes the fingerprint from a 24-character string to a full 64-character SHA-256 hex string. If the upstream relay specifically expects a 24-character ID (which is common for some Anthropic-based client gating), this might cause requests to be rejected. Please confirm if the current Claude CLI indeed uses the full hash without truncation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Claude Code (CC) compatible bridge to better match current Claude CLI wire behavior (auth/header fingerprinting) while preserving more Claude-native request fields and avoiding bridge-injected synthetic system/context blocks.

Changes:

  • Switch CC-compatible auth/header profile to Authorization: Bearer ... and update fingerprint ordering to match the stable Claude CLI API-key profile.
  • Stop rewriting request bodies with synthetic billing/CWD/date/context-management blocks; preserve caller-provided Claude-native fields (thinking, output_config, metadata, max_tokens) with minimal defaults.
  • Expand Claude Code client detection so cache-control preservation recognizes modern claude-cli/... (external, sdk-cli) user agents.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
open-sse/services/claudeCodeCompatible.ts Updates CC-compatible header profile and request shaping to preserve Claude-native fields and remove synthetic blocks.
open-sse/config/cliFingerprints.ts Adjusts CC-compatible fingerprint header/body field ordering for the new CLI parity profile.
open-sse/utils/cacheControlPolicy.ts Recognizes modern Claude CLI user agents to preserve cache markers on deterministic routes.
tests/unit/executor-default-base.test.ts Updates header expectations for CC-compatible auth and Accept behavior.
tests/unit/claude-code-compatible-request.test.ts Updates request-building assertions to reflect preserved Claude-native fields and new system handling.
tests/unit/claude-code-compatible-helpers.test.ts Updates helper tests for bearer auth headers and the trimmed beta set.
tests/unit/chatcore-translation-paths.test.ts Updates chatCore translation expectations for CC-compatible upstream calls.
tests/unit/cc-compatible-provider.test.ts Updates CC-compatible provider behavior expectations for headers and request body shape.
tests/unit/cache-control-policy.test.ts Adds test coverage for modern claude-cli/... (external, sdk-cli) UA detection.

export const CLAUDE_CODE_COMPATIBLE_DEFAULT_CHAT_PATH = "/v1/messages?beta=true";
export const CLAUDE_CODE_COMPATIBLE_DEFAULT_MODELS_PATH = "/models";
export const CLAUDE_CODE_COMPATIBLE_DEFAULT_MAX_TOKENS = 8092;
export const CLAUDE_CODE_COMPATIBLE_DEFAULT_MAX_TOKENS = 64000;
@rdself
rdself marked this pull request as draft April 19, 2026 08:58
@rdself
rdself marked this pull request as ready for review April 19, 2026 09:04
@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.6.9 April 19, 2026 09:50
@diegosouzapw
diegosouzapw merged commit 7443585 into cheaper-inference:release/v3.6.9 Apr 19, 2026
1 check was pending
@rdself
rdself deleted the coder/cc-compatible-claude-cli-parity branch April 20, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants