Nested .claude/ directory created when agent CWD is inside .claude/

Resolved 💬 3 comments Opened Mar 14, 2026 by jamieadams-nerd Closed May 4, 2026

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 how git finds .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 own settings.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

  1. Have a project with .claude/ at the repository root
  2. Launch a subagent whose task involves reading/writing files within .claude/ (e.g., agent memory files)
  3. 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.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗