Skip to content

Duplicate projects in sidebar #38

Closed

Description

@joshmlambert

I'm seeing duplicated projects in the sidebar like in this screenshot:

Image

There is a 3rd entry with the same name which actually has sessions under it, but the two in the image don't. I'm not able to archive them or anything, they just clutter the sidebar. Not sure if it might be due to spaces in the folder name or something else.

Activity

  1. joshmlambert commented on May 1, 2026

    @joshmlambert
    Author

    Here's some analysis found from Claude... it does indeed look like a couple bugs:


    Bug: Duplicate projects in sidebar for paths with spaces or dots

    Description

    Two separate bugs combine to produce phantom duplicate project entries in the sidebar that cannot be dismissed.


    Bug 1: Folder naming mismatch between Switchboard and Claude CLI

    File: main.js:296

    When a project is added via the "Add project" button, Switchboard creates a folder in ~/.claude/projects/ using this formula:

    projectPath.replace(/[/_]/g, '-').replace(/^-/, '-')

    This only replaces / and _. Claude CLI uses a broader formula that replaces all non-alphanumeric characters (spaces, dots, etc.) with hyphens.

    Example:

    • Project path: /Users/jla/claude-projects/AI Enablement Plan
    • Switchboard creates: -Users-jla-claude-projects-AI Enablement Plan ← space preserved
    • Claude CLI creates: -Users-jla-claude-projects-AI-Enablement-Plan ← space → hyphen

    The result is two folders on disk for the same project. Every real session the CLI writes goes into its folder; the Switchboard-created folder contains only the seed .jsonl stub.

    This also affects paths with dots (e.g. msci-6.1-upgrade-analysis → msci-6-1-upgrade-analysis).

    Fix: Update Switchboard's folder naming formula to match Claude CLI: projectPath.replace(/[^a-zA-Z0-9-]/g, '-')


    Bug 2: buildProjectsFromCache creates project entries for folders with only archived sessions

    File: session-cache.js:175–196

    In buildProjectsFromCache, the project entry for a folder is added to projectMap before the archive filter runs:

    if (!projectMap.has(row.folder)) {
    projectMap.set(row.folder, { ..., sessions: [] }); // created here
    }
    // ...
    if (!showArchived && s.archived) continue; // filtered here
    projectMap.get(row.folder).sessions.push(s);

    If a folder has sessions in the DB but all are archived, and showArchived=false (the default), the folder appears in the sidebar as an empty project with no sessions.

    This compounds Bug 1: the Switchboard-created stub folder has one session (the seed .jsonl). Once that seed session gets treated as archived or otherwise hidden, the folder shows up as an empty phantom project. The archive button is
    then a no-op because its handler exits early when project.sessions is empty:

    // sidebar.js — archive button handler
    const sessions = project.sessions.filter(s => !s.archived);
    if (sessions.length === 0) return; // ← nothing to archive, can't dismiss the entry

    Fix: After the loop in buildProjectsFromCache, remove any project entry that (a) has sessions in the DB but (b) ended up with zero visible sessions due to archive filtering. Truly empty projects (no sessions in DB at all, just a new
    folder on disk) should still appear.


    Reproduction

    1. Add a project whose path contains spaces (e.g. /Users/you/projects/My Project) via the "Add project" button
    2. Run claude in that directory — the CLI creates a differently-named folder
    3. Both folders appear in the sidebar as the same project name
    4. The Switchboard-created entry shows no sessions and cannot be archived
  2. abasiri commented on May 4, 2026

    @abasiri
    Contributor

    Confirmed both bugs and put up a fix in #41. tl;dr:

    Bug 1 (folder-name mismatch): the analysis above is correct that Switchboard's regex was too narrow, but the suggested fix [^a-zA-Z0-9-] still doesn't fully match the CLI. I pulled the actual algorithm out of the claude 2.1.126 binary:

    function encodeProjectPath(p) {
      const s = p.replace(/[^a-zA-Z0-9]/g, '-');
      if (s.length <= 200) return s;
      let h = 0;
      for (let i = 0; i < p.length; i++) h = (h << 5) - h + p.charCodeAt(i) | 0;
      return s.slice(0, 200) + '-' + Math.abs(h).toString(36);
    }

    It's [^a-zA-Z0-9] (not [^a-zA-Z0-9-]), and there's a 200-char cap with a Java-style String.hashCode-derived suffix on overflow that Switchboard wasn't handling. The function is pure and deterministic, so mirroring it produces byte-identical folder names to the CLI for any project path.

    Bug 2 (phantom empty projects): confirmed and fixed by moving the projectMap.set(...) call to after the archive filter in session-cache.js. Folders whose sessions are all archived no longer appear as undismissable empty entries when "show archived" is off.

    Migration: existing duplicate folders on disk from before the fix are left alone (auto-cleanup felt risky). If you have leftover dupes, you can rm -rf ~/.claude/projects/<the-bad-folder-name> manually. Any project you add or claude you run after the fix will encode correctly and merge with the CLI's folder.

    PR #41 also supersedes #37, which fixed the Windows half of Bug 1 — [^a-zA-Z0-9] covers \ and : for free.

    — Claude (Opus 4.7), on behalf of @abassiri

  3. added a commit that references this issue on May 4, 2026
    560e4c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions