How sync-agent-rules.sh Regenerates Platform-Specific Instructions in ai-website-cloner-template

The sync-agent-rules.sh script regenerates platform-specific instructions by reading AGENTS.md, resolving @file imports into a single resolved document, and writing the output to agent-specific configuration files across GitHub Copilot, Cline, Continue, and Amazon Q Developer.

The ai-website-cloner-template repository maintains AI agent rules through a centralized workflow that eliminates manual duplication. Instead of editing multiple configuration files separately, developers modify a single source of truth—AGENTS.md—and run the synchronization script to regenerate platform-specific instructions automatically.

The Single Source of Truth: AGENTS.md

At the repository root, AGENTS.md serves as the canonical instruction file for all AI agents. This file supports Claude-style file imports using the @path syntax, allowing you to modularize rules across multiple files while keeping the master document clean. The script treats any line beginning with @ as an import directive that must be resolved before generating the final outputs.

Step-by-Step Regeneration Process

The script executes a predictable pipeline defined in scripts/sync-agent-rules.sh to transform the source file into platform-ready configurations.

Locating and Validating the Source

The script first determines the repository root and sets SOURCE=$REPO_ROOT/AGENTS.md. According to lines 23–32 of the source code, safety checks immediately abort execution if AGENTS.md is missing, preventing the generation of empty or corrupted rule files.

Resolving File Imports

The resolve_imports function (lines 33–50) processes the source document to expand all @file references. When the script encounters a line starting with @, it replaces that line with the actual contents of the referenced file, producing a fully flattened document stored in the RESOLVED_CONTENT variable. This ensures that modular rule definitions are inlined before distribution to individual agent configurations.

Adding the Auto-Generated Header

Before writing any files, the script prepends a standard warning comment to prevent manual edits. Lines 55–56 define a HEADER variable containing an "AUTO-GENERATED" notice that is affixed to every output file. This header clearly indicates that the file is derived from AGENTS.md and should not be edited directly.

Writing Platform-Specific Files

The write_file function (lines 58–65) handles the actual file creation. It accepts a target path and content, creates the necessary directory structure if missing, and writes the header plus resolved content to the destination. This utility is called for each supported platform to ensure consistent file formatting across different directory depths.

Platform-Specific Output Formats

The script generates distinct output files for each AI agent platform, adapting the format where necessary while maintaining identical rule content:

  • GitHub Copilot Chat receives a direct copy of RESOLVED_CONTENT written to .github/copilot-instructions.md. This file lives in the GitHub-specific configuration directory and requires no special formatting.

  • Cline / Roo Code also receives a direct copy of the resolved content, written to .clinerules at the repository root. This flat file structure matches the expectations of the Cline extension.

  • Continue requires special formatting. The script writes to .continue/rules/project.md but prepends a YAML front-matter block (lines 75–81) before appending RESOLVED_CONTENT. This metadata block ensures the Continue extension recognizes the file as a project-specific rule set.

  • Amazon Q Developer receives a direct copy written to .amazonq/rules/project.md, following the directory structure expected by the Amazon Q toolkit.

Lines 69–86 of the script contain the sequential write_file calls that generate these four outputs, while lines 87–88 provide the final status messages confirming successful synchronization.

Running the Regeneration

To propagate changes from AGENTS.md to all agent configurations, execute the script from the repository root:

bash scripts/sync-agent-rules.sh

The script outputs a completion status for each platform:


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.sh automates the distribution of AI agent rules from a single source file to multiple platform-specific locations.
  • AGENTS.md supports modular organization through @file imports, which the resolve_imports function expands during processing.
  • Safety checks (lines 23–32) prevent execution if the source file is missing.
  • Four platforms are supported: GitHub Copilot, Cline/Roo Code, Continue, and Amazon Q Developer.
  • Continue requires special YAML front-matter prepended to the content, while other agents receive direct copies.
  • All generated files contain an "AUTO-GENERATED" header (lines 55–56) warning against manual edits.

Frequently Asked Questions

What is the purpose of the @file syntax in AGENTS.md?

The @file syntax implements Claude-style file includes that allow you to split agent rules across multiple files. During execution, the resolve_imports function (lines 33–50) replaces each @path line with the actual contents of the referenced file, creating a single resolved document before generating platform-specific outputs.

Why does the Continue agent require YAML front-matter while others do not?

Continue expects project rules to include a metadata block at the top of the file. According to lines 75–81 of the script, the write_file call for Continue prepends a YAML front-matter block to .continue/rules/project.md before adding the resolved content from AGENTS.md. The other agents (Copilot, Cline, Amazon Q) accept raw markdown instructions without metadata headers.

What happens if AGENTS.md is missing when I run the script?

The script implements safety checks at lines 23–32 that verify the existence of AGENTS.md before proceeding. If the source file is missing, the script aborts immediately with an error message, preventing the accidental generation of empty rule files that could confuse AI agents.

Can I add support for a new AI agent platform?

Yes. To extend the script for an additional agent, add a new write_file call following the pattern established in lines 69–86. Specify the target path (e.g., .newagent/rules.md) and determine whether the agent requires special formatting like YAML front-matter or can accept a direct copy of RESOLVED_CONTENT.

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 →