Adopt Claude Code 2.1.257 identity - #180
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Architecture diagram
sequenceDiagram
participant Client as OpenCode Client
participant Proxy as Request Proxy
participant Transform as transform.ts
participant CCH as cch.ts
participant API as Anthropic API
Note over Client,API: Request Flow with Billing Header Signing
Client->>Proxy: Send request (messages, model, sessionId)
Proxy->>Transform: rewriteRequestBody()
Transform->>Transform: Check model type
alt Fable/Mythos 5.1 model
Transform->>Transform: Add thinking-binding-controls betas
Transform->>Transform: Add block_binding prefix_mismatch_behavior
else Other models
Transform->>Transform: No binding controls
end
Transform->>Transform: Extract first user message text
alt Session ID present
Transform->>Transform: Check pinnedFirstUserTexts map
alt Pin exists
Transform->>Transform: Use pinned text
else No pin
Transform->>Transform: Extract and pin text (bounded map)
end
else No session ID
Transform->>Transform: Extract text directly
end
Transform->>CCH: buildBillingHeaderValue(pinnedText)
CCH->>CCH: computeVersionSuffix(firstUserText)
CCH->>CCH: Sample positions [4,7,20]
CCH->>CCH: Hash salt + sampled + version
CCH-->>Transform: cc_version suffix
Transform->>CCH: signRequestBody(body)
CCH->>CCH: Parse JSON body
CCH->>CCH: Blank model field
CCH->>CCH: Delete max_tokens field
Note over CCH: fallbacks field KEPT
CCH->>CCH: Hash canonical body
CCH-->>Transform: Signed cch value
Transform-->>Proxy: Rewritten body with billing header
Proxy->>API: Forward request (identity 2.1.257)
alt Playback with prefix mismatch (5.1)
API-->>Proxy: input_transformations (thinking dropped)
Proxy-->>Client: Pass-through stream
else Prefix match
API-->>Proxy: Normal response
Proxy-->>Client: Response stream
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
dbeb51f to
dfa149d
Compare
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
b2005de to
fccf5c1
Compare
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
fccf5c1 to
d14f418
Compare
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Replicates the Claude Code 2.1.257 request identity, verified against a live wire capture of the real client. - Canonical cch body signing keeps `fallbacks` in the hash (only `model` is blanked and `max_tokens` deleted) — matches the real 2.1.257 wire. - Version 2.1.257, UA claude-cli/2.1.257, stainless package 0.112.1, runtime v26.3.0, and the full 2.1.257 beta set. - cc_version suffix samples the first user text from the <command-name> block, pinned at conversation start (frozen per session, LRU-bounded) so a fold layer mutating message[0] can't rotate it and self-bust the prompt cache. - Fable/Mythos 5.1 requests send the thinking-binding-controls-2026-08-01 beta with block_binding prefix_mismatch_behavior: drop_block, gated by route so API-key fallbacks carry neither the beta nor the body field.
d14f418 to
bc188e7
Compare
There was a problem hiding this comment.
All reported issues were addressed across 10 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Reconcile the two contributed implementations against captured Claude Code 2.1.258 traffic, including model metadata, billing identity, conditional thinking-prefix controls, Pi support, and documentation. Co-authored-by: iceteaSA <171169159+iceteaSA@users.noreply.github.com>
Updates the replicated Claude Code request identity to 2.1.257, verified against a live mitmproxy capture of the real client (login + turns + status). The capture caught a real bug in the prior identity that no static review could — see the cch fix below.
cch fix (correctness)
The canonical cch body previously deleted
fallbacksbefore hashing. Real 2.1.257 keeps it — the only canonicalization is blankmodel+ deletemax_tokens. Brute-forcing all canonicalization subsets against the captured byte-complete bodies, the delete-fallbacks rule produces a cch no real client emits on fallback-enabled requests; keepingfallbacksreproduces the exact wire hashes (19824/1bd22/ae6eb). Fixed, with the test polarity flipped to assertfallbacksis kept.Identity
2.1.257, UAclaude-cli/2.1.257 (external, cli), stainless package0.112.1, runtimev26.3.0. (The prior0.208.0stainless was wrong — real is lower despite the higher client version.)server-side-fallbackstays conditional onfallbacks=default).cc_versionsuffix samples the first user text from the<command-name>block (skipping reminder/caveat blocks), matching the real client's derivation (reproduces the captured23f/615suffixes).Suffix pinning
The suffix hashes bytes from the first user message. A fold/context layer that mutates
message[0]mid-session would rotate the suffix → change the billing line insystem[]→ bust the prompt cache, in a self-sustaining loop. The suffix is now pinned at conversation start (frozen per session, bounded map), which also matches real CC — it never mutatesmessage[0], so its suffix is de-facto frozen.Fable 5.1 thinking-block binding
Fable 5.1 server-binds each thinking block to its conversation prefix; replaying after a prefix change 400s. 5.1 requests now send
thinking-binding-controls-2026-08-01withthinking.block_binding.prefix_mismatch_behavior: "drop_block", degrading that 400 to a silent server-side drop. Wire shape confirmed against the platform doc; the dropped-block +input_transformationsresponse parses cleanly through the existing pass-through stream.Verification
1320 tests pass (0 fail; the flaky
relay-worker-miniflareparallel timeout solo-greens). Cross-family review (GLM) approved 0-must on both the identity bump and the binding-controls delta, independently reproducing the wire cch hashes and confirming the binding-controls field path against the doc.Deferred (follow-up issue)
cc_prompt_id+cc_prev_reqbilling-header fields — they need per-prompt UUID / response-request-id plumbing and sit in the uncached billing tail (no cache/billing-accept impact). Filing separately.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Updates the replicated Claude Code request identity from 2.1.177 to 2.1.257 to match live client traffic, including its UA, Stainless versions, and beta flags. Canonical cch signing now keeps
fallbacks, fixing hashes that previously could not match fallback-enabled requests.Behavior changes
cc_versionsuffix from the first user text after<command-name>and pins it per session in bounded state, preventing message rewrites from changing prompt-cache prefixes.effort-2025-11-24,mid-conversation-system-2026-04-07, andfallback-credit-2026-06-01;redact-thinking-2026-02-12stays off because it suppresses thinking-block content OpenCode displays.thinking-binding-controls-2026-08-01and drop thinking blocks after prefix mismatches instead of returning a 400; API-key routes remain unchanged.Written for commit bc188e7. Summary will update on new commits.