claude-code - 💡(How to fix) Fix [BUG] Bug: File edits cause metadata loss (group, setuid, xattrs, hardlinks)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error Messages/Logs

Code Example



---

echo "test" > foo.txt
chown user:docker foo.txt        # set group to docker
# Edit foo.txt via Claude Code
stat foo.txt                     # Gid reverts to user's primary group

---

echo "test" > foo.py
chmod 4755 foo.py                # -rwsr-xr-x
# Edit foo.py via Claude Code
stat foo.py                      # → 0755 -rwxr-xr-x (setuid gone)

---

echo "test" > foo.txt
setfattr -n user.custom -v "hello" foo.txt
# Edit foo.txt via Claude Code
getfattr -d foo.txt              #  (empty)

---

echo "test" > foo.txt
ln foo.txt bar.txt               # both point to the same inode
# Edit foo.txt via Claude Code
cat bar.txt                      # → still shows old content
stat foo.txt                     # new inode
stat bar.txt                     # old inode — link is broken
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Claude Code's Edit and Write tools replace files via delete+create rather than in-place modification. The inode always changes after an edit. While basic rwx permission bits are recovered, several important pieces of file metadata are silently lost: group ownership, setuid/setgid/sticky bits, extended attributes, and hardlinks.

What Should Happen?

File edits should preserve all metadata. The standard approach is an atomic write-to-tempfile + rename(tmpfile, path), followed by copying metadata from the original:

  • fchown to restore uid + gid
  • fchmod to restore the full mode including setuid/setgid/sticky bits
  • copy xattrs (iterate with listxattr / setxattr)

Alternatively, open-and-truncate (open(path, O_WRONLY|O_TRUNC)) preserves inode identity (and thus hardlinks and xattrs), but sacrifices atomicity.

Error Messages/Logs

Steps to Reproduce

1. Group ownership is reset

echo "test" > foo.txt
chown user:docker foo.txt        # set group to docker
# Edit foo.txt via Claude Code
stat foo.txt                     # Gid reverts to user's primary group

Before: Gid: ( 144/ docker)
After: Gid: ( 1001/ martin) ← silently reset


2. setuid/setgid/sticky bits are stripped

echo "test" > foo.py
chmod 4755 foo.py                # -rwsr-xr-x
# Edit foo.py via Claude Code
stat foo.py                      # → 0755 -rwxr-xr-x (setuid gone)

Before: Access: (4755/-rwsr-xr-x)
After: Access: (0755/-rwxr-xr-x) ← setuid bit silently stripped


3. Extended attributes (xattrs) are lost

echo "test" > foo.txt
setfattr -n user.custom -v "hello" foo.txt
# Edit foo.txt via Claude Code
getfattr -d foo.txt              # → (empty)

Before: user.custom="hello"
After: (no xattrs) ← xattr silently deleted


4. Hardlinks are broken

echo "test" > foo.txt
ln foo.txt bar.txt               # both point to the same inode
# Edit foo.txt via Claude Code
cat bar.txt                      # → still shows old content
stat foo.txt                     # new inode
stat bar.txt                     # old inode — link is broken

Before: both files share one inode, Links: 2
After: two separate inodes, each with Links: 1 — the hardlink is silently broken and bar.txt diverges

Claude Model

None

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.145

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING