To fix broken agent instructions across repos and git worktrees, engineers must resolve path-relative symlink failures, automate cross-repository rule synchronization, and decouple agent instructions from isolated branch states. Standardizing shared configs into centralized global directories or utilizing automated skill sync prevents rule drift across Cursor, Claude Code, Codex, and Google Antigravity.
Why Do AI Agent Instructions Break Across Repositories and Git Worktrees?
AI agent instructions break across repositories and Git worktrees because modern coding assistants evaluate instructions through local directory trees rather than global operating system context. When developers operate across microservices, polyrepos, or isolated branch checkouts, files like CLAUDE.md, AGENTS.md, and .cursor/rules become trapped inside specific branch commits or fail to resolve across non-standard filesystem layouts. Consequently, an instruction updated on one feature branch or repository remains completely unknown to adjacent directories.
Software engineers leveraging advanced Git workflows frequently utilize worktrees to execute parallel tasks. As detailed in the official Git Worktree documentation:
"A git repository can support multiple working trees, allowing you to check out more than one branch at a time. With git worktree add a new working tree is associated with the repository, along with additional metadata..."
While Git worktrees provide exceptional isolation for compiling source code and running test suites, they reveal four severe structural points of failure for AI agent instructions:
1. The Git Worktree Inode Trap and Broken Relative Symlinks
In a standard Git checkout, the repository root contains a true .git/ directory. Many engineers attempt to share agent instructions across repositories by symlinking configuration directories (for instance, creating a symbolic link from .cursor/rules to a shared dotfiles folder). However, when you create a secondary worktree using git worktree add ../feature-branch feature-branch, Git does not duplicate the .git folder. Instead, it creates a plain ASCII file containing a path reference: gitdir: /path/to/main/.git/worktrees/feature-branch. Any relative symlinks configured within the parent directory structure break immediately because the relative parent traversal fails inside the linked worktree.
2. Branch Drift and Stale Commit Overwrites
When instruction files like AGENTS.md or .cursor/rules/*.mdc are committed directly into a git repository's version control, they become bound to that branch's git history. If an engineer optimizes a prompt for refactoring database migrations on feature/user-auth, that improved instruction exists solely on that branch. When switching to main, checking out an older hotfix branch, or opening a parallel repo, the AI agent reverts to whatever stale instructions existed when that branch was branched. Merging older feature branches can even trigger silent merge conflicts or overwrite newer prompt instructions with legacy versions.
3. Monolithic In-Repo Context Stuffing
Duplicating multi-thousand-word instruction files across every microservice repository creates immense token bloat. In modern LLM coding workflows, every prompt turn consumes context budget. Copying monolithic guidelines covering database rules, frontend styling, API error formatting, and security checklists into every repository's CLAUDE.md forces the agent to read 2,000 to 4,000 tokens of boilerplate on every command—even when you are simply asking the agent to fix a typo in documentation.
4. Format Fragmentation Across Coding Assistants
Modern engineering teams rarely use a single AI tool. Developers switch fluidly between Anthropic's Claude Code CLI in the terminal, Cursor in the IDE, OpenAI Codex, and Google Antigravity. As documented in our deep-dive on CLAUDE.md vs AGENTS.md format differences, each agent expects its own schema: Claude Code inspects CLAUDE.md and ~/.claude/skills, Cursor parses .cursor/rules, and Codex relies on AGENTS.md. Maintaining parity across three tools in ten repositories requires updating thirty separate files manually.
The Sprawl Moment: When Your Best Rules Vanish on a New Branch
You spend two days dialing in an automated test-generation instruction inside your core API repository—tuning edge-case prompts, setting up lint assertions, and eliminating hallucinations until Cursor and Claude Code generate pristine pull requests. Later that afternoon, you spin up a secondary git worktree (git worktree add ../feature-auth feature/auth-refactor) to tackle an urgent migration, and open a secondary microservice repo. You launch your coding agent, issue the prompt, and watch in disbelief as the agent completely ignores your architecture guidelines, suggests deprecated libraries, and reintroduces the exact security flaws you spent all morning debugging. The instruction file exists only on the unmerged branch of your primary checkout, leaving your new worktree and adjacent repositories completely stranded.
Prompttly is a skill manager for AI agents — one library for your skills and prompts that syncs into Claude Code, Codex, ChatGPT, and Claude and is one hotkey away on your Mac, so your setup follows you across every machine, repo, and tool.
By centralizing your AI agent instructions into a unified, version-controlled library, you eliminate the friction of copying markdown files across folders. Whether you launch an agent inside a new git worktree, switch physical laptops, or jump between Cursor and terminal CLIs, your proven instructions follow you automatically.
Cross-Agent Repository Configuration and Worktree Support Matrix
Understanding where each AI coding agent expects instruction files and how each handles Git worktrees is critical for multi-repo architecture. The following matrix details configuration paths and worktree resolution behavior across the leading agent environments:
| Agent Environment | In-Repo Instruction File | Global User Scope Directory | Git Worktree Resolution Behavior | Recommended Sync Mechanism |
|---|---|---|---|---|
| Claude Code (Anthropic) | CLAUDE.md, .claude/skills/ | ~/.claude/skills/ | Reads worktree root; merges global skills seamlessly | Sync into ~/.claude/skills via Prompttly |
| Cursor (Anysphere) | .cursor/rules/*.mdc, .cursorrules | Cursor Settings (Global Rules) | Requires opening worktree as fresh VS Code workspace | Global hotkey insertion or repo symlink scripts |
| OpenAI Codex / Amp | AGENTS.md | ~/.codex/skills/ | Evaluates current working directory up to git root | Sync into ~/.codex/skills via Prompttly |
| Google Antigravity | .agent/rules, AGENTS.md | ~/.gemini/antigravity/skills/ | Discovers parent corpus and active workspace directory | Centralized skill library & MCP endpoint |
Notice from the table that while project files like CLAUDE.md require branch-specific maintenance, all major agents support a global user scope directory. As stated in the official Anthropic Claude Code documentation:
"Each surface connects to the same underlying Claude Code engine, so your repo’s CLAUDE.md files, settings, and MCP servers work across all of them."
By moving reusable prompts and skills out of ephemeral branch files and into persistent global agent directories, your instructions remain immediately accessible across every checkout and worktree on your machine.
How Do You Audit and Detect Instruction Drift Across Multiple Repositories?
You audit and detect instruction drift across multiple repositories by inspecting file checksums and comparing markdown diffs across your project roots. Before implementing a synchronization strategy, running an automated scan identifies which repositories contain stale, divergent, or missing agent instructions. Using standard POSIX utilities, developers can fingerprint all agent instructions across their entire workspace in seconds.
Execute the following Bash script in your root development directory (e.g., ~/Projects) to calculate 256-bit cryptographic fingerprints (SHA-256) of all agent instruction files:
#!/usr/bin/env bash
# audit-agent-instructions.sh: Audit prompt & rule drift across git repositories
set -euo pipefail
WORKSPACE_ROOT="${1:-$HOME/Projects}"
echo "Auditing agent instruction files across: $WORKSPACE_ROOT"
echo "---------------------------------------------------------"
# Find all instruction files across repositories and worktrees
find "$WORKSPACE_ROOT" -maxdepth 4 -type f \( \
-name "CLAUDE.md" -o \
-name "AGENTS.md" -o \
-path "*/.cursor/rules/*.mdc" \
\) ! -path "*/node_modules/*" ! -path "*/.git/*" | while read -r filepath; do
# Generate SHA-256 hash
if command -v shasum >/dev/null 2>&1; then
HASH=$(shasum -a 256 "$filepath" | awk '{print $1}')
else
HASH=$(sha256sum "$filepath" | awk '{print $1}')
fi
REL_PATH="${filepath#$WORKSPACE_ROOT/}"
printf "%-64s %s\n" "$HASH" "$REL_PATH"
done | sortIf identical files (such as a shared code review rule or security guideline) yield different hash values across repositories, your instructions have drifted. Next, you can inspect the exact divergence between any two repositories using standard git diff:
# Compare instruction differences between two microservices or worktrees
diff -u ~/Projects/api-service/CLAUDE.md ~/Projects/billing-service/CLAUDE.md
# Inspect changes made on a feature worktree versus the main repo
git diff main..HEAD -- CLAUDE.md .cursor/rules/What Are the 4 Proven Strategies for Synchronizing Agent Instructions Across Repos?
The 4 proven strategies for synchronizing agent instructions across repositories are: leveraging global user-scope directories, mounting centralized Git submodules, establishing absolute symlinks via dotfile managers, and deploying dedicated cloud skill managers with bidirectional sync. Each approach addresses different organizational constraints, balancing automation against setup complexity.
Strategy 1: Move Reusable Workflows to Global User Scope
The most resilient native technique is to split instructions by scope: keep project-specific facts (such as build commands and directory paths) in CLAUDE.md or AGENTS.md, but migrate all repeatable workflows into your global agent directory. For Claude Code, store skills in ~/.claude/skills/<skill-name>/SKILL.md. When Claude Code executes in any repository or worktree, it automatically discovers and loads these global skills without requiring a single file inside the repository. Read our guide on global Claude skills across projects to structure this two-layer hierarchy.
Strategy 2: Mount Centralized Git Submodules
For engineering teams requiring uniform rules across fifty repositories, creating a dedicated shared-agent-rules git repository and mounting it as a submodule is an established pattern:
# Add shared rules as a submodule in your target repository
git submodule add git@github.com:org/shared-agent-rules.git .agent-rules
# In Claude Code or Codex, reference the submodule path in your base prompt
echo "Include rules from .agent-rules/AGENTS.md" >> AGENTS.mdWhile submodules ensure version-locked auditing, they introduce significant friction: developers must remember to run git submodule update --remote, merge conflicts frequently occur during rebase operations, and secondary git worktrees require explicit git submodule update --init --recursive invocations.
Strategy 3: Absolute-Path Symlink Management
If your team relies heavily on Cursor rules in .cursor/rules, you can maintain a single directory of .mdc rule files in ~/.config/cursor-rules/ and link them into each repository using absolute paths rather than relative paths:
# Use absolute target paths to prevent Git worktree relative traversal failures
mkdir -p .cursor/rules
ln -sfn "$HOME/.config/cursor-rules/code-style.mdc" .cursor/rules/code-style.mdc
ln -sfn "$HOME/.config/cursor-rules/testing.mdc" .cursor/rules/testing.mdcUsing absolute paths ensures that when you spin up a secondary git worktree in ../feature-worktree, the symlinks continue to resolve correctly back to your home directory. However, you must add .cursor/rules/*.mdc to your global ~/.gitignore so local developer symlinks are never committed into shared team repositories.
Strategy 4: Cloud-Synchronized Skill Manager (Prompttly)
The most scalable, zero-maintenance approach is to manage your skills in a dedicated skill manager like Prompttly. Instead of maintaining fragile symlinks, managing submodule commits, or manually re-syncing repositories across machines (as detailed in our guide to synchronizing prompts across laptops), Prompttly automatically writes your skill packages directly into ~/.claude/skills and ~/.codex/skills on your Mac.
When you update a prompt or author a new skill, Prompttly’s two-way sync updates the local filesystem instantly. Every repository, worktree, and CLI session gains immediate access to the updated workflow. Furthermore, Prompttly’s global hotkey palette lets you trigger and insert any prompt or skill into Cursor, Xcode, or web browsers with sub-200ms latency.
When Should You Keep Instructions In-Repo vs. In a Centralized Skill Manager?
You should keep instructions inside the repository when they dictate non-negotiable project boundaries, and store them in a centralized skill manager when they govern personal developer productivity workflows. Combining repository-level context files with a centralized skill manager creates the optimal balance between team compliance and developer velocity.
| Criterion | In-Repository (CLAUDE.md / AGENTS.md) | Centralized Skill Manager (Prompttly) |
|---|---|---|
| Target Audience | Every contributor, CI/CD bots, open-source forks | The individual engineer across all their tools |
| Typical Contents | Build commands, test runners, strict linting rules, schema boundaries | Refactoring skills, PR drafting prompts, review checklists, debugging rubrics |
| Worktree Behavior | Tied to branch commit; diverges across branches | Universal across all worktrees, branches, and repos |
| Maintenance Overhead | High: requires separate PRs and commits in every repo | Zero: update once in Prompttly, synced everywhere |
For technical teams evaluating modern tooling architectures, exploring the best prompt managers for developers offers a structured comparison of terminal CLI integrations, hotkey palettes, and agent synchronization options. You can also generate standardized SKILL.md definitions using the free Claude Skill Creator tool to ensure all your multi-repo workflows adhere to official schemas.
Discover more developer workflow guides, prompt engineering frameworks, and multi-agent tutorials on the Prompttly AI resources hub.
Related Prompt Resources
Stop copying agent instructions between repos
Prompttly synchronizes your prompt and skill library into Claude Code, Codex, Cursor, and ChatGPT. Keep your workflows uniform across every git worktree and repository with sub-200ms hotkey access on macOS.