You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Name a Partial CLAUDE.md Write Correctly and Stop Re-Backing Up a Refused File #2426
The host-safety installer renders ~/.claude/CLAUDE.md first and treats the real write as its own check. Two smaller gaps remain after #2423's follow-up fix:
A partial write is reported as nothing installed.write_bytes truncates the file before writing. When the write fails partway, for example on a full disk or a file-size limit, the refusal still says "Nothing was installed" and suggests a permissions remedy. The file is in fact left truncated, so new sessions load a partial CLAUDE.md until the next run.
A re-run recovers it. Its first step backs up the truncated file, and that backup is useless.
An atomic temp-file-and-replace write would close this, but it would replace a dotfiles symlink with a plain file. The fix needs to write through a link, or at least name the failure correctly.
Each refused re-run adds another backup. With a read-only CLAUDE.md holding a hand edit, every run writes a timestamped .bak and then fails at the write. The backups pile up. Taking the backup only once the write is known to be possible would stop that.
Shape that reproduces it
Partial write: set a 4 KiB file-size limit, give a stamp-matching CLAUDE.md larger than that, and run the installer. The run refuses with "Nothing was installed", and the file is left at 4096 bytes.
Backups piling up: run chmod 444 on a hand-edited CLAUDE.md, then run the installer twice. Both runs are refused, and two .bak files are left behind.
Found by the local strict review of the CLAUDE.md fix branch for #2425. These are low severity: no hand-written content is lost in either case.
A third gap of the same kind: a FIFO at ~/.claude/settings.json or ~/.claude/agent-safety-stamp.json hangs both the install and --report. The install reads and writes settings.json and the stamp, and the report reads both, all without a regular-file check. The stamp write runs last, so it leaves a half-finished install with no stamp. The local instruction file is now read through read_regular_file() in install.py, which opens non-blocking and checks the open descriptor. That helper is the shape to reuse for these reads. Found by the local strict review of the local-file FIFO fix for #2425; these reads predate that change.
Windows limit, unverified on a native host: on Windows, os.lstat on a path whose parent component is a regular file is expected to raise FileNotFoundError (ERROR_PATH_NOT_FOUND), not NotADirectoryError. So #2429's refusal of such a local instruction path is POSIX-only, and Windows still reads it as absent. To confirm on Windows: python -c "import os,pathlib; p=pathlib.Path(os.environ['TEMP'])/'f'; p.write_text(''); os.lstat(p/'x')". A fix that works on both would check each ancestor after a FileNotFoundError.
One more reader of the same kind: read_claude_md() in host-setup/agent-safety/claude/install.py checks is_file() and then calls read_text(), two separate path lookups. A CLAUDE.md swapped for a FIFO between them blocks the read, which needs a concurrent process to replace the file during a run. Moving it, the settings.json reads and the stamp reads onto read_regular_file() closes all of them at once. Raised by Copilot on #2425.
Done, shipped in 2.0.853 through #2455 and promotion #2456. The native Windows check passed against main:
On Windows, os.lstat on a path whose parent is a regular file raises FileNotFoundError (WinError 3), as expected. The ancestor walk in read_local_instructions is what refuses that case there.
test_install.py run natively with the eight cases that exercise this change without the hook self-test: the ancestor walk (file parent refused, missing directory still absent), the directory fallback in read_regular_file (a CLAUDE.md directory and a local-path directory), and the close and truncate paths of write_regular_file. All eight pass.
The full native suite cannot run on Windows yet, because the guard hook self-test fails there and every install stops at it. That is unrelated to this change and is tracked as #2458. The pre-existing partial-file state the local review found is #2454.
Activity
Render CLAUDE.md First and Let the Real Write Be the Check (#2427)
ptr727 commentedon Oct 6, 2026
A third gap of the same kind: a FIFO at
~/.claude/settings.jsonor~/.claude/agent-safety-stamp.jsonhangs both the install and--report. The install reads and writes settings.json and the stamp, and the report reads both, all without a regular-file check. The stamp write runs last, so it leaves a half-finished install with no stamp. The local instruction file is now read throughread_regular_file()ininstall.py, which opens non-blocking and checks the open descriptor. That helper is the shape to reuse for these reads. Found by the local strict review of the local-file FIFO fix for #2425; these reads predate that change.Read the Local Instruction File Only When It Is a Regular File (#2428)
ptr727 commentedon Oct 6, 2026
Windows limit, unverified on a native host: on Windows,
os.lstaton a path whose parent component is a regular file is expected to raiseFileNotFoundError(ERROR_PATH_NOT_FOUND), notNotADirectoryError. So #2429's refusal of such a local instruction path is POSIX-only, and Windows still reads it as absent. To confirm on Windows:python -c "import os,pathlib; p=pathlib.Path(os.environ['TEMP'])/'f'; p.write_text(''); os.lstat(p/'x')". A fix that works on both would check each ancestor after aFileNotFoundError.ptr727 commentedon Oct 6, 2026
One more reader of the same kind:
read_claude_md()inhost-setup/agent-safety/claude/install.pychecksis_file()and then callsread_text(), two separate path lookups. ACLAUDE.mdswapped for a FIFO between them blocks the read, which needs a concurrent process to replace the file during a run. Moving it, thesettings.jsonreads and the stamp reads ontoread_regular_file()closes all of them at once. Raised by Copilot on #2425.Read and Write Every Installer File Through One Regular-File Primitive (
Promote develop to main: Read and Write Every Installer File Through …
ptr727 commentedon Oct 7, 2026
Done, shipped in 2.0.853 through #2455 and promotion #2456. The native Windows check passed against
main:os.lstaton a path whose parent is a regular file raisesFileNotFoundError(WinError 3), as expected. The ancestor walk inread_local_instructionsis what refuses that case there.test_install.pyrun natively with the eight cases that exercise this change without the hook self-test: the ancestor walk (file parent refused, missing directory still absent), the directory fallback inread_regular_file(aCLAUDE.mddirectory and a local-path directory), and the close and truncate paths ofwrite_regular_file. All eight pass.The full native suite cannot run on Windows yet, because the guard hook self-test fails there and every install stops at it. That is unrelated to this change and is tracked as #2458. The pre-existing partial-file state the local review found is #2454.