Skip to content

Git worktrees produce isolated container tags, fragmenting project memory #27

@nwentling5

Description

@nwentling5

Problem

When using git worktrees (e.g. via tools like Conductor that spin up parallel workspaces), each worktree gets its own container tag, completely isolating memories from the same project.

getGitRoot() in src/lib/container-tag.js uses git rev-parse --show-toplevel, which returns the worktree path — not the main repo root. Since the container tag is derived from a SHA256 of that path, every worktree becomes its own memory silo.

Example

For a project at /Users/me/myproject with worktrees in .conductor/:

Path Container Tag
/Users/me/myproject claudecode_project_fe131957
/Users/me/myproject/.conductor/workspace-a claudecode_project_45c1779a
/Users/me/myproject/.conductor/workspace-b claudecode_project_a0136a23

These are all the same codebase but get completely separate memory buckets. Sessions in one workspace can't recall anything from another.

Fix

Replace git rev-parse --show-toplevel with a check for git rev-parse --git-common-dir first:

const path = require('node:path');

function getGitRoot(cwd) {
  try {
    const gitCommonDir = execSync('git rev-parse --git-common-dir', {
      cwd,
      encoding: 'utf-8',
      stdio: ['pipe', 'pipe', 'pipe'],
    }).trim();

    // Worktree: git-common-dir is an absolute path to the main repo's .git
    if (gitCommonDir && gitCommonDir !== '.git') {
      const resolved = path.resolve(cwd, gitCommonDir);
      return path.dirname(resolved);
    }

    // Normal repo: use show-toplevel
    const gitRoot = execSync('git rev-parse --show-toplevel', {
      cwd,
      encoding: 'utf-8',
      stdio: ['pipe', 'pipe', 'pipe'],
    }).trim();
    return gitRoot || null;
  } catch {
    return null;
  }
}

How it works

  • Normal repo: --git-common-dir returns .git (relative) → falls through to --show-toplevel as before
  • Worktree: --git-common-dir returns an absolute path like /Users/me/myproject/.git → take the parent as the repo root

After this change, all worktrees resolve to the same container tag as the main repo.

Impact

Anyone using git worktrees (directly or via tooling like Conductor) is silently losing cross-session memory. Each workspace starts fresh with "No previous memories found" even though dozens of sessions have been saved — just under different tags.

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