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

> Discover how sync-agent-rules.sh regenerates platform-specific instruction files by reading AGENTS.md resolving imports and adding a header for custom agent paths.

- Repository: [JCodesMore/ai-website-cloner-template](https://github.com/JCodesMore/ai-website-cloner-template)
- Tags: deep-dive
- Published: 2026-07-03

---

**[`sync-agent-rules.sh`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/sync-agent-rules.sh) regenerates platform-specific instruction files by reading [`AGENTS.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.github/copilot-instructions.md) and `.clinerules`.**

The [`sync-agent-rules.sh`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/sync-agent-rules.sh) script in the [JCodesMore/ai-website-cloner-template](https://github.com/JCodesMore/ai-website-cloner-template) repository regenerates platform-specific instruction files for multiple AI development platforms. Developers maintain a single [`AGENTS.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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:

- **GitHub Copilot Chat**: Writes directly to [`.github/copilot-instructions.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.github/copilot-instructions.md) (lines 69–72) with a direct copy of the resolved content.
- **Cline / Roo Code**: Writes directly to `.clinerules` (lines 73–74) with identical content.
- **Continue**: Prepends YAML front-matter (lines 75–81) before writing to [`.continue/rules/project.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.continue/rules/project.md).
- **Amazon Q Developer**: Writes directly to [`.amazonq/rules/project.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.amazonq/rules/project.md) (lines 82–86).

## Running the Regeneration

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

```bash
bash scripts/sync-agent-rules.sh

```

The script outputs status messages indicating successful generation:

```text
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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/sync-agent-rules.sh)** treats [`AGENTS.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/sync-agent-rules.sh), the script prepends a YAML block to [`.continue/rules/project.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.continue/rules/project.md) before adding the resolved [`AGENTS.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/AGENTS.md) content, while other platforms receive the raw markdown directly.

### Where should I make edits to the agent rules?

Always edit **[`AGENTS.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/AGENTS.md)** directly. The generated files in [`.github/copilot-instructions.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.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.