Skip to content

fix(claude): Replace hardcoded Claude version (cc_version=2.1.63) in the billing-header#2109

Open
lang-911 wants to merge 1 commit intorouter-for-me:mainfrom
lang-911:fix/use-config-version-for-claude
Open

fix(claude): Replace hardcoded Claude version (cc_version=2.1.63) in the billing-header#2109
lang-911 wants to merge 1 commit intorouter-for-me:mainfrom
lang-911:fix/use-config-version-for-claude

Conversation

@lang-911
Copy link
Contributor

Summary

  • add claude-header-defaults.version as the Claude Code version source
  • use that version for cloaked billing-header generation and fallback Claude User-Agent
  • document the new config field and cover default/configured/custom-User-Agent behavior in executor tests

Testing

  • go test ./internal/runtime/executor -run 'Test(CheckSystemInstructionsWithMode|ApplyClaudeHeaders|ConfiguredClaudeVersion)' -count=1

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors how the Claude Code version is managed within the application. Instead of hardcoding the version in multiple places, it introduces a centralized configuration field. This change streamlines updates to the Claude Code version, ensuring that components like billing header generation and fallback User-Agent strings consistently reflect the desired version, thereby improving maintainability and reducing potential discrepancies.

Highlights

  • Configurable Claude Version: Introduced a new claude-header-defaults.version configuration field to centralize the Claude Code version.
  • Dynamic Billing Header Generation: The Claude Code version is now dynamically sourced from the new configuration field when generating the cloaked billing-header.
  • Fallback User-Agent Logic: The fallback Claude User-Agent now utilizes the configured Claude Code version, improving consistency.
  • Enhanced Test Coverage: Added new tests to cover the behavior of default, configured, and custom User-Agent settings, ensuring correct version application.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • config.example.yaml
    • Added version field to claude-header-defaults section.
    • Updated the example user-agent to reflect the new version.
  • internal/config/config.go
    • Added a Version field to the ClaudeHeaderDefaults struct.
  • internal/runtime/executor/claude_executor.go
    • Introduced defaultClaudeCodeVersion constant.
    • Modified applyClaudeHeaders to use a new defaultClaudeUserAgent function that incorporates the configurable version.
    • Updated generateBillingHeader to accept ClaudeHeaderDefaults and use the configured version.
    • Modified checkSystemInstructions and checkSystemInstructionsWithMode to pass configuration for version retrieval.
    • Added new helper functions claudeCodeVersion and defaultClaudeUserAgent.
  • internal/runtime/executor/claude_executor_test.go
    • Updated existing calls to checkSystemInstructionsWithMode to pass nil for configuration where appropriate.
    • Added new tests to verify the use of the configured Claude version for billing headers.
    • Added new tests to confirm the configured Claude version is used for fallback User-Agent.
    • Added a test to ensure a custom User-Agent is not overridden by the configured Claude version.
Activity
  • The author provided testing instructions for specific Go tests, indicating local verification of the changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively removes the hardcoded Claude version by introducing a new configuration field claude-header-defaults.version. The changes are well-implemented across the configuration, main logic, and tests. The new version is correctly used for generating the billing header and as a fallback for the User-Agent header. The added tests cover the new functionality, including default behavior, configured behavior, and precedence of a custom User-Agent over the version-derived one. I have one suggestion to improve test clarity by refactoring a test case to have a single responsibility.

Comment on lines +1102 to +1123
func TestConfiguredClaudeVersionDoesNotOverrideCustomUserAgent(t *testing.T) {
payload := []byte(`{"system":"You are a helpful assistant.","messages":[{"role":"user","content":"hi"}]}`)
req := httptest.NewRequest(http.MethodPost, "https://example.com/v1/messages", nil)
cfg := &config.Config{
ClaudeHeaderDefaults: config.ClaudeHeaderDefaults{
Version: "2.3.4",
UserAgent: "claude-cli/custom-build (external, cli)",
},
}

out := checkSystemInstructionsWithMode(payload, false, cfg)
billingHeader := gjson.GetBytes(out, "system.0.text").String()
if !strings.Contains(billingHeader, "cc_version=2.3.4.") {
t.Fatalf("billing header should use configured Claude version, got %q", billingHeader)
}

applyClaudeHeaders(req, nil, "key-123", false, nil, cfg)

if got := req.Header.Get("User-Agent"); got != "claude-cli/custom-build (external, cli)" {
t.Fatalf("User-Agent = %q, want %q", got, "claude-cli/custom-build (external, cli)")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test combines two separate concerns: testing checkSystemInstructionsWithMode and applyClaudeHeaders. The check for checkSystemInstructionsWithMode is already covered in TestCheckSystemInstructionsWithMode_UsesConfiguredClaudeVersion, making it redundant here.

To improve clarity and focus, this test should only verify the behavior of applyClaudeHeaders regarding the User-Agent.

Consider renaming the test to something more direct, like TestApplyClaudeHeaders_UsesConfiguredUserAgent, and simplifying its body to focus on that single responsibility.

func TestApplyClaudeHeaders_UsesConfiguredUserAgent(t *testing.T) {
	req := httptest.NewRequest(http.MethodPost, "https://example.com/v1/messages", nil)
	cfg := &config.Config{
		ClaudeHeaderDefaults: config.ClaudeHeaderDefaults{
			Version:   "2.3.4",
			UserAgent: "claude-cli/custom-build (external, cli)",
		},
	}

	applyClaudeHeaders(req, nil, "key-123", false, nil, cfg)

	if got := req.Header.Get("User-Agent"); got != "claude-cli/custom-build (external, cli)" {
		t.Fatalf("User-Agent = %q, want %q", got, "claude-cli/custom-build (external, cli)")
	}
}

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e724b940c4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


func checkSystemInstructions(payload []byte) []byte {
return checkSystemInstructionsWithMode(payload, false)
return checkSystemInstructionsWithMode(payload, false, nil)

Choose a reason for hiding this comment

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

P2 Badge Pass config into count_tokens billing-header generation

checkSystemInstructions now hard-codes nil for cfg, so any caller using this helper (notably the CountTokens flow at body = checkSystemInstructions(body)) will always fall back to defaultClaudeCodeVersion when building cc_version. When claude-header-defaults.version is configured, /v1/messages requests use the configured value but /v1/messages/count_tokens still emits 2.1.63, creating an inconsistent fingerprint and defeating the new configurability in this request path.

Useful? React with 👍 / 👎.

@lang-911 lang-911 changed the title Replace hardcoded Claude version fix(claude): Replace hardcoded Claude version (cc_version=2.1.63) in the billing-header Mar 13, 2026
@lang-911 lang-911 force-pushed the fix/use-config-version-for-claude branch from e724b94 to 918f7d5 Compare March 13, 2026 05:07
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 918f7d5083

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


func checkSystemInstructions(payload []byte) []byte {
return checkSystemInstructionsWithMode(payload, false)
return checkSystemInstructionsWithMode(payload, false, nil)

Choose a reason for hiding this comment

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

P2 Badge Pass executor config into system-instruction helper

In this commit checkSystemInstructions was updated to call checkSystemInstructionsWithMode(payload, false, nil), and CountTokens still routes /v1/messages/count_tokens through that helper, so claude-header-defaults.version is ignored for billing-header generation on that path. When a custom Claude version is configured, /v1/messages uses it (via applyCloaking/applyClaudeHeaders) but /count_tokens keeps emitting the default cc_version, causing an inconsistent client fingerprint.

Useful? React with 👍 / 👎.

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