Skip to content

fix(installer): stop swapping symlinked config files for detached copies (shared AGENTS.md setups) - #1503

Open
meganemura wants to merge 1 commit into
colbymchenry:mainfrom
meganemura:fix/installer-stop-swapping-symlinked-configs
Open

fix(installer): stop swapping symlinked config files for detached copies (shared AGENTS.md setups)#1503
meganemura wants to merge 1 commit into
colbymchenry:mainfrom
meganemura:fix/installer-stop-swapping-symlinked-configs

Conversation

@meganemura

@meganemura meganemura commented Aug 3, 2026

Copy link
Copy Markdown

Summary

codegraph install breaks symlinked config files. The installer writes a temp file and then renames it onto the destination. But rename replaces the symlink itself, not the file it points to. So the symlink turns into a plain copy.

This hurts setups that share one AGENTS.md across agents:

ln -sf ~/AGENTS.md ~/.claude/CLAUDE.md
ln -sf ~/AGENTS.md ~/.codex/AGENTS.md

After install, the link is gone, and edits to the shared file no longer reach the agent. Dotfiles-managed configs break the same way.

The fix: resolve the symlink first, then write to the real file. The write stays atomic (temp file + rename in the target's own directory). All installer writes go through this one helper, so JSON, TOML, and markdown files are all covered. If several agents link to the same shared file, the block is written only once; the other installs report unchanged.

Relationship to #433

@0x1306a94 found this problem first and proposed the same core fix in #433 — full credit to them. This PR differs in three ways:

Test plan

  • npx vitest run __tests__/installer-targets.test.ts — all pass (6 new symlink tests), macOS
  • tsc --noEmit clean

🤖 Generated with Claude Code

…ies (shared AGENTS.md setups)

atomicWriteFileSync landed its temp file on the destination via
renameSync, which replaces a symlink itself rather than its target.
Setups that symlink one shared instructions file into each agent's
expected location (~/.claude/CLAUDE.md -> ~/AGENTS.md,
~/.codex/AGENTS.md -> ~/AGENTS.md, ...), and dotfiles-managed configs,
silently lost the link: the file became a detached regular-file copy,
and later edits to the shared source never reached the file the agent
actually reads.

Resolve the symlink chain first (manually — realpathSync throws on
dangling links, and creating a dangling link's target must keep
working) and run the temp-file-plus-rename against the real target,
keeping the write atomic on the target's own filesystem. When several
selected agents point at the same shared file, the marker-based upsert
dedupes across them: the guidance block is written exactly once.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@meganemura
meganemura force-pushed the fix/installer-stop-swapping-symlinked-configs branch from 044b342 to eff3500 Compare August 8, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant