syncai
CLAUDE.md10 starsChanged 7 months agoMITView on GitHub
This file provides guidance to a Coding Agent when working with code in this repository. There is no test suite in this repo (no *_test.go files). Verify changes with make build plus a manual smoke test against a temp working directory: CLI flags: -config, -workdir, -no-watch (one-shot for CI), -self-update, -version, -help. SyncAI is a polling watcher that propagates AI-assistant config files between agents (Cursor, Copilot, Claude Code, Codex). The whole program is a single Go binary; the moving parts…
In this repository2 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
The file
Files
CLAUDE.md
This file provides guidance to a Coding Agent when working with code in this repository.
Build & run
make build—go mod tidythen build tobin/syncai.make run— builds and then runsgo run ./cmd -config syncai.json.make clean— removesbin/.
There is no test suite in this repo (no *_test.go files). Verify changes with make build plus a manual smoke test against a temp working directory:
./bin/syncai -workdir /tmp/syncai-smoke -config /tmp/syncai-smoke/syncai.json -no-watchCLI flags: -config, -workdir, -no-watch (one-shot for CI), -self-update, -version, -help.
Architecture
SyncAI is a polling watcher that propagates AI-assistant config files between agents (Cursor, Copilot, Claude Code, Codex). The whole program is a single Go binary; the moving parts split cleanly along four "sync kinds" defined in internal/model/model.go:
| Kind | Source config field | Source unit | Destination logic |
| context | Agent.Context.Path | single file | verbatim copy |
| ignore | Agent.Ignore.Path | single file | verbatim copy |
| rules | Agent.Rules.Pattern | files matched by glob | content rewritten by per-agent rules generator (frontmatter shape differs between cursor's globs/alwaysApply and copilot's applyTo) |
| skills | Agent.Skills.Pattern | whole directory matched by glob | every file inside the matched dir copied verbatim, preserving the in-skill relative path |
Lifecycle
cmd/main.goloads config, runsinitialSync(dedup keykind|stem|rel, picks the newest mtime per logical file across agents), then enters a ticker loop atcfg.Interval()(default 5s).- Each tick rebuilds the watched-file list via
(config.Agent).Files()and diffs sha256 hashes against the in-memoryfilesState. Changes →(*SyncAI).Sync. Missing entries →(*SyncAI).Delete. Files()uses two distinct collectors:globPattern(file glob, used for rules) andwalkSkillDirs(recursive walk of every matched directory, used for skills). Don't conflate them.
Identify is the routing decision
(*SyncAI).Identify(path) returns (*config.Agent, model.Kind, stem, rel):
stemis the wildcard capture (skill folder name, or rule file's wildcard portion).relis non-empty only for skills — it's the file's path relative to its skill folder.Identifywalks the agents in config order; the first match wins. Rules are checked before skills, so don't configure overlapping patterns.
Pattern matching helpers in internal/syncai/util.go
matchPattern(pattern, path)— for file patterns (rules).*may appear in any path component. Falls back to basename-without-extension as stem when the pattern has no*.matchSkillsPattern(pattern, path)— for directory patterns (skills). The pattern is a prefix of the path; the remainder is the rel.generatePatternPath(pattern, stem)— substitutessteminto every*component. For skills, callers joinrelafterwards ingeneratePath.skillsBaseDir(pattern)— the literal prefix of the pattern before its first wildcard component. Used to bound the empty-dir cleanup walk.
Two sync paths in (*SyncAI).Sync
- Skills →
syncSkill: read source bytes once,util.WriteFilethem to every peer's substituted destination. No frontmatter parsing — skill folders may contain scripts/data that aren't markdown. - Everything else → document-stack path: parse all peers' versions of the logical file, sort with the changed path forced last (so it wins regardless of mtime), pass through
generate()which dispatches to a per-agentRulesGeneratoronly whenkind == KindRules. Context/ignore fall through verbatim.
Deletes and empty-dir pruning
(*SyncAI).Delete only propagates deletions for KindRules and KindSkills (context/ignore deletions are intentionally non-propagating to avoid accidents). After each successful peer-side skill file removal, util.PruneEmptyDirs(dirOf(dst), skillsBaseDir(dstAgent.Skills.Pattern)) walks upward removing empty dirs, stopping at the configured base — so .codex/skills/ survives even when its last skill is deleted.
Atomic file writes
util.WriteFile is the sole writer: temp file in the same dir → fsync → rename → fsync the dir. It returns early if destination bytes already match, which is what prevents ping-pong syncs.
Frontmatter parsing
util.ParseFile extracts YAML frontmatter from markdown. Used by the document-stack path to merge metadata across agents in generator.ExtractRulesMetadata. Non-string YAML values are coerced via cleanYAMLValue; sequences are joined with commas. Skills bypass this entirely.
CI
.github/workflows/syncai.yml runs syncai against the repo's own syncai.json on every push (except main and release/*). It builds from source (make build) — do not reintroduce the cross-repo binary download; it was removed because unauth'd curl to api.github.com from the runner hit IP rate limits and broke the workflow.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

