✨ feat(playbook): auto-inject AGENTS.md into CLAUDE.md
When any sync action runs and the target project already has a CLAUDE.md, automatically insert @AGENTS.md / @AGENT_RULES.md import block so Claude Code picks up the same rules as Codex without manual setup. - Add sync_claude_md() called at end of sync_agents_template() - Uses <!-- playbook:claude:start/end --> block markers for idempotent updates - Skips if no CLAUDE.md exists (Codex users unaffected) - Skips if @AGENTS.md already present (manual setups respected) - Add 4 tests covering: no file, append, update block, already-referenced Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -721,9 +721,56 @@ def sync_agents_template(context: dict) -> int:
|
||||
date_value,
|
||||
playbook_scripts,
|
||||
)
|
||||
sync_claude_md(project_root)
|
||||
return 0
|
||||
|
||||
|
||||
_CLAUDE_BLOCK_START = "<!-- playbook:claude:start -->"
|
||||
_CLAUDE_BLOCK_END = "<!-- playbook:claude:end -->"
|
||||
|
||||
|
||||
def sync_claude_md(project_root: Path) -> None:
|
||||
claude_md = project_root / "CLAUDE.md"
|
||||
if not claude_md.exists():
|
||||
return
|
||||
|
||||
block_lines = [
|
||||
_CLAUDE_BLOCK_START,
|
||||
"",
|
||||
"@AGENTS.md",
|
||||
"@AGENT_RULES.md",
|
||||
"",
|
||||
_CLAUDE_BLOCK_END,
|
||||
]
|
||||
|
||||
text = claude_md.read_text(encoding="utf-8")
|
||||
|
||||
if _CLAUDE_BLOCK_START in text:
|
||||
lines = text.splitlines()
|
||||
updated: list[str] = []
|
||||
in_block = False
|
||||
replaced = False
|
||||
for line in lines:
|
||||
if not replaced and line.strip() == _CLAUDE_BLOCK_START:
|
||||
updated.extend(block_lines)
|
||||
in_block = True
|
||||
replaced = True
|
||||
continue
|
||||
if in_block:
|
||||
if line.strip() == _CLAUDE_BLOCK_END:
|
||||
in_block = False
|
||||
continue
|
||||
updated.append(line)
|
||||
claude_md.write_text("\n".join(updated) + "\n", encoding="utf-8")
|
||||
log("Updated CLAUDE.md (playbook block).")
|
||||
elif "@AGENTS.md" in text:
|
||||
log("Skip: CLAUDE.md already references AGENTS.md")
|
||||
else:
|
||||
appended = text.rstrip("\n") + "\n\n" + "\n".join(block_lines) + "\n"
|
||||
claude_md.write_text(appended, encoding="utf-8")
|
||||
log("Appended playbook block to CLAUDE.md")
|
||||
|
||||
|
||||
def should_sync_agents(config: dict) -> bool:
|
||||
for key in ("sync_rules", "sync_memory_bank", "sync_prompts", "sync_standards"):
|
||||
if key in config:
|
||||
|
||||
Reference in New Issue
Block a user