fix(keys): preserve Claude attribution headers
This commit is contained in:
Wesley Liddick
2026-08-29 09:00:46 +08:00
committed by GitHub
2 changed files with 65 additions and 10 deletions
+5 -10
View File
@@ -779,22 +779,19 @@ function generateAnthropicFiles(baseUrl: string, apiKey: string): FileConfig[] {
path = 'Terminal'
content = `export ANTHROPIC_BASE_URL="${baseUrl}"
export ANTHROPIC_AUTH_TOKEN="${apiKey}"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
export CLAUDE_CODE_ATTRIBUTION_HEADER=0`
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1`
break
case 'cmd':
path = 'Command Prompt'
content = `set ANTHROPIC_BASE_URL=${baseUrl}
set ANTHROPIC_AUTH_TOKEN=${apiKey}
set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
set CLAUDE_CODE_ATTRIBUTION_HEADER=0`
set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1`
break
case 'powershell':
path = 'PowerShell'
content = `$env:ANTHROPIC_BASE_URL="${baseUrl}"
$env:ANTHROPIC_AUTH_TOKEN="${apiKey}"
$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
$env:CLAUDE_CODE_ATTRIBUTION_HEADER=0`
$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1`
break
default:
path = 'Terminal'
@@ -810,8 +807,7 @@ $env:CLAUDE_CODE_ATTRIBUTION_HEADER=0`
"env": {
"ANTHROPIC_BASE_URL": "${baseUrl}",
"ANTHROPIC_AUTH_TOKEN": "${apiKey}",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0"
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}`
@@ -835,8 +831,7 @@ function generateGrokClaudeFiles(baseUrl: string, apiKey: string): FileConfig[]
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'grok-4.5',
ANTHROPIC_DEFAULT_FABLE_MODEL: 'grok-4.5',
CLAUDE_CODE_SUBAGENT_MODEL: 'grok-4.5',
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
CLAUDE_CODE_ATTRIBUTION_HEADER: '0'
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1'
}
let path: string
let content: string
@@ -39,6 +39,52 @@ describe('UseKeyModal', () => {
vi.unstubAllGlobals()
saveAsMock.mockClear()
})
it('omits the attribution override from every standard Claude Code setup form', async () => {
const wrapper = mount(UseKeyModal, {
props: {
show: true,
apiKey: 'sk-anthropic-test',
baseUrl: 'https://example.com/v1',
platform: 'anthropic'
},
global: {
stubs: {
BaseDialog: {
template: '<div><slot /><slot name="footer" /></div>'
},
Icon: {
template: '<span />'
}
}
}
})
for (const [shell, trafficSetting] of [
['macOS / Linux', 'export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1'],
['Windows CMD', 'set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1'],
['PowerShell', '$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1']
]) {
if (shell !== 'macOS / Linux') {
const shellTab = wrapper.findAll('button').find(
(button) => button.text().trim() === shell
)
expect(shellTab).toBeDefined()
await shellTab!.trigger('click')
await nextTick()
}
const codeBlocks = wrapper.findAll('pre code').map((code) => code.text())
const allCode = codeBlocks.join('\n')
const settings = JSON.parse(codeBlocks.find((content) => content.includes('"$schema"'))!)
expect(allCode).not.toContain('CLAUDE_CODE_ATTRIBUTION_HEADER')
expect(allCode).toContain(trafficSetting)
expect(settings.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC).toBe('1')
expect(settings.env).not.toHaveProperty('CLAUDE_CODE_ATTRIBUTION_HEADER')
}
})
it('renders Grok Build and OpenCode setup for Grok groups', async () => {
const wrapper = mount(UseKeyModal, {
props: {
@@ -179,6 +225,10 @@ describe('UseKeyModal', () => {
const parsedSettings = JSON.parse(settingsConfig!)
expect(parsedSettings.$schema).toBe('https://json.schemastore.org/claude-code-settings.json')
expect(parsedSettings.env.ANTHROPIC_MODEL).toBe('grok-4.5')
expect(codeBlocks.join('\n')).not.toContain('CLAUDE_CODE_ATTRIBUTION_HEADER')
expect(codeBlocks.join('\n')).toContain('CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC')
expect(parsedSettings.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC).toBe('1')
expect(parsedSettings.env).not.toHaveProperty('CLAUDE_CODE_ATTRIBUTION_HEADER')
expect(wrapper.text()).toContain('keys.useKeyModal.claudeSettingsHint')
expect(wrapper.text()).toContain('keys.useKeyModal.grok.claudeNote')
expect(wrapper.find('nav[aria-label="Client"]').classes()).toContain('min-w-max')
@@ -195,6 +245,11 @@ describe('UseKeyModal', () => {
expect(codeBlocks.join('\n')).toContain('set ANTHROPIC_MODEL=grok-4.5')
expect(codeBlocks.join('\n')).toContain('set ANTHROPIC_DEFAULT_FABLE_MODEL=grok-4.5')
expect(codeBlocks.join('\n')).toContain('set CLAUDE_CODE_SUBAGENT_MODEL=grok-4.5')
expect(codeBlocks.join('\n')).toContain('set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1')
expect(codeBlocks.join('\n')).not.toContain('CLAUDE_CODE_ATTRIBUTION_HEADER')
const cmdSettings = JSON.parse(codeBlocks.find((content) => content.includes('"$schema"'))!)
expect(cmdSettings.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC).toBe('1')
expect(cmdSettings.env).not.toHaveProperty('CLAUDE_CODE_ATTRIBUTION_HEADER')
const powershellTab = wrapper.findAll('button').find(
(button) => button.text().trim() === 'PowerShell'
@@ -208,6 +263,11 @@ describe('UseKeyModal', () => {
expect(codeBlocks.join('\n')).toContain('$env:ANTHROPIC_MODEL="grok-4.5"')
expect(codeBlocks.join('\n')).toContain('$env:ANTHROPIC_DEFAULT_FABLE_MODEL="grok-4.5"')
expect(codeBlocks.join('\n')).toContain('$env:CLAUDE_CODE_SUBAGENT_MODEL="grok-4.5"')
expect(codeBlocks.join('\n')).toContain('$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1"')
expect(codeBlocks.join('\n')).not.toContain('CLAUDE_CODE_ATTRIBUTION_HEADER')
const powershellSettings = JSON.parse(codeBlocks.find((content) => content.includes('"$schema"'))!)
expect(powershellSettings.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC).toBe('1')
expect(powershellSettings.env).not.toHaveProperty('CLAUDE_CODE_ATTRIBUTION_HEADER')
expect(wrapper.text()).toContain('%USERPROFILE%\\.claude\\settings.json')
const copyButton = wrapper.findAll('button').find((button) =>