fix: honor CLAUDE_CONFIG_DIR environment variable (#261)

Fixes #255

- Add getClaudeConfigDir() utility function that respects CLAUDE_CONFIG_DIR env var
- Update all hardcoded ~/.claude paths to use the new utility
- Add comprehensive tests for getClaudeConfigDir()
- Maintain backward compatibility with default ~/.claude when env var is not set

Files updated:
- src/shared/claude-config-dir.ts (new utility)
- src/shared/claude-config-dir.test.ts (tests)
- src/hooks/claude-code-hooks/config.ts
- src/hooks/claude-code-hooks/todo.ts
- src/hooks/claude-code-hooks/transcript.ts
- src/features/claude-code-command-loader/loader.ts
- src/features/claude-code-agent-loader/loader.ts
- src/features/claude-code-skill-loader/loader.ts
- src/features/claude-code-mcp-loader/loader.ts
- src/tools/session-manager/constants.ts
- src/tools/slashcommand/tools.ts

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
This commit is contained in:
Sisyphus
2025-12-26 23:28:33 +09:00
committed by GitHub
parent 15de6f637e
commit cad6425a4a
12 changed files with 97 additions and 26 deletions

View File

@@ -0,0 +1,60 @@
import { describe, test, expect, beforeEach, afterEach } from "bun:test"
import { homedir } from "node:os"
import { join } from "node:path"
import { getClaudeConfigDir } from "./claude-config-dir"
describe("getClaudeConfigDir", () => {
let originalEnv: string | undefined
beforeEach(() => {
originalEnv = process.env.CLAUDE_CONFIG_DIR
})
afterEach(() => {
if (originalEnv !== undefined) {
process.env.CLAUDE_CONFIG_DIR = originalEnv
} else {
delete process.env.CLAUDE_CONFIG_DIR
}
})
test("returns CLAUDE_CONFIG_DIR when env var is set", () => {
process.env.CLAUDE_CONFIG_DIR = "/custom/claude/path"
const result = getClaudeConfigDir()
expect(result).toBe("/custom/claude/path")
})
test("returns ~/.claude when env var is not set", () => {
delete process.env.CLAUDE_CONFIG_DIR
const result = getClaudeConfigDir()
expect(result).toBe(join(homedir(), ".claude"))
})
test("returns ~/.claude when env var is empty string", () => {
process.env.CLAUDE_CONFIG_DIR = ""
const result = getClaudeConfigDir()
expect(result).toBe(join(homedir(), ".claude"))
})
test("handles absolute paths with trailing slash", () => {
process.env.CLAUDE_CONFIG_DIR = "/custom/path/"
const result = getClaudeConfigDir()
expect(result).toBe("/custom/path/")
})
test("handles relative paths", () => {
process.env.CLAUDE_CONFIG_DIR = "./my-claude-config"
const result = getClaudeConfigDir()
expect(result).toBe("./my-claude-config")
})
})

View File

@@ -0,0 +1,11 @@
import { homedir } from "node:os"
import { join } from "node:path"
export function getClaudeConfigDir(): string {
const envConfigDir = process.env.CLAUDE_CONFIG_DIR
if (envConfigDir) {
return envConfigDir
}
return join(homedir(), ".claude")
}

View File

@@ -13,3 +13,4 @@ export * from "./dynamic-truncator"
export * from "./config-path"
export * from "./data-path"
export * from "./config-errors"
export * from "./claude-config-dir"