Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/claude/claude-config-dir-pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ function samePath(a: string, b: string, platform: NodeJS.Platform): boolean {

// Pin only nondefault homes: even an explicit default changes the CLI's Keychain identity.
// Preserve the trimmed path's spelling; normalization is only for comparison.
/** Only the Claude CLI honors $CLAUDE_CONFIG_DIR; Claude-compatible variants keep their home-relative dir. */
export function claudeCompatibleConfigDir(configDirName: string): string {
return configDirName === '.claude' ? defaultClaudeConfigDir() : join(homedir(), configDirName)
}

export function claudeConfigDirEnvPatch(
accountHome: string,
options: { env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform } = {}
Expand Down
38 changes: 38 additions & 0 deletions src/main/claude/hook-settings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Why: locks the hook settings target to the config dir the Claude CLI actually reads,
// so a set CLAUDE_CONFIG_DIR cannot strand Orca's managed hooks in an unread ~/.claude (#24873).
import { homedir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { CLAUDE_HOOK_SETTINGS, getConfigPath, OPENCLAUDE_HOOK_SETTINGS } from './hook-settings'

afterEach(() => {
vi.unstubAllEnvs()
delete process.env.CLAUDE_CONFIG_DIR
})

describe('getConfigPath', () => {
it('follows a set CLAUDE_CONFIG_DIR, the same resolution as the rest of Orca\u2019s Claude code', () => {
vi.stubEnv('CLAUDE_CONFIG_DIR', join('/config', 'claude-alt'))
expect(getConfigPath()).toBe(join('/config', 'claude-alt', 'settings.json'))
})

it('keeps the legacy ~/.claude path when the variable is unset, so the fallback is unchanged', () => {
delete process.env.CLAUDE_CONFIG_DIR
expect(getConfigPath()).toBe(join(homedir(), '.claude', 'settings.json'))
})

it('falls back on a whitespace-only value and keeps a real value verbatim, like defaultClaudeConfigDir', () => {
vi.stubEnv('CLAUDE_CONFIG_DIR', ' ')
expect(getConfigPath()).toBe(join(homedir(), '.claude', 'settings.json'))
vi.stubEnv('CLAUDE_CONFIG_DIR', `${join('/config', 'claude-alt')}/`)
expect(getConfigPath()).toBe(join('/config', 'claude-alt', 'settings.json'))
})

it('leaves Claude-compatible CLIs on their own home directory', () => {
vi.stubEnv('CLAUDE_CONFIG_DIR', join('/config', 'claude-alt'))
expect(getConfigPath(OPENCLAUDE_HOOK_SETTINGS)).toBe(
join(homedir(), '.openclaude', 'settings.json')
)
expect(getConfigPath(CLAUDE_HOOK_SETTINGS)).toBe(join('/config', 'claude-alt', 'settings.json'))
})
})
4 changes: 2 additions & 2 deletions src/main/claude/hook-settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { homedir } from 'node:os'
import { claudeCompatibleConfigDir } from './claude-config-dir-pin'
import { basename, extname, join, win32 } from 'node:path'
import {
buildManagedCommandHook,
Expand Down Expand Up @@ -51,7 +51,7 @@ export const OPENCLAUDE_HOOK_SETTINGS: ClaudeCompatibleHookSettings = {
export type NativeHookFormOptions = { execForm?: boolean }

export function getConfigPath(settings = CLAUDE_HOOK_SETTINGS, configDir?: string): string {
return join(configDir ?? join(homedir(), settings.configDirName), 'settings.json')
return join(configDir ?? claudeCompatibleConfigDir(settings.configDirName), 'settings.json')
}

export function getStatusLineScriptBaseName(settings = CLAUDE_HOOK_SETTINGS): string {
Expand Down