Skip to content

feat(upstream): add shared Claude Code client profile for custom upstreams - #802

Merged
yyyr-p merged 9 commits into
Menci:mainfrom
yyyr-p:feat/custom-client-profile
Dec 1, 2026
Merged

yyyr-p merged 9 commits into
Menci:mainfrom
yyyr-p:feat/custom-client-profile

Conversation

@yyyr-p

@yyyr-p yyyr-p commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Some third-party relays and Claude Code pool resellers enforce Claude Code client checks: User-Agent, X-Stainless-*, x-app, anthropic-beta, the billing header, metadata.user_id, and the identity system blocks. The wire mimicry that satisfies those checks lived only inside @floway-dev/upstream-claude-code, so a Custom upstream layered on top of such a relay had no way to reuse it.

Extract the OAuth-independent Claude Code wire profile into the shared @floway-dev/upstream/client-profiles layer, and expose it as an extensible clientProfile?: 'claude-code' preset on Custom upstreams. The shared package owns request detection (isClaudeCodeShapedRequest, parseMetadataUserID), the pinned header surface (pickClaudeCodeHeaders, buildClaudeCodeReshapedHeaders, headersForClaudeCodeCountTokensCall), the inbound header allowlist, the Anthropic Messages mimicry chain (backfill required fields, synthesize metadata.user_id, hoist caller system text, then inject the billing, identity, and cached template blocks), and the per-profile default flags. @floway-dev/upstream-claude-code delegates to the same layer and keeps OAuth, quota, and account state provider-local.

On a profiled Custom upstream, genuine Claude Code-shaped Messages requests pass through with their own system blocks, anthropic-beta opt-ins, and metadata.user_id intact. Other requests run the mimicry chain and receive the pinned header surface while caller-requested beta tokens are merged without duplicates, explicit ingressHeadersRules keep override precedence, and headers admitted only for the profile do not leak into non-Messages protocols. The profile layers strip-billing-attribution: false and rewrite-disallowed-mid-conv-system-to-user: true beneath operator and model flag overrides; explicitly enabling strip-billing-attribution removes the billing block and the claude-code-20250219 token from reshaped requests, and cached auto-model flags are recomputed when the profile changes.

The dashboard adds a Client profile (None / Claude Code) dropdown to Custom upstream settings with en and zh-Hans strings, warns when the profile is selected without the Anthropic Messages endpoint, and reflects the profile's effective defaults in both the upstream and per-model flag editors.

Verification

  • Typechecked @floway-dev/upstream, @floway-dev/upstream-custom, @floway-dev/upstream-claude-code, @floway-dev/gateway, and @floway-dev/web.
  • Targeted ESLint over the 45 changed TypeScript files.
  • Targeted Vitest across 12 suites (55 tests) covering profile detection and interceptors, custom upstream reshaping and passthrough, header isolation, control-plane create/PATCH-clear and cached flag recomputation, and the web editor form values.
  • pnpm run build:web.
  • Local dashboard smoke check: selecting Claude Code warns until Anthropic Messages is enabled, the Upstream Feature Flags tab shows the profile defaults, and save/reload plus clearing back to None persist.
  • All 21 jobs in Verify passed on 1c4df73d2.

yyyr-p and others added 9 commits December 1, 2026 11:10
…upstreams

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…file defaults

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…aude Code requests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…haping Claude Code requests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…dropdown and dirty state

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…list into client-profiles

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…after upstream rebase

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…hropic Messages endpoint

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@yyyr-p yyyr-p changed the title feat(upstream): add shared Claude Code clientProfile preset for custom upstreams feat(upstream): add shared Claude Code client profile for custom upstreams Dec 1, 2026
@yyyr-p
yyyr-p merged commit 46a9a1d into Menci:main Dec 1, 2026
21 checks passed
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.

1 participant