Submodule project path derived from .git/modules/ instead of working directory

Status Fixed / completed
Maintainer reply None cached
Activity 4 comments · opened Mar 25, 2026 · closed Mar 25, 2026

Summary

When Claude Code runs inside a git submodule, the project path (used for ~/.claude/projects/<key>/) is derived from the git metadata path (.git/modules/...) instead of the actual working directory.

Reproduction

  1. Have a repo with a git submodule (e.g., parent-repo/submodule/)
  2. Launch Claude Code from the submodule directory

Expected: Project dir key derived from the working directory:

~/.claude/projects/-Users-me-Dev-parent-repo-submodule/

Actual: Project dir key derived from git metadata path:

~/.claude/projects/-Users-me-Dev-parent-repo--git-modules-submodule/

Root cause

Likely using git worktree list --porcelain to determine the working directory. For submodules, the main worktree entry returns the bare git metadata directory:

$ cd parent-repo/submodule
$ git worktree list --porcelain
worktree /Users/me/Dev/parent-repo/.git/modules/submodule
HEAD abc123
branch refs/heads/main

git rev-parse --show-toplevel returns the correct path:

$ git rev-parse --show-toplevel
/Users/me/Dev/parent-repo/submodule

Impact

The submodule gets an unexpected project key, so project-scoped state (memory, settings) is stored under a path that doesn't correspond to the actual working directory.

View original on GitHub ↗

4 Comments

github-actions[bot] · 6 months ago

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/29256

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

mhonsel · 6 months ago

Per the memory docs:

The <project> path is derived from the git repository, so all worktrees and subdirectories within the same repo share one auto memory directory.

So the intent is for all worktrees to share one project directory. For submodules, they're getting a separate project key derived from .git/modules/ instead, which breaks this.

mhonsel · 6 months ago

Closing as duplicate of #29256 — same root cause (git submodule worktree path resolved from .git/modules/ instead of the actual working directory).

github-actions[bot] · 6 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.