fix(claude): keep a differently cased Windows entrypoint override

Windows env names are case-insensitive, so a launch value spelled
claude_code_entrypoint lost to the uppercase Orca default when Node
deduplicated the keys.
This commit is contained in:
Brennan Benson
2026-11-08 17:38:41 -08:00
parent 6a00378a06
commit d079ea042e
2 changed files with 43 additions and 7 deletions
@@ -2,7 +2,11 @@ import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, expect, it, vi } from 'vitest'
import { claudeChildEnv, resolveClaudeChildEnvSources } from './claude-structured-child-env'
import {
claudeChildEnv,
resolveClaudeChildEnvSources,
withOrcaClaudeEntrypoint
} from './claude-structured-child-env'
import { resolveStructuredAgentCommand } from '../../../native-chat/structured-agent-command-resolution'
afterEach(() => vi.unstubAllEnvs())
@@ -42,3 +46,14 @@ it('names Orca as the Claude client unless the launch environment sets one', ()
'custom'
)
})
it('keeps a differently cased Windows launch value over the Orca default', () => {
const inherited = { Claude_Code_Entrypoint: 'cli', PATH: 'C:\\bin' }
expect(
withOrcaClaudeEntrypoint(inherited, { claude_code_entrypoint: 'company-client' }, 'win32')
).toEqual({ PATH: 'C:\\bin', claude_code_entrypoint: 'company-client' })
expect(withOrcaClaudeEntrypoint(inherited, undefined, 'win32')).toEqual({
PATH: 'C:\\bin',
CLAUDE_CODE_ENTRYPOINT: 'orca'
})
})
@@ -82,6 +82,26 @@ async function readClaudeChildEnvSources(deps: ClaudeEnvDeps): Promise<ClaudeChi
return { ...invocation, overlay: overlay ? cloneDefinedEnv(overlay) : undefined, inheritedEnv }
}
const CLAUDE_ENTRYPOINT_ENV = 'CLAUDE_CODE_ENTRYPOINT'
// Name Orca as the client instead of the SDK's sdk-ts default or a launching Claude's value.
export function withOrcaClaudeEntrypoint(
inheritedEnv: Record<string, string>,
overlay: Record<string, string> | undefined,
platform: NodeJS.Platform
): Record<string, string> {
// Windows env names are case-insensitive, so a differently cased twin is the same variable.
const isEntrypointKey = (key: string): boolean =>
(platform === 'win32' ? key.toUpperCase() : key) === CLAUDE_ENTRYPOINT_ENV
const env = Object.fromEntries(
Object.entries(inheritedEnv).filter(([key]) => !isEntrypointKey(key))
)
if (!Object.keys(overlay ?? {}).some(isEntrypointKey)) {
env[CLAUDE_ENTRYPOINT_ENV] = 'orca'
}
return { ...env, ...overlay }
}
// Merge onto the shell environment to retain PATH and ambient Anthropic auth.
export function claudeChildEnv(
sources: ClaudeChildEnvSources,
@@ -89,12 +109,13 @@ export function claudeChildEnv(
/** False when the session's seal pairs the CLI runtime itself, behind this app's CLI. */
{ runtimeOnPath = true }: { runtimeOnPath?: boolean } = {}
): Record<string, string> {
const env = decorateEnv({
...withoutInheritedClaudeConfigDir(sources.inheritedEnv, process.platform),
// Name Orca as the client instead of the SDK's sdk-ts default or a launching Claude's value.
CLAUDE_CODE_ENTRYPOINT: 'orca',
...sources.overlay
})
const env = decorateEnv(
withOrcaClaudeEntrypoint(
withoutInheritedClaudeConfigDir(sources.inheritedEnv, process.platform),
sources.overlay,
process.platform
)
)
return runtimeOnPath
? withCliRuntimeOnPath(sources.command, env, { platform: process.platform })
: env