How sync-agent-rules.sh Regenerates Platform-Specific Instruction Files

sync-agent-rules.sh regenerates platform-specific instruction files by reading AGENTS.md, resolving Claude-style @file imports, prepending an auto-generated header, and writing the expanded content to agent-specific paths like .github/copilot-instructions.md and .clinerules.

The sync-agent-rules.sh script in the JCodesMore/ai-website-cloner-template repository regenerates platform-specific instruction files for multiple AI development platforms. Developers maintain a single AGENTS.md file as the source of truth, then run this utility to propagate consistent rules to GitHub Copilot, Cline, Continue, and Amazon Q Developer without manual duplication.

How the Regeneration Process Works

The script executes a five-step pipeline to transform the canonical AGENTS.md into platform-ready formats.

Step 1: Locate the Source File

The script determines the repository root and sets SOURCE=$REPO_ROOT/AGENTS.md. It performs safety checks (lines 23–32) to abort execution if AGENTS.md is missing, preventing the generation of empty or corrupted instruction files.

Step 2: Resolve Imports

The resolve_imports function (lines 33–50) processes AGENTS.md for Claude-style file inclusions. Lines beginning with @ are treated as references to external files; the function replaces each @path with the actual file contents, producing a fully-expanded document stored in RESOLVED_CONTENT.

Step 3: Add the Auto-Generated Header

To prevent manual edits to derived files, the script constructs a standard HEADER variable (lines 55–56) containing an "AUTO-GENERATED" comment. This header is prepended to every output file, signaling that changes should be made in AGENTS.md instead.

Step 4: Write Files with Directory Creation

The write_file helper function (lines 58–65) creates target directories automatically if they don't exist, then writes the header plus the resolved content to the specified destination.

Step 5: Generate Platform-Specific Outputs

The script invokes write_file for each supported platform (lines 69–86), tailoring the output format where necessary:

Running the Regeneration

Execute the script from the repository root to synchronize all agent configurations:

bash scripts/sync-agent-rules.sh

The script outputs status messages indicating successful generation:

Syncing agent rules from AGENTS.md...
  ✓ .github/copilot-instructions.md
  ✓ .clinerules
  ✓ .continue/rules/project.md
  ✓ .amazonq/rules/project.md

Done. Generated files are committed to the repo but sourced from AGENTS.md.
Edit AGENTS.md, then re-run this script to update all agent configs.

Summary

  • sync-agent-rules.sh treats AGENTS.md as the single source of truth for AI agent instructions.
  • The resolve_imports function expands @file references to inline external content.
  • An auto-generated header is prepended to every output file to prevent manual edits.
  • The script generates configuration files for GitHub Copilot, Cline/Roo Code, Continue, and Amazon Q Developer.
  • Run bash scripts/sync-agent-rules.sh after editing AGENTS.md to synchronize all platforms.

Frequently Asked Questions

What happens if AGENTS.md is missing?

The script aborts immediately. Lines 23–32 contain safety checks that verify the existence of AGENTS.md before proceeding, ensuring the script never generates empty instruction files.

Can I add support for a new AI agent?

Yes. Add a new write_file call in the script (around lines 69–86) specifying the target path and any required formatting. The function handles directory creation automatically, so you only need to define the destination and content formatting.

Why does the Continue output include YAML front-matter?

The Continue platform requires specific metadata to recognize project rules. According to lines 75–81 in sync-agent-rules.sh, the script prepends a YAML block to .continue/rules/project.md before adding the resolved AGENTS.md content, while other platforms receive the raw markdown directly.

Where should I make edits to the agent rules?

Always edit AGENTS.md directly. The generated files in .github/copilot-instructions.md, .clinerules, and other locations are overwritten every time the script runs. The auto-generated header in these files explicitly warns against manual modifications.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →