Skip to content

Stagger consecutive claude restores to avoid ~/.claude.json corruption#20

Merged
AThraen merged 1 commit into
mainfrom
fix/stagger-claude-restore
May 11, 2026
Merged

Stagger consecutive claude restores to avoid ~/.claude.json corruption#20
AThraen merged 1 commit into
mainfrom
fix/stagger-claude-restore

Conversation

@AThraen
Copy link
Copy Markdown
Contributor

@AThraen AThraen commented May 11, 2026

Summary

  • Claude's CLI does an unlocked read-modify-write on ~/.claude.json at startup, so when CSM auto-restores several claude sessions back-to-back the writes race and can corrupt the user's profile.
  • Added a 2s Task.Delay between any two consecutive claude restores in MainWindow.OnLoaded. Non-claude sessions and the first claude in the loop launch with no added delay, so startup cost only grows when there are multiple claude sessions to restore.

Notes

  • This is a workaround on the CSM side — the underlying race is in Claude itself and should be fixed upstream with proper file locking.
  • 2s was chosen as a safe quiet period for claude's startup writes; if it proves too short we can raise it or move to a global mutex held by CSM around each claude launch.

Test plan

  • Launch CSM with several restored claude sessions and confirm ~/.claude.json stays valid after every restart.
  • Confirm non-claude sessions still restore without added delay.
  • Confirm a single claude session restores with no added delay.

🤖 Generated with Claude Code

…uption

Claude's CLI does an unlocked read-modify-write on ~/.claude.json at
startup. When CodeShellManager auto-restores many claude sessions in
quick succession, those writes race and can truncate or corrupt the
user's profile. Insert a 2s delay between any two consecutive claude
restores so each instance can settle its config write before the next
one reads.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@AThraen AThraen merged commit b70862c into main May 11, 2026
1 check passed
@AThraen AThraen deleted the fix/stagger-claude-restore branch May 11, 2026 12:27
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