From 1b99c9422b626cb655b95db8a3a2e5152afcbb44 Mon Sep 17 00:00:00 2001 From: weishu Date: Wed, 17 Dec 2025 20:00:35 +0800 Subject: [PATCH] fix: handle underscores in project path generation Add underscore to the regex pattern in getProjectPath to ensure underscores are replaced with hyphens, along with existing handling for slashes, colons, and dots. Includes test case for paths with underscores. --- cli/src/claude/utils/path.test.ts | 6 ++++++ cli/src/claude/utils/path.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/src/claude/utils/path.test.ts b/cli/src/claude/utils/path.test.ts index 3e0e594c..9293d778 100644 --- a/cli/src/claude/utils/path.test.ts +++ b/cli/src/claude/utils/path.test.ts @@ -38,6 +38,12 @@ describe('getProjectPath', () => { expect(result).toBe(join('/home/user', '.claude', 'projects', '-var-www-my-site-com-public')); }); + it('should replace underscores with hyphens in the project path', () => { + const workingDir = '/data/github/hapi__worktrees/ime'; + const result = getProjectPath(workingDir); + expect(result).toBe(join('/home/user', '.claude', 'projects', '-data-github-hapi--worktrees-ime')); + }); + it('should handle relative paths by resolving them first', () => { const workingDir = './my-project'; const result = getProjectPath(workingDir); diff --git a/cli/src/claude/utils/path.ts b/cli/src/claude/utils/path.ts index 39a638af..5580e3b1 100644 --- a/cli/src/claude/utils/path.ts +++ b/cli/src/claude/utils/path.ts @@ -2,7 +2,7 @@ import { homedir } from "node:os"; import { join, resolve } from "node:path"; export function getProjectPath(workingDirectory: string) { - const projectId = resolve(workingDirectory).replace(/[\\\/\.:]/g, '-'); + const projectId = resolve(workingDirectory).replace(/[\\\/\.:_]/g, '-'); const claudeConfigDir = process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude'); return join(claudeConfigDir, 'projects', projectId); } \ No newline at end of file