Skip to content

feat(generate): warn when an output is written through a symlink - #3949

Merged
dyoshikawa merged 4 commits into
mainfrom
resolve-issue-3945-warn-symlink-writes
Nov 24, 2026
Merged

dyoshikawa merged 4 commits into
mainfrom
resolve-issue-3945-warn-symlink-writes

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements option 3 of #3945: a warning whenever generate writes a file through a symbolic link that stays inside the output root. What gets written is unchanged — no skip and no new option; options 1 and 2 stay open for a maintainer decision.

#3123 made generate refuse links that lead out of the output root and keep writing through in-root ones (dotfiles setups rely on that). As a result, an in-root AGENTS.md -> .claude/CLAUDE.md link let generate --targets codexcli,opencode replace Claude Code's instructions file without any message. Now the run prints:

"<root>/AGENTS.md" is a symbolic link to "<root>/.claude/CLAUDE.md"; files rulesync writes through it land there
  • New warnIfWriteFollowsLink in src/types/feature-processor.ts, next to refusesWriteOutsideRoot. It finds the first symbolic link below the output root on the output path (new firstLinkBelowRoot in src/utils/file.ts, an lstat walk over the segments below the root) and names that link and its real path. An output root that is itself a link does not count.
  • It is called at the point where each writer is about to change a file: FeatureProcessor.writeAiFiles, DirFeatureProcessor.writeAiDirs (every file of a changed directory), and the Hermes / Goose config rewrites, Hermes plugin activation and the Antigravity plugin manifest. It runs before the dry-run branch, so --dry-run / --check warn too.
  • A file whose content is already up to date is neither rewritten nor warned about. Without this, a --global dotfiles setup (~/.claude -> ~/dotfiles/.claude) would get one warning per file on every run.
  • Warnings go through warnOnceWithFallback keyed on the link, so a linked directory is reported once however many files below it change, and a path that several targets write in one run (codexcli and opencode both write AGENTS.md) is reported once.
  • When a file below that link is itself redirected by a further link (for example ~/.codex -> ~/dotfiles/.codex plus ~/dotfiles/.codex/AGENTS.md -> ../.claude/CLAUDE.md), a second warning names that file and its own real path, once per file.
  • The Symlinks section of docs/reference/file-formats.md documents the warning.

Refs #3945

Tests

  • feature-processor.test.ts: the existing in-root-link case now expects the warning. New cases cover the issue's AGENTS.md -> .claude/CLAUDE.md file link, a dry run, an up-to-date file (no warning), two processors writing the same linked file (one warning), and a path with no link (no warning), many files below one linked directory (one warning), an output root that is itself a link (no warning), and a nested link inside a linked directory (a second warning naming the file's real path).
  • dir-feature-processor.test.ts: a skill directory linked inside the root warns for its SKILL.md, and an up-to-date linked directory stays quiet.
  • file.test.ts: firstLinkBelowRoot cases, including a non-ENOENT error (EACCES) being rethrown. hermes-project-plugin-activation.test.ts: a config linked inside the home directory warns.
  • pnpm cicheck passes (17289 tests).

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

Generate already refuses links that lead out of the output root and writes through ones that stay inside it. An in-root link such as AGENTS.md -> .claude/CLAUDE.md therefore let one target silently replace another target's file. Every writer now warns, once per run and path, naming the output path and the real path the content lands in whenever it writes (or, under --dry-run, would write) a file through such a link. What gets written is unchanged.

Refs #3945

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
Key the in-root link warning on the first link below the output root, so a linked directory such as ~/.claude -> ~/dotfiles/.claude is reported once however many files below it a run writes. The warning names the link and its real path. Finding the link is a plain lstat walk over the segments below the root, so an output root that is itself a link does not count and no extra landing walks are needed for files without a link. Also warn from the Antigravity plugin manifest write.

Refs #3945

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
The per-link warning stops at the first link below the output root, so with ~/.codex -> ~/dotfiles/.codex and AGENTS.md -> ../.claude/CLAUDE.md inside it, only ~/.codex was named. When a file's real landing differs from the first link's landing joined with the rest of its path, warn for that file too with its real path. Also pin that errors other than a missing entry propagate from firstLinkBelowRoot.

Refs #3945

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…rn-symlink-writes

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit 698aca3 into main Nov 24, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-3945-warn-symlink-writes branch November 24, 2026 11:00
@dyoshikawa

Copy link
Copy Markdown
Owner Author

@dyoshikawa Thank you!

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