How sync-agent-rules.sh Regenerates Platform-Specific Instruction Files for AI Agents
The sync-agent-rules.sh script maintains consistency across AI agent configurations by reading AGENTS.md, resolving file imports, and writing standardized instruction files to platform-specific locations.
In the JCodesMore/ai-website-cloner-template repository, managing AI agent instructions across multiple development platforms is automated through a single source of truth. The sync-agent-rules.sh utility ensures that changes to central agent rules propagate instantly to GitHub Copilot, Cline, Continue, and Amazon Q Developer without manual file duplication.
Locating the Source Configuration
The script determines the repository root and defines the canonical configuration path:
SOURCE=$REPO_ROOT/AGENTS.md
Safety checks (lines 23-32) abort execution immediately if AGENTS.md is missing, preventing incomplete regeneration of instruction files.
Resolving File Imports
The resolve_imports function (lines 33-50) handles Claude-style file includes. When AGENTS.md contains lines beginning with @, the script treats these as import directives:
@path/to/file.mdis replaced with the actual file contents- The fully expanded document is stored in
RESOLVED_CONTENT
This allows you to modularize agent rules across multiple files while maintaining a single compiled output.
Generating the Auto-Generated Header
Before writing outputs, the script constructs a standard header (lines 55-56) that marks files as derived from AGENTS.md. This prevents developers from editing generated files directly, ensuring all changes flow through the source document.
Writing Platform-Specific Files
The write_file helper function (lines 58-65) creates target directories recursively using mkdir -p if needed, then writes the header plus resolved content to each destination.
GitHub Copilot Chat
Outputs to .github/copilot-instructions.md as a direct copy of RESOLVED_CONTENT.
Cline / Roo Code
Receives the rules at .clinerules with identical content to the source document.
Continue
Requires special formatting at .continue/rules/project.md. The script prepends YAML front-matter (lines 75-81) before the resolved content to match Continue's configuration schema:
# Auto-generated from AGENTS.md
name: Project Rules
description: Generated project-specific instructions
Amazon Q Developer
Stores instructions at .amazonq/rules/project.md as a direct copy of RESOLVED_CONTENT.
Running the Regeneration Script
Execute the utility from the repository root:
bash scripts/sync-agent-rules.sh
The script outputs confirmation for each generated file:
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
- Single source of truth: All agent instructions originate from
AGENTS.mdin the repository root. - Import resolution: The
resolve_importsfunction expands@filereferences to create a complete rule set. - Multi-platform support: The script generates configuration files for GitHub Copilot, Cline, Continue, and Amazon Q Developer.
- Safety checks: Built-in validation ensures
AGENTS.mdexists before processing begins. - Automation: Running
bash scripts/sync-agent-rules.shupdates all platform-specific files simultaneously.
Frequently Asked Questions
What happens if AGENTS.md references a file that doesn't exist?
The resolve_imports function expects valid @path references within AGENTS.md. If a referenced file is missing, the script fails during the import resolution phase. Always verify that imported files exist at the specified paths before running the regeneration script.
Can I modify the generated instruction files directly?
No. The script prepends an "AUTO-GENERATED" comment header (lines 55-56) to warn against direct edits. Changes should be made to AGENTS.md or the imported files, then the script rerun to regenerate all platform-specific instruction files consistently.
How do I add support for a new AI agent?
Extend scripts/sync-agent-rules.sh by adding another write_file call (following the pattern in lines 69-86) pointing to your desired configuration file path. The script will automatically include the resolved content and auto-generated header in the new location.
Does the script handle nested directory structures?
Yes. The write_file function uses mkdir -p to create parent directories recursively before writing files. This ensures paths like .continue/rules/ are created automatically even if they did not exist previously.
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 →