diff --git a/src/usage-api.ts b/src/usage-api.ts index c4f9b72..347c78b 100644 --- a/src/usage-api.ts +++ b/src/usage-api.ts @@ -48,6 +48,7 @@ const CACHE_FAILURE_TTL_MS = 15_000; // 15 seconds for failed requests const KEYCHAIN_TIMEOUT_MS = 3000; const KEYCHAIN_BACKOFF_MS = 60_000; // Backoff on keychain failures to avoid re-prompting const USAGE_API_TIMEOUT_MS_DEFAULT = 15_000; +export const USAGE_API_USER_AGENT = 'claude-code/2.1'; interface CacheFile { data: UsageData; @@ -662,7 +663,7 @@ function fetchUsageApi(accessToken: string): Promise { headers: { 'Authorization': `Bearer ${accessToken}`, 'anthropic-beta': 'oauth-2025-04-20', - 'User-Agent': 'claude-hud/1.0', + 'User-Agent': USAGE_API_USER_AGENT, }, timeout: timeoutMs, agent: proxyUrl ? createProxyTunnelAgent(proxyUrl) : undefined, diff --git a/tests/usage-api.test.js b/tests/usage-api.test.js index bde6232..1c6c46b 100644 --- a/tests/usage-api.test.js +++ b/tests/usage-api.test.js @@ -9,6 +9,7 @@ import { getUsageApiTimeoutMs, isNoProxy, getProxyUrl, + USAGE_API_USER_AGENT, } from '../dist/usage-api.js'; import { mkdtemp, rm, mkdir, writeFile } from 'node:fs/promises'; import { tmpdir } from 'node:os'; @@ -505,6 +506,10 @@ describe('getUsage', () => { }); }); +test('usage API user agent matches the working Claude Code identifier', () => { + assert.equal(USAGE_API_USER_AGENT, 'claude-code/2.1'); +}); + describe('getKeychainServiceName', () => { test('uses legacy default service name for default config directory', () => { const homeDir = '/tmp/claude-hud-home-default';