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

> Discover how sync-agent-rules.sh regenerates AI instruction files. This script ensures consistency by reading AGENTS.md and writing platform-specific outputs.

- Repository: [JCodesMore/ai-website-cloner-template](https://github.com/JCodesMore/ai-website-cloner-template)
- Tags: how-to-guide
- Published: 2026-07-07

---

**The [`sync-agent-rules.sh`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/sync-agent-rules.sh) script maintains consistency across AI agent configurations by reading [`AGENTS.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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:

```bash
SOURCE=$REPO_ROOT/AGENTS.md

```

Safety checks (lines 23-32) abort execution immediately if [`AGENTS.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/AGENTS.md) contains lines beginning with `@`, the script treats these as import directives:

- `@path/to/file.md` is 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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.continue/rules/project.md). The script prepends YAML front-matter (lines 75-81) before the resolved content to match Continue's configuration schema:

```yaml

# Auto-generated from AGENTS.md

name: Project Rules
description: Generated project-specific instructions

```

### Amazon Q Developer

Stores instructions at [`.amazonq/rules/project.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/.amazonq/rules/project.md) as a direct copy of `RESOLVED_CONTENT`.

## Running the Regeneration Script

Execute the utility from the repository root:

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

```

The script outputs confirmation for each generated file:

```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

- **Single source of truth**: All agent instructions originate from [`AGENTS.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/AGENTS.md) in the repository root.
- **Import resolution**: The `resolve_imports` function expands `@file` references 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.md`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/AGENTS.md) exists before processing begins.
- **Automation**: Running `bash scripts/sync-agent-rules.sh` updates 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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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`](https://github.com/JCodesMore/ai-website-cloner-template/blob/main/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.