🐛 fix(playbook): use relative paths in CLAUDE.md when not at project root

When CLAUDE.md lives in a subdirectory (e.g. .claude/CLAUDE.md), the
@AGENTS.md import must use ../AGENTS.md since Claude Code resolves @path
relative to the file's directory. Calculate depth automatically.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
csh 2026-05-17 08:11:48 +08:00
parent 6518f0f554
commit c8d6bf21a6
1 changed files with 11 additions and 2 deletions

View File

@ -746,11 +746,20 @@ def sync_claude_md(project_root: Path, config: dict) -> None:
if claude_md is None: if claude_md is None:
claude_md = project_root / "CLAUDE.md" claude_md = project_root / "CLAUDE.md"
rel_prefix = ""
try:
rel = claude_md.parent.resolve().relative_to(project_root.resolve())
if rel != Path("."):
depth = len(rel.parts)
rel_prefix = "../" * depth
except ValueError:
pass
block_lines = [ block_lines = [
_CLAUDE_BLOCK_START, _CLAUDE_BLOCK_START,
"", "",
"@AGENTS.md", f"@{rel_prefix}AGENTS.md",
"@AGENT_RULES.md", f"@{rel_prefix}AGENT_RULES.md",
"", "",
_CLAUDE_BLOCK_END, _CLAUDE_BLOCK_END,
] ]