Skip to content

rtk init rewrites existing files with mode 0600, whatever mode they had #4631

Done

Description

@KuSh

What happens

atomic_write in src/hooks/init/mod.rs writes the new content to a NamedTempFile in the same directory and renames it over the target. NamedTempFile creates the file with mode 0600, and nothing copies the original file's mode onto it, so every file rtk init rewrites in place loses its group and other permission bits.

$ chmod 644 .agents/rules/antigravity-rtk-rules.md     # user content + an appended RTK block
$ rtk init --agent antigravity                          # with #4335, strips RTK's block
$ stat -c %a .agents/rules/antigravity-rtk-rules.md
600

(Reproduced on #4335's head merged onto develop 7bff768.) Every caller of atomic_write on an existing file behaves the same way: settings.json patches, CLAUDE.md / AGENTS.md patches and the other instruction files. In a checkout shared between users, or one read by an agent running under another uid, the file becomes unreadable to them after rtk init or rtk init --uninstall.

What a fix has to do

  • When the target already exists, the replacement keeps its mode (on Unix, copy the original permissions onto the temp file before the rename).
  • A newly created file keeps getting the mode it gets today.
  • A test that pins it: write a 0644 file, rewrite it through atomic_write, and check the mode is still 0644 (cfg(unix)).

#4335 newly routes a user-owned rules file through atomic_write and waits on this fix before it merges.

Activity

  1. rtk-wshm-sync-bot commented on Oct 17, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 95%

    Summary

    atomic_write in src/hooks/init/mod.rs drops existing file permissions to 0600 instead of preserving original mode; fix and add a cfg(unix) regression test.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/hooks/init/mod.rs

    Suggested Actions

    1. Fix atomic_write to copy the target file's existing permissions onto the temp file before rename (Unix)
    2. Add cfg(unix) test: write 0644 file, rewrite via atomic_write, assert mode stays 0644
    3. Unblock fix(init): migrate legacy Antigravity rules on install and uninstall (#4317) #4335, which routes a user-owned rules file through atomic_write and is waiting on this fix

    Triaged automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliarea:securitybuggood first issuepriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions