From c037766040ae06ef85ec79f35b747858638fe778 Mon Sep 17 00:00:00 2001 From: wucm667 Date: Fri, 28 Aug 2026 20:42:58 +0800 Subject: [PATCH] fix(keys): preserve Claude attribution headers --- frontend/src/components/keys/UseKeyModal.vue | 15 ++--- .../keys/__tests__/UseKeyModal.spec.ts | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/keys/UseKeyModal.vue b/frontend/src/components/keys/UseKeyModal.vue index fc5356cf5e..0030f7226a 100644 --- a/frontend/src/components/keys/UseKeyModal.vue +++ b/frontend/src/components/keys/UseKeyModal.vue @@ -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 diff --git a/frontend/src/components/keys/__tests__/UseKeyModal.spec.ts b/frontend/src/components/keys/__tests__/UseKeyModal.spec.ts index 4da87d9e79..414608f0a4 100644 --- a/frontend/src/components/keys/__tests__/UseKeyModal.spec.ts +++ b/frontend/src/components/keys/__tests__/UseKeyModal.spec.ts @@ -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: '
' + }, + Icon: { + template: '' + } + } + } + }) + + 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) =>