Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,17 @@ upstream:
# anything else is dropped so the outgoing set stays one a real client could produce.
# Other Anthropic-compatible upstreams still forward caller betas verbatim.
#
# Shared Claude CLI fingerprint defaults. Update only after measuring a new Claude Code release.
# Unconfirmed clients use this CLI baseline. Verified native Claude Code CLI, sdk-cli,
# and VSCode requests preserve their measured entrypoint when the Claude Code version is a
# patch release in the configured major/minor line at or above this baseline. Older versions
# and newer major/minor lines fall back to the baseline until measured. In legacy mode,
# timeout is a fallback and
# verified native OS/arch values remain client-supplied. When stabilize-device-profile is
# enabled, OS/arch are pinned to the values below and cached profiles remain constrained to
# the same exact software baseline rather than learning newer client versions.
# Verified native Claude Code requests keep their own CLI version and entrypoint.
# Other clients use the configured CLI baseline. An optional version-file overrides
# the baseline version with an installed X.Y.Z version, read once per request.
# Missing, unreadable, or invalid files retain the configured or builtin baseline.
# Update SDK/runtime defaults only after measuring a new Claude Code release.
# In legacy mode, timeout is a fallback and verified native OS/arch stay client-supplied.
# Stabilization pins SDK/runtime and OS/arch fields, but native callers still keep
# their own CLI version in the User-Agent and billing metadata.
# header-defaults:
# user-agent: "claude-cli/2.1.280 (external, cli)"
# version-file: "/config/claude-code-version" # optional installed version, refreshed without a restart
# package-version: "0.112.1"
# runtime-version: "v26.3.0"
# os: "MacOS"
Expand Down
10 changes: 10 additions & 0 deletions internal/config/claude_version_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ func TestClaudeVersionFileV8RoundTrip(t *testing.T) {
}
}
}

func TestClaudeVersionFileLegacyV8Alias(t *testing.T) {
cfg, err := ParseConfigBytes([]byte("config-version: 8\noauth:\n providers:\n claude:\n header-defaults:\n version-file: /config/claude-code-version\n"))
if err != nil {
t.Fatal(err)
}
if cfg.ClaudeHeaderDefaults.VersionFile != "/config/claude-code-version" {
t.Fatalf("legacy version-file lost: %q", cfg.ClaudeHeaderDefaults.VersionFile)
}
}
1 change: 1 addition & 0 deletions internal/config/config_v8.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var v8SharedPaths = []configPath{
{"oauth.providers.claude.claude-code.disable-cloaking-model-list", "upstream.claude.disable-cloaking-model-list"},
{"oauth.providers.claude.disable-claude-cloak-mode", "upstream.claude.disable-claude-cloak-mode"},
{"oauth.providers.claude.header-defaults.user-agent", "upstream.claude.header-defaults.user-agent"},
{"oauth.providers.claude.header-defaults.version-file", "upstream.claude.header-defaults.version-file"},
{"oauth.providers.claude.header-defaults.package-version", "upstream.claude.header-defaults.package-version"},
{"oauth.providers.claude.header-defaults.runtime-version", "upstream.claude.header-defaults.runtime-version"},
{"oauth.providers.claude.header-defaults.os", "upstream.claude.header-defaults.os"},
Expand Down
38 changes: 38 additions & 0 deletions internal/runtime/executor/claude_version_tracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,41 @@ func TestClaudeVersionTrackingOutbound(t *testing.T) {
}
}
}

func TestClaudeVersionTrackingCountTokens(t *testing.T) {
path := filepath.Join(t.TempDir(), "claude-code-version")
cfg := &config.Config{}
cfg.ClaudeHeaderDefaults.VersionFile = path
executor := NewClaudeExecutor(cfg)
auth := &cliproxyauth.Auth{Attributes: map[string]string{"api_key": "sk-ant-oat-version-count"}}
for _, native := range []bool{false, true} {
for _, installed := range []string{"2.1.321", "2.2.1"} {
if err := os.WriteFile(path, []byte(installed+"\n"), 0600); err != nil {
t.Fatal(err)
}
want := installed
headers := http.Header{}
if native {
want = "3.0.1"
headers.Set("User-Agent", "claude-cli/3.0.1 (external, cli)")
headers.Set("X-App", "cli")
headers.Set("Anthropic-Beta", "claude-code-20250219,oauth-2025-04-20")
}
transport := roundTripperFunc(func(req *http.Request) (*http.Response, error) {
if req.URL.Path != "/v1/messages/count_tokens" {
t.Fatalf("unexpected path: %s", req.URL.Path)
}
if got := req.UserAgent(); got != "claude-cli/"+want+" (external, cli)" {
t.Errorf("count_tokens UA = %q, want version %s", got, want)
}
return &http.Response{StatusCode: http.StatusOK, Header: http.Header{}, Body: io.NopCloser(strings.NewReader(`{"input_tokens":7}`)), Request: req}, nil
})
ctx := context.WithValue(context.Background(), "cliproxy.roundtripper", http.RoundTripper(transport))
payload := []byte(`{"model":"claude-sonnet-5","messages":[{"role":"user","content":"hello"}],"tools":[]}`)
_, err := executor.CountTokens(ctx, auth, cliproxyexecutor.Request{Model: "claude-sonnet-5", Payload: payload}, cliproxyexecutor.Options{SourceFormat: sdktranslator.FormatClaude, Headers: headers})
if err != nil {
t.Fatal(err)
}
}
}
}
Loading