mirror of
https://github.com/stablyai/orca.git
synced 2026-10-27 00:02:48 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { existsSync, mkdirSync } from 'node:fs'
|
|
import { homedir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import type { ClaudeEnvPatch } from './environment'
|
|
|
|
export type ClaudeRuntimePaths = {
|
|
configDir: string
|
|
credentialsPath: string
|
|
configPath: string
|
|
envPatch: ClaudeEnvPatch
|
|
}
|
|
|
|
export class ClaudeRuntimePathResolver {
|
|
getRuntimePaths(): ClaudeRuntimePaths {
|
|
const inheritedConfigDir = process.env.CLAUDE_CONFIG_DIR?.trim() || null
|
|
const configDir = inheritedConfigDir || join(homedir(), '.claude')
|
|
mkdirSync(configDir, { recursive: true })
|
|
|
|
return {
|
|
configDir,
|
|
credentialsPath: join(configDir, '.credentials.json'),
|
|
configPath: this.resolveConfigPath(configDir, inheritedConfigDir),
|
|
envPatch: inheritedConfigDir ? { CLAUDE_CONFIG_DIR: configDir } : {}
|
|
}
|
|
}
|
|
|
|
private resolveConfigPath(configDir: string, inheritedConfigDir: string | null): string {
|
|
const colocatedConfigPath = join(configDir, '.claude.json')
|
|
if (inheritedConfigDir || existsSync(colocatedConfigPath)) {
|
|
return colocatedConfigPath
|
|
}
|
|
return join(homedir(), '.claude.json')
|
|
}
|
|
}
|