Skip to main content

Sync CLAUDE.md with AGENTS.md for AI coding agents

Project description

sync-claude-md

CI Go Report Card

English | 日本語 | 한국어

Keeps CLAUDE.md in sync with AGENTS.md for multi-agent development workflows.

Why

AI coding agents disagree on which instruction file to read — Claude Code wants CLAUDE.md, most others (GitHub Copilot, Cursor, etc.) want AGENTS.md. Maintaining both by hand is tedious and error-prone.

sync-claude-md keeps them in sync automatically: for every AGENTS.md it finds, it ensures a sibling CLAUDE.md containing an @AGENTS.md reference exists — creating the file, or adding the reference to an existing one while preserving its content — and removes the reference (deleting the file if it's now empty) once AGENTS.md is gone. Pass --gemini to do the same for GEMINI.md (@./AGENTS.md).

Works as a pre-commit hook or standalone CLI.

Installation

via npm (Node.js projects)

npm install --save-dev sync-claude-md
npx sync-claude-md --help

via GitHub Releases

Download the binary for your platform from Releases.

via Go

go install github.com/lohn/sync-claude-md/cmd/sync-claude-md@latest

Usage

CLI

sync-claude-md sync           # sync staged AGENTS.md files (default), verified against the git index
sync-claude-md sync --all     # scan the entire repository instead
sync-claude-md sync --stage   # also stage the synced files (succeeds in one pass)
sync-claude-md check --all    # dry-run: report drift without writing
sync-claude-md sync --gemini  # also sync GEMINI.md (@./AGENTS.md)

Running sync-claude-md with no command prints help. With no file arguments, only staged AGENTS.md files are processed — the intended git-hook use. Outside a git repository, "staged" is meaningless, so the default falls back to a full scan too.

Flags:

Flag Effect
--all Scan the entire repository instead of only staged files
--stage, -S git add the synced target files (inside a git repository only)
--force, -f Overwrite targets with unstaged changes, or write at all outside a git repository
--gemini Also sync GEMINI.md (@./AGENTS.md) in each directory
--no-claude Skip CLAUDE.md (use with --gemini to sync GEMINI.md only)
--no-ignore Also process target files that are git-ignored (skipped by default)
--fail-on-change Exit 1 if any file was written, even after a successful sync/stage

You can also pass specific files instead of relying on --all/staged discovery, e.g. sync-claude-md sync path/to/AGENTS.md another/AGENTS.md.

sync enforces three safety guarantees:

  • Destroy protection — refuses to overwrite a target file that has unstaged changes, which would discard your work; exits 1 without writing unless --force is passed.
  • No writes outside a git repository — there's no git history to recover from, so it refuses to write anything, even a brand-new file; exits 1 unless --force is passed.
  • Index sync (inside a git repository only) — the @AGENTS.md reference must be staged so the sync actually lands in the next commit. If it isn't (including a freshly created but untracked CLAUDE.md), it exits 1 and asks you to git add the file. Pass --stage to stage the synced files automatically and succeed in a single pass.

Note: --stage adds the whole target file, so it does not play well with partial staging (git add -p). Omit --stage and stage manually if you rely on partially staged commits.

Exit codes: 0 when there's nothing left to do (everything up to date and, inside a git repository, staged); 1 on a guarantee violation above, on drift detected by check, or — with --fail-on-change — on any write at all.

Pre-commit / prek

Add to .pre-commit-config.yaml:

repos:
  - repo: https://github.com/lohn/sync-claude-md
    rev: v1.0.0
    hooks:
      - id: sync-claude-md

The hook runs sync-claude-md sync and, by default, fails the commit when a synced file is not staged so you re-stage and commit again. To stage the synced files automatically instead, add args: ['--stage']:

repos:
  - repo: https://github.com/lohn/sync-claude-md
    rev: v1.0.0
    hooks:
      - id: sync-claude-md
        args: ["--stage"]

Or use repo: local with a pre-installed binary:

repos:
  - repo: local
    hooks:
      - id: sync-claude-md
        name: Sync CLAUDE.md
        entry: sync-claude-md sync
        language: system
        always_run: true
        pass_filenames: false

Husky

See docs/husky.md for detailed setup instructions.

Quick example for .husky/pre-commit:

sync-claude-md sync --stage

How It Works

For each AGENTS.md found, a CLAUDE.md is created in the same directory containing just:

@AGENTS.md

The @path/to/file syntax resolves relative to the CLAUDE.md file itself (not CWD), so @AGENTS.md always points to the correct file. With --gemini, a GEMINI.md is created the same way using Gemini's import syntax @./AGENTS.md.

It's idempotent and safe:

  • Adds the reference (at the top) only if it isn't already present anywhere in the file, and preserves all existing content
  • Removes the reference automatically when AGENTS.md is deleted, and deletes the file if that leaves it empty
  • Refuses to read a target file larger than 10 MiB, capping how much it will ever load into memory at once — no effect on normal-sized files

License

MIT © lohn

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sync_claude_md-1.0.0-py3-none-win_arm64.whl (866.8 kB view details)

Uploaded Python 3Windows ARM64

sync_claude_md-1.0.0-py3-none-win_amd64.whl (965.0 kB view details)

Uploaded Python 3Windows x86-64

sync_claude_md-1.0.0-py3-none-manylinux_2_17_x86_64.whl (921.8 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

sync_claude_md-1.0.0-py3-none-manylinux_2_17_aarch64.whl (837.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

sync_claude_md-1.0.0-py3-none-macosx_11_0_arm64.whl (832.8 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

sync_claude_md-1.0.0-py3-none-macosx_10_9_x86_64.whl (897.5 kB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file sync_claude_md-1.0.0-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for sync_claude_md-1.0.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 add7cf4cc07275ef73feaf0bb3c3122e1eab755c2143f9b23b9f5e698c919a90
MD5 c1b9834176c9d4ff65a729ff4041d1cd
BLAKE2b-256 5485b5fb7d3bb99ae1bebe3f790672babf828a07736fdfa29e05a81a0b23b391

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_claude_md-1.0.0-py3-none-win_arm64.whl:

Publisher: release.yaml on lohn/sync-claude-md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sync_claude_md-1.0.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for sync_claude_md-1.0.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 33cb2513ef20b6463559b909cc705cc36cbbcfdff0be32887b5812e0fa217ca7
MD5 b3f2c939d00693ea1232a42587f44e40
BLAKE2b-256 4ec594a46c0ed3dba6045c242bf02b04c1963b82c17a3a9c6cb250c2e2548b3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_claude_md-1.0.0-py3-none-win_amd64.whl:

Publisher: release.yaml on lohn/sync-claude-md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sync_claude_md-1.0.0-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for sync_claude_md-1.0.0-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 b88686cfcddd04357bfd1c0a3f83e6c8b38a1eb0db990d3800679281380a79a5
MD5 0472631613f41fdf7785c77128d274a5
BLAKE2b-256 671b6349d8adcc4244a46c4d51680a572888b06f6500378eec191bfabb5783ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_claude_md-1.0.0-py3-none-manylinux_2_17_x86_64.whl:

Publisher: release.yaml on lohn/sync-claude-md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sync_claude_md-1.0.0-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for sync_claude_md-1.0.0-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 af0fd6970247c81ebb31667080d3311b5763e7689f8aa151526591391510e8b8
MD5 07660f23b1614a26f6f0bf334ba5ba12
BLAKE2b-256 3aa6c65f2a95d5bbb24365341e6d99e1a463179a2db52e7377e277e19e5de283

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_claude_md-1.0.0-py3-none-manylinux_2_17_aarch64.whl:

Publisher: release.yaml on lohn/sync-claude-md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sync_claude_md-1.0.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sync_claude_md-1.0.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef64b292ff71a0e20db0febaf7f925818d143f4744d1296e9336795f217e7072
MD5 083b0bf7de9e8f058614ccb55e315ab6
BLAKE2b-256 ab7073845cfd0bf84c87db246636ad0099bb36fe918a9662cbc5db799a77f98e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_claude_md-1.0.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yaml on lohn/sync-claude-md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sync_claude_md-1.0.0-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for sync_claude_md-1.0.0-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 934e306d8c2535bc567c3267d9edcf3ff3225d6630d98dfe45847f1b91da79a6
MD5 a6f2285907c81a60d1f875df061a01f2
BLAKE2b-256 10f17ab7d40a0bc94c59542f1479eb8ac9a465f1acbe35373efa9bfabcf112df

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_claude_md-1.0.0-py3-none-macosx_10_9_x86_64.whl:

Publisher: release.yaml on lohn/sync-claude-md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page