Skip to content

fix: write settings.json atomically in hooks.Install#260

Merged
claude[bot] merged 1 commit intomainfrom
claude/issue-256-20260228-1411
Feb 28, 2026
Merged

fix: write settings.json atomically in hooks.Install#260
claude[bot] merged 1 commit intomainfrom
claude/issue-256-20260228-1411

Conversation

@claude
Copy link
Contributor

@claude claude bot commented Feb 28, 2026

Summary

Replace the direct os.WriteFile in hooks.Install with an atomic temp-file + os.Rename pattern, consistent with how snapshot.go and activitylog.go already handle writes.

Before:

if err := os.WriteFile(settingsPath, finalJSON, 0600); err != nil {
    return nil, fmt.Errorf("writing settings.json: %w", err)
}

After:

tmp := settingsPath + ".tmp"
if err := os.WriteFile(tmp, finalJSON, 0600); err != nil {
    _ = os.Remove(tmp)
    return nil, fmt.Errorf("writing settings.json: %w", err)
}
if err := os.Rename(tmp, settingsPath); err != nil {
    _ = os.Remove(tmp)
    return nil, fmt.Errorf("writing settings.json: %w", err)
}

A mid-write crash now leaves the original settings.json intact rather than truncating/corrupting the user's entire Claude Code configuration.

Closes #256

Generated with Claude Code

Replace direct os.WriteFile with a temp-file + os.Rename pattern,
matching the pattern already used in snapshot.go and activitylog.go.
A mid-write crash now leaves the original settings.json intact instead
of truncating/corrupting the user's entire Claude Code configuration.

Fixes #256

Co-Authored-By: Grey Newell <greyshipscode@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: claude[bot] <claude[bot]@users.noreply.github.com>
@claude claude bot merged commit 0ad803a into main Feb 28, 2026
1 check passed
@claude claude bot deleted the claude/issue-256-20260228-1411 branch February 28, 2026 14:24
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.

bug: hooks.Install writes settings.json non-atomically (corruption risk)

0 participants