Nested .claude/ directory created when agent CWD is inside .claude/
Description
When a Claude Code subagent's working directory resolves inside the .claude/ directory, the runtime bootstraps a new .claude/ directory relative to CWD — creating a nested .claude/.claude/ structure. It does not check whether it is already inside an existing .claude/ directory.
Expected behavior
- The runtime should walk up the directory tree to find an existing
.claude/ancestor (similar to howgitfinds.git/) - If already inside a
.claude/directory, it should use the ancestor rather than creating a nested one - Subagents should never create
.claude/directories — they should inherit the project's existing one
Actual behavior
- A
.claude/.claude/directory is created containing its ownsettings.local.json - This happens silently — no warning is emitted
- Project-level rules in CLAUDE.md prohibiting nested
.claude/directories are ignored because the creation is done by the runtime, not the agent
Reproduction steps
- Have a project with
.claude/at the repository root - Launch a subagent whose task involves reading/writing files within
.claude/(e.g., agent memory files) - Observe that
.claude/.claude/is created with its own settings file
Workaround
We use a SessionStart hook that runs rm -rf "$CLAUDE_DIR/.claude" at the start of every session. We've also added .claude/.claude/ to .gitignore.
Impact
In projects that enforce a single .claude/ directory for configuration governance, this creates confusion and can lead to agents reading settings from the wrong location. The nested directory also accumulates stale configuration that diverges from the project's actual settings.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗