How sync-agent-rules.sh Regenerates Platform-Specific Instruction Files
The sync-agent-rules.sh script reads AGENTS.md, resolves Claude-style @file imports, and writes the expanded content to multiple agent-specific configuration files across your repository.
In the JCodesMore/ai-website-cloner-template repository, maintaining consistent AI-agent instructions across different platforms is handled by scripts/sync-agent-rules.sh. This Bash utility eliminates manual duplication by treating AGENTS.md as the single source of truth and automatically regenerating platform-specific instruction files for GitHub Copilot, Cline, Continue, and Amazon Q Developer.
The Regeneration Pipeline
The script operates through a four-phase pipeline that transforms the canonical AGENTS.md into various agent-readable formats.
1. Locating the Source File
The script determines the repository root and sets SOURCE=$REPO_ROOT/AGENTS.md as the canonical instruction file. Safety checks (lines 23-32) abort execution if this source file is missing, preventing incomplete or broken updates.
2. Resolving Claude-Style Imports
Between lines 33-50, the resolve_imports function processes AGENTS.md for lines beginning with @. Each @path reference is replaced with the actual content of the referenced file, producing a fully expanded document stored in RESOLVED_CONTENT. This allows modular rule organization while maintaining a single deployable configuration.
3. Generating the Auto-Generated Header
Lines 55-56 define a standard HEADER variable containing an "AUTO-GENERATED" comment. This header is prepended to every output file, warning developers that the file is derived from AGENTS.md and should not be edited directly.
4. Writing Platform-Specific Files
The write_file helper (lines 58-65) creates target directories if needed and writes the header plus resolved content. Lines 69-86 invoke this helper to generate four distinct configuration files.
Platform-Specific Output Locations
The script generates the following platform-specific instruction files:
- GitHub Copilot Chat: Writes to
.github/copilot-instructions.mdas a direct copy ofRESOLVED_CONTENT. - Cline / Roo Code: Outputs to
.clineruleswith identical content. - Continue: Creates
.continue/rules/project.mdwith YAML front-matter prepended (lines 75-81) followed by the resolved content. - Amazon Q Developer: Generates
.amazonq/rules/project.mdas a direct copy.
Running the Regeneration
Execute the script from the repository root to regenerate all platform-specific instruction files:
bash scripts/sync-agent-rules.sh
Expected output:
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
scripts/sync-agent-rules.shacts as the central orchestrator for AI-agent configuration, reading fromAGENTS.mdand propagating changes to multiple platforms.- The
resolve_importsfunction (lines 33-50) handles modular file includes using the@pathsyntax before generating final outputs. - Four platforms receive automatic updates: GitHub Copilot (
.github/copilot-instructions.md), Cline (.clinerules), Continue (.continue/rules/project.mdwith YAML front-matter), and Amazon Q (.amazonq/rules/project.md). - Each generated file contains an AUTO-GENERATED header (defined at lines 55-56) preventing manual edits that would be overwritten.
Frequently Asked Questions
What happens if AGENTS.md is missing when I run the script?
The script performs safety checks at lines 23-32 and aborts immediately if AGENTS.md cannot be found at the repository root. This prevents the generation of empty or corrupted instruction files that would break your AI agent configurations.
Can I modify the generated files directly?
No. The script inserts an explicit "AUTO-GENERATED" warning header into each file to indicate that direct edits will be lost. All changes should be made to AGENTS.md (or files referenced via @ imports) followed by re-running bash scripts/sync-agent-rules.sh.
How do I add support for a new AI agent platform?
Extend the script by adding another write_file call after line 86, specifying your target path and any platform-specific preprocessing (such as the YAML front-matter required by Continue). Follow the existing pattern used for Copilot or Amazon Q if your agent accepts raw markdown.
Why does Continue require special YAML front-matter?
According to lines 75-81 in the source, Continue reads project rules from .continue/rules/project.md but requires a specific YAML metadata block to recognize the file as a rule configuration. The script automatically prepends this block before the resolved content, unlike the direct copies made for other platforms.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →