From 931ec32257320ec8f9deaeeef8e043eebc59c904 Mon Sep 17 00:00:00 2001 From: zhuguanqi Date: Tue, 10 Mar 2026 11:43:45 +0800 Subject: [PATCH] fix(claudecode): handle underscores in findProjectDir path matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude Code replaces underscores with hyphens when encoding project paths as directory names (e.g. sandwichlab_core → sandwichlab-core). findProjectDir only replaced path separators and colons, causing /list to return empty for projects with underscores in their path. Co-Authored-By: Claude Opus 4.6 --- agent/claudecode/claudecode.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/agent/claudecode/claudecode.go b/agent/claudecode/claudecode.go index 3ed966f..676a3e4 100644 --- a/agent/claudecode/claudecode.go +++ b/agent/claudecode/claudecode.go @@ -695,12 +695,15 @@ func summarizeInput(tool string, input any) string { func findProjectDir(homeDir, absWorkDir string) string { projectsBase := filepath.Join(homeDir, ".claude", "projects") - // Build candidate keys: different ways Claude Code might encode the path + // Build candidate keys: different ways Claude Code might encode the path. + // Claude Code replaces path separators, colons, and underscores with "-". candidates := []string{ // Unix-style: replace OS separator with "-" strings.ReplaceAll(absWorkDir, string(filepath.Separator), "-"), // Windows: replace both "\" and ":" with "-" strings.NewReplacer("/", "-", "\\", "-", ":", "-").Replace(absWorkDir), + // Claude Code also replaces underscores with "-" + strings.NewReplacer("/", "-", "\\", "-", ":", "-", "_", "-").Replace(absWorkDir), } // Also try with forward slashes (config might use forward slashes on Windows) fwd := strings.ReplaceAll(absWorkDir, "\\", "/") @@ -720,7 +723,7 @@ func findProjectDir(homeDir, absWorkDir string) string { return "" } - normWork := strings.ToLower(strings.NewReplacer("/", "-", "\\", "-", ":", "-").Replace(absWorkDir)) + normWork := strings.ToLower(strings.NewReplacer("/", "-", "\\", "-", ":", "-", "_", "-").Replace(absWorkDir)) for _, entry := range entries { if !entry.IsDir() { continue