Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions encode-project-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Mirror Claude CLI's project-folder naming so Switchboard-created folders
// match the ones the CLI writes for the same project path.
// Reverse-engineered from claude CLI 2.1.126.
function encodeProjectPath(projectPath) {
const sanitized = projectPath.replace(/[^a-zA-Z0-9]/g, '-');
if (sanitized.length <= 200) return sanitized;
let h = 0;
for (let i = 0; i < projectPath.length; i++) {
h = (h << 5) - h + projectPath.charCodeAt(i) | 0;
}
return sanitized.slice(0, 200) + '-' + Math.abs(h).toString(36);
}

module.exports = { encodeProjectPath };
7 changes: 4 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ipcMain.handle('reload-shell-env', async () => {
// Shell profiles → shell-profiles.js
const { discoverShellProfiles, getShellProfiles, resolveShell, isWindows, isWslShell, windowsToWslPath, shellArgs } = require('./shell-profiles');
const { startScheduler } = require('./schedule-runner');
const { encodeProjectPath } = require('./encode-project-path');



Expand Down Expand Up @@ -331,7 +332,7 @@ ipcMain.handle('add-project', (_event, projectPath) => {
}

// Create the corresponding folder in ~/.claude/projects/ so it persists
const folder = projectPath.replace(/[/_]/g, '-').replace(/^-/, '-');
const folder = encodeProjectPath(projectPath);
const folderPath = path.join(PROJECTS_DIR, folder);
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true });
Expand Down Expand Up @@ -367,7 +368,7 @@ ipcMain.handle('remove-project', (_event, projectPath) => {
setSetting('global', global);

// Clean up DB cache and search index for this folder
const folder = projectPath.replace(/[/_]/g, '-').replace(/^-/, '-');
const folder = encodeProjectPath(projectPath);
deleteCachedFolder(folder);
deleteSearchFolder(folder);
deleteSetting('project:' + projectPath);
Expand Down Expand Up @@ -1031,7 +1032,7 @@ ipcMain.handle('open-terminal', async (_event, sessionId, projectPath, isNew, se

if (!isPlainTerminal) {
// Snapshot existing .jsonl files before spawning (for new session + fork/plan detection)
projectFolder = projectPath.replace(/[/_]/g, '-').replace(/^-/, '-');
projectFolder = encodeProjectPath(projectPath);
const claudeProjectDir = path.join(PROJECTS_DIR, projectFolder);
if (fs.existsSync(claudeProjectDir)) {
try {
Expand Down
Loading