Skip to content

Adopt Claude Code 2.1.257 identity - #180

Closed
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:feat/claude-code-2-1-257
Closed

Adopt Claude Code 2.1.257 identity#180
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:feat/claude-code-2-1-257

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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 fallbacks before hashing. Real 2.1.257 keeps it — the only canonicalization is blank model + delete max_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; keeping fallbacks reproduces the exact wire hashes (19824 / 1bd22 / ae6eb). Fixed, with the test polarity flipped to assert fallbacks is kept.

Identity

  • Version 2.1.257, UA claude-cli/2.1.257 (external, cli), stainless package 0.112.1, runtime v26.3.0. (The prior 0.208.0 stainless was wrong — real is lower despite the higher client version.)
  • Beta set matched exactly to the captured 2.1.257 wire (server-side-fallback stays conditional on fallbacks=default).
  • cc_version suffix samples the first user text from the <command-name> block (skipping reminder/caveat blocks), matching the real client's derivation (reproduces the captured 23f / 615 suffixes).

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 in system[] → 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 mutates message[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-01 with thinking.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_transformations response parses cleanly through the existing pass-through stream.

Verification

1320 tests pass (0 fail; the flaky relay-worker-miniflare parallel 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_req billing-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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with 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

  • Derives the cc_version suffix from the first user text after <command-name> and pins it per session in bounded state, preventing message rewrites from changing prompt-cache prefixes.
  • Adds effort-2025-11-24, mid-conversation-system-2026-04-07, and fallback-credit-2026-06-01; redact-thinking-2026-02-12 stays off because it suppresses thinking-block content OpenCode displays.
  • OAuth relay requests for Fable and Mythos 5.1 add thinking-binding-controls-2026-08-01 and 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.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/opencode/src/transform.ts
Comment thread packages/opencode/src/tests/transform.test.ts
Comment thread packages/opencode/src/transform.ts
@iceteaSA
iceteaSA force-pushed the feat/claude-code-2-1-257 branch from dbeb51f to dfa149d Compare September 1, 2026 21:25

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 10 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/opencode/src/transform.ts Outdated
@iceteaSA
iceteaSA force-pushed the feat/claude-code-2-1-257 branch 2 times, most recently from b2005de to fccf5c1 Compare September 1, 2026 22:00

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread packages/opencode/src/tests/transform.test.ts
@iceteaSA
iceteaSA force-pushed the feat/claude-code-2-1-257 branch from fccf5c1 to d14f418 Compare September 1, 2026 22:15

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread packages/core/src/cch.ts
Comment thread packages/opencode/src/index.ts
Comment thread packages/opencode/src/tests/transform.test.ts Outdated
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.
@iceteaSA
iceteaSA force-pushed the feat/claude-code-2-1-257 branch from d14f418 to bc188e7 Compare September 1, 2026 22:43
iceteaSA added a commit to iceteaSA/anthropic-auth that referenced this pull request Sep 1, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread packages/core/src/models.ts
ualtinok added a commit that referenced this pull request Sep 2, 2026
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>
@ualtinok

ualtinok commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Integrated into main in db02924 after reconciling this implementation with #179 and verifying CCH, billing suffixes, and request behavior against captured Claude Code 2.1.258 traffic. The squash commit retains your co-author attribution. Thank you for the identity and signing work.

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.

2 participants