fix(core): align request fidelity with genuine Claude Code CLI (2.1.177)#75
Open
iceteaSA wants to merge 3 commits into
Open
fix(core): align request fidelity with genuine Claude Code CLI (2.1.177)#75iceteaSA wants to merge 3 commits into
iceteaSA wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
iceteaSA has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
No issues found across 10 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant Plugin as OpenCode Plugin
participant Core as anthropic-auth-core
participant Constants as Constants Module
participant Betas as Beta Selector
participant Identity as Identity Builder
participant HTTP as Fetch / Axios
participant API as Anthropic API
Note over Plugin,API: Claude Code Interactive-CLI Request Fidelity
Plugin->>Core: request LLM completion
Core->>Constants: read fingerprint constants
Constants-->>Core: USER_AGENT, CLAUDE_CODE_VERSION, etc.
Core->>Betas: selectClaudeCodeBetas(request)
alt Full agent turn (tools present)
Betas->>Betas: build FULL beta set
Note over Betas: oauth-2025-04-20<br/>interleaved-thinking-2025-05-14<br/>thinking-token-count-2026-05-13<br/>context-management-2025-06-27<br/>prompt-caching-scope-2026-01-05<br/>claude-code-20250219<br/>advisor-tool-2026-03-01<br/>advanced-tool-use-2025-11-20<br/>extended-cache-ttl-2025-04-11<br/>cache-diagnosis-2026-04-07
else Structured output turn
Betas->>Betas: build STRUCTURED beta set
Note over Betas: oauth-2025-04-20<br/>interleaved-thinking-2025-05-14<br/>thinking-token-count-2026-05-13<br/>context-management-2025-06-27<br/>prompt-caching-scope-2026-01-05<br/>advisor-tool-2026-03-01<br/>structured-outputs-2025-12-15
else Simple turn (no tools)
Betas->>Betas: build BASE beta set
Note over Betas: oauth-2025-04-20<br/>interleaved-thinking-2025-05-14<br/>thinking-token-count-2026-05-13<br/>context-management-2025-06-27<br/>prompt-caching-scope-2026-01-05<br/>advisor-tool-2026-03-01<br/>advanced-tool-use-2025-11-20<br/>extended-cache-ttl-2025-04-11<br/>cache-diagnosis-2026-04-07
end
Betas-->>Core: beta header string
Core->>Identity: build system identity
Identity-->>Core: "You are Claude Code, Anthropic's official CLI for Claude."
Core->>Core: compute billing header
Note over Core: cc_version=2.1.177.3bf<br/>cc_entrypoint=cli
Core->>HTTP: POST /messages
Note over HTTP: anthropic-beta: <selected betas><br/>user-agent: claude-cli/2.1.177 (external, cli)<br/>x-claude-code-session-id: <uuid>
HTTP-->>Core: response
Note over Plugin,API: OAuth Token Refresh
Plugin->>Core: refreshClaudeOAuthToken(refreshToken)
Core->>HTTP: POST /v1/oauth/token
Note over HTTP: Accept: application/json, text/plain, */*<br/>User-Agent: axios/1.15.2
Note over HTTP: body: grant_type=refresh_token<br/>refresh_token=<token><br/>client_id=9d1c250a-...<br/>scope=user:profile user:inference ...
HTTP-->>Core: token response
Core-->>Plugin: new access token
Note over Plugin,API: OAuth Authorize Flow
Plugin->>Core: authorize(provider="max")
Core->>Constants: get AUTHORIZE_URLS.max
Constants-->>Core: https://claude.com/cai/oauth/authorize
Core->>Core: generate PKCE challenge
Core-->>Plugin: { url, verifier }
Plugin->>HTTP: GET https://claude.com/cai/oauth/authorize?...
Note over HTTP: 307 redirect preserves PKCE params
HTTP-->>API: redirected to claude.ai/oauth/authorize
API-->>Plugin: auth page
Note over Plugin,API: Bootstrap Session
Plugin->>Core: bootstrapCLI(entrypoint="cli")
Core->>HTTP: GET /api/claude_cli/bootstrap?entrypoint=cli&model=...
Note over HTTP: user-agent: claude-code/2.1.177<br/>anthropic-beta: oauth-2025-04-20
HTTP-->>Core: session config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns the plugin's Anthropic request fingerprint with genuine Claude Code interactive-CLI traffic, captured + live-verified via MITM on 2026-06-14. Three independently-reviewed commits.
1.
anthropic-betacorrectness (packages/core/src/claude-code.ts)context-1m-2025-08-07andeffort-2025-11-24from the full-agent set — verified:context-1mreturns400 "long context beta is not yet available for this subscription"on Max.thinking-token-count-2026-05-13as always-on (BASE/FULL/structured).advanced-tool-use-2025-11-20+extended-cache-ttl-2025-04-11to BASE (genuine simple turns send them).oauth-2025-04-20;claude-code-20250219sits afterprompt-caching-scope-2026-01-05and only on tool-bearing turns.redact-thinking-2026-02-12is intentionally NOT sent (product decision), even though genuine CLI includes it. A test pins its absence.2. OAuth refresh + login fidelity (
packages/core/src/{constants,auth}.ts)axios/1.13.6→axios/1.15.2(extracted toAXIOS_USER_AGENT), on both refresh and code-exchange.Accept: application/json, text/plain, */*+ bodyscope(REFRESH_SCOPE, which omitsorg:create_api_key— matches genuine refresh; login keeps it).AUTHORIZE_URLS.max→https://claude.com/cai/oauth/authorize(genuine post-rebrand host; verified 307→claude.ai preserving PKCEcode_challenge/state).3. Interactive-CLI identity (
packages/core/src/constants.ts)All-or-nothing fingerprint swap from the Agent-SDK persona to the interactive CLI:
USER_AGENT→claude-cli/2.1.177 (external, cli),CLAUDE_CODE_VERSION→2.1.177,CLAUDE_CODE_BUILD_HASH→3bf,CLAUDE_CODE_ENTRYPOINT→cli, identity →"You are Claude Code, Anthropic's official CLI for Claude."cc_version=2.1.177.3bf; cc_entrypoint=cli. cch signing mechanism untouched.3bfis a per-build hash that churns; re-confirm against a fresh capture on future bumps.Test isolation fix (
index.test.ts)The
provider.modelssuite read the real~/.config/opencode/anthropic-auth.jsoninstead of an isolated temp file, so the cost-zeroing test failed on any machine that opted out of cost-zeroing (passed only in clean CI). AddedbeforeEach/afterEachconfig isolation mirroring theauth.loaderblock.Testing
bun run build/bun run typecheckcleanbun test: 496 pass / 0 failOut of scope
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Aligns our Anthropic request and identity to the genuine Claude Code interactive CLI 2.1.177 for higher fidelity and fewer auth/feature mismatches. Updates beta headers, OAuth requests, and CLI identity; fixes flaky test config isolation.
Bug Fixes
oauth-2025-04-20; addedthinking-token-count-2026-05-13; movedclaude-code-20250219afterprompt-caching-scope-2026-01-05only on tool turns; addedadvanced-tool-use-2025-11-20andextended-cache-ttl-2025-04-11to BASE; removedcontext-1m-2025-08-07andeffort-2025-11-24; intentionally omitredact-thinking-2026-02-12.Accept: application/json, text/plain, */*andAXIOS_USER_AGENT(axios/1.15.2); refresh body includesscope(REFRESH_SCOPE);AUTHORIZE_URLS.maxnowhttps://claude.com/cai/oauth/authorize.USER_AGENTclaude-cli/2.1.177 (external, cli);CLAUDE_CODE_VERSION=2.1.177,CLAUDE_CODE_BUILD_HASH=3bf,CLAUDE_CODE_ENTRYPOINT=cli); system identity updated; billing header now usescc_entrypoint=cli.Tests
provider.modelsfrom real user config (temp files inbeforeEach/afterEach).Written for commit 18c4649. Summary will update on new commits.