fix: validate sessionId on resume and respect CLAUDE_CONFIG_DIR
- Use CLAUDE_CONFIG_DIR env var for Claude config location - Rename tool call name to 'permission' for permission requests - Update tests to use CLAUDE_CONFIG_DIR instead of HOME
This commit is contained in:
@@ -1261,9 +1261,10 @@ function normalizeCwdCandidates(cwd: string): string[] {
|
||||
}
|
||||
|
||||
function cleanupClaudeHistory(cwd: string) {
|
||||
const configDir = process.env.CLAUDE_CONFIG_DIR ?? path.join(os.homedir(), ".claude");
|
||||
for (const candidate of normalizeCwdCandidates(cwd)) {
|
||||
const sanitized = sanitizeClaudeProjectName(candidate);
|
||||
const projectDir = path.join(os.homedir(), ".claude", "projects", sanitized);
|
||||
const projectDir = path.join(configDir, "projects", sanitized);
|
||||
if (existsSync(projectDir)) {
|
||||
rmSync(projectDir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -325,7 +325,8 @@ export class ClaudeAgentClient implements AgentClient {
|
||||
}
|
||||
|
||||
async listPersistedAgents(options?: ListPersistedAgentsOptions): Promise<PersistedAgentDescriptor[]> {
|
||||
const projectsRoot = path.join(os.homedir(), ".claude", "projects");
|
||||
const configDir = process.env.CLAUDE_CONFIG_DIR ?? path.join(os.homedir(), ".claude");
|
||||
const projectsRoot = path.join(configDir, "projects");
|
||||
if (!(await pathExists(projectsRoot))) {
|
||||
return [];
|
||||
}
|
||||
@@ -628,7 +629,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
};
|
||||
pending.resolve(result);
|
||||
this.pushToolCall({
|
||||
name: pending.request.name,
|
||||
name: "permission",
|
||||
status: "granted",
|
||||
callId: pending.request.id,
|
||||
input: pending.request.input,
|
||||
@@ -641,7 +642,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
};
|
||||
pending.resolve(result);
|
||||
this.pushToolCall({
|
||||
name: pending.request.name,
|
||||
name: "permission",
|
||||
status: "denied",
|
||||
callId: pending.request.id,
|
||||
input: pending.request.input,
|
||||
@@ -1050,7 +1051,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
};
|
||||
|
||||
this.pushToolCall({
|
||||
name: toolName,
|
||||
name: "permission",
|
||||
status: "requested",
|
||||
callId: requestId,
|
||||
input,
|
||||
@@ -1075,7 +1076,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
cleanup();
|
||||
const error = new Error("Permission request timed out");
|
||||
this.pushToolCall({
|
||||
name: toolName,
|
||||
name: "permission",
|
||||
status: "denied",
|
||||
callId: requestId,
|
||||
input,
|
||||
|
||||
@@ -2660,13 +2660,11 @@ describe("daemon E2E", () => {
|
||||
|
||||
describe("Claude persisted agent import", () => {
|
||||
test("filters internal warmup entries from persisted Claude history", async () => {
|
||||
const previousHome = process.env.HOME;
|
||||
const previousUserProfile = process.env.USERPROFILE;
|
||||
const homeDir = mkdtempSync(path.join(tmpdir(), "claude-home-"));
|
||||
process.env.HOME = homeDir;
|
||||
process.env.USERPROFILE = homeDir;
|
||||
const previousClaudeConfigDir = process.env.CLAUDE_CONFIG_DIR;
|
||||
const claudeConfigDir = mkdtempSync(path.join(tmpdir(), "claude-config-"));
|
||||
process.env.CLAUDE_CONFIG_DIR = claudeConfigDir;
|
||||
|
||||
const projectDir = path.join(homeDir, ".claude", "projects", "test-project");
|
||||
const projectDir = path.join(claudeConfigDir, "projects", "test-project");
|
||||
mkdirSync(projectDir, { recursive: true });
|
||||
|
||||
const sessionId = `session-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
||||
@@ -2708,17 +2706,12 @@ describe("daemon E2E", () => {
|
||||
expect(timelineTexts).toContain("Real task prompt");
|
||||
expect(timelineTexts).not.toContain("Warmup");
|
||||
} finally {
|
||||
if (previousHome === undefined) {
|
||||
delete process.env.HOME;
|
||||
if (previousClaudeConfigDir === undefined) {
|
||||
delete process.env.CLAUDE_CONFIG_DIR;
|
||||
} else {
|
||||
process.env.HOME = previousHome;
|
||||
process.env.CLAUDE_CONFIG_DIR = previousClaudeConfigDir;
|
||||
}
|
||||
if (previousUserProfile === undefined) {
|
||||
delete process.env.USERPROFILE;
|
||||
} else {
|
||||
process.env.USERPROFILE = previousUserProfile;
|
||||
}
|
||||
rmSync(homeDir, { recursive: true, force: true });
|
||||
rmSync(claudeConfigDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user