Skip to content

feat: add transparent quota-aware Claude subscription routing - #6172

Open
ejc3 wants to merge 16 commits into
router-for-me:devfrom
ejc3:feature/claude-master-inference
Open

ejc3 wants to merge 16 commits into
router-for-me:devfrom
ejc3:feature/claude-master-inference

Conversation

@ejc3

@ejc3 ejc3 commented Sep 28, 2026 •

Copy link
Copy Markdown

Summary

Adds claude-master, a launcher that keeps the installed native Claude Code client and its normal master login while routing only /v1/messages and /v1/messages/count_tokens through separately authorized Claude subscription profiles.

  • Uses the current claude executable on PATH; there is no version pin, model pin, or local model allowlist.
  • Creates every inference profile through the normal Anthropic OAuth browser login. It never copies or replaces the native master credential.
  • Preserves the native model, payload, tools, active context, conversation/session identity, betas, and end-to-end headers. Only authorization and selected account/device identity change, followed by required CCH re-signing.
  • Preserves Anthropic status, body representation, duplicate/unknown response headers, compression, and incremental streaming bytes. SSE is not parsed or reconstructed, and a request is never replayed after response bytes begin.
  • Reads each profile weekly usage/reset state and selects the usable quota that resets soonest. The configured order is the deterministic fallback when usage is unavailable or tied.
  • Reserves the final 10% of an account for bound opaque continuations when another account has capacity.
  • Decides switchability from the current request payload, not a compaction/version header. Self-contained text and client tool history can move; encrypted/signed thinking, containers/files, unfinished server tools, signed compaction, and unclassifiable payloads stay bound.
  • Gives self-contained subagents independent bindings while opaque children inherit the parent account.
  • Does not rotate subscriptions for request-, model-, authentication-, validation-, or transport-scoped failures, and never falls back to the master account for inference.

Login and run

go build -o claude-master ./cmd/claude-master

./claude-master login claude-primary
./claude-master login claude-secondary

./claude-master run claude-primary \
  --next-profile claude-secondary \
  -- --remote-control

Native Claude options go after --, for example:

./claude-master run claude-primary \
  --next-profile claude-secondary \
  -- --model claude-sonnet-5-5 --fallback-model haiku --remote-control

The repository helper is:

/home/ubuntu/CLIProxyAPI-claude-master/try-claude-master.sh --remote-control

The checked-in scripts/claude-master-gym/ harness drives two disjoint tmux sessions on claude-sonnet-5-5, applies /effort ultracode interactively, and asks each lane to fan out to two bounded read-only subagents.

Verification

  • go test ./...
  • PR race matrix for Claude Master, auth, native header/error, and executor boundaries
  • native Claude Code 2.1.285 CONNECT/TLS/header/SSE smoke under the race detector
  • exact raw gzip, duplicate/unknown header, direct-error, split-stream, quota, reserve, affinity, and subagent-binding tests
  • bash -n and shellcheck for the launcher/gym scripts
  • go build -o test-output ./cmd/server
  • go build -o claude-master-test-output ./cmd/claude-master

Full design and operating instructions are in docs/claude-master.md.

@github-actions
github-actions Bot changed the base branch from main to dev September 28, 2026 08:38
@github-actions

Copy link
Copy Markdown

This pull request targeted main.

The base branch has been automatically changed to dev.

@ejc3
ejc3 force-pushed the feature/claude-master-inference branch 2 times, most recently from 4c4ce9b to 32b8aaf Compare September 30, 2026 05:56
@ejc3
ejc3 force-pushed the feature/claude-master-inference branch from 32b8aaf to 0aebf6e Compare September 30, 2026 17:00
@ejc3 ejc3 changed the title feat: add ordered Claude subscription profiles feat: add transparent quota-aware Claude subscription routing Sep 30, 2026
ejc3 added 2 commits October 1, 2026 03:32
Persist account origins across restarts, confirm handoffs only after upstream acceptance, retain child lineage, and prevent active-generation account switches. Keep failures request-scoped and select usable earliest-reset subscriptions without reserve ping-pong.

Forward native headers and exact successful statuses before stream bytes without replay. Recover staged refresh tokens, renew local TLS leaves, handle SIGHUP, fix relative backup-key paths, strengthen gym evidence and Bash 3.2 compatibility, and cover credential metadata concurrency.

Add deterministic regressions and run Claude-specific CI for fork PRs as well as trusted contributors.
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