Skip to content

Commit 9f7e434

Browse files
FelixIsaacclaude
andcommitted
fix: improve cross-platform path expansion logic
- Refine ExpandPathsInJSON to better handle Unix path conversion - Only replace backslashes on lines with expanded path - Reduces risk of corrupting JSON escape sequences - Known issue: expansion not triggering on pull (investigation ongoing) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 725e06f commit 9f7e434

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

internal/sync/paths.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,23 @@ func ExpandPathsInJSON(data []byte, claudeDir string) []byte {
3939
escapedClaudeDir := strings.ReplaceAll(claudeDir, `\`, `\\`)
4040
content = strings.ReplaceAll(content, ClaudeDirPlaceholder, escapedClaudeDir)
4141
} else {
42-
// Unix: replace placeholder and convert any remaining backslashes to forward slashes
42+
// Unix: replace placeholder first
4343
content = strings.ReplaceAll(content, ClaudeDirPlaceholder, claudeDir)
44-
// Convert escaped backslashes (\\) to forward slashes
45-
content = strings.ReplaceAll(content, `\\`, `/`)
46-
// Convert single backslashes to forward slashes (shouldn't happen in JSON but just in case)
47-
content = strings.ReplaceAll(content, `\`, `/`)
44+
45+
// Convert path separators: replace \\ with / on lines that now contain the expanded path
46+
lines := strings.Split(content, "\n")
47+
for i, line := range lines {
48+
if strings.Contains(line, claudeDir) {
49+
// This line now contains the expanded path with backslashes
50+
// Replace \\ (escaped backslash in JSON = one actual backslash) with /
51+
// Go string literal: `\\` is actually two characters (backslash, backslash) in the source
52+
// When applied to JSON content, "C:\\Users" becomes /home/ubuntu/.claude\plugins\...
53+
// And we want to convert \plugins to /plugins
54+
line = strings.ReplaceAll(line, `\`, `/`)
55+
lines[i] = line
56+
}
57+
}
58+
content = strings.Join(lines, "\n")
4859
}
4960

5061
return []byte(content)

0 commit comments

Comments
 (0)