fix: prevent profile doctor from silently wiping Claude state on bad JSON#135
Open
xzq-xu wants to merge 1 commit intoHKUDS:mainfrom
Open
fix: prevent profile doctor from silently wiping Claude state on bad JSON#135xzq-xu wants to merge 1 commit intoHKUDS:mainfrom
xzq-xu wants to merge 1 commit intoHKUDS:mainfrom
Conversation
…JSON When ~/.claude.json existed but contained invalid JSON (or a non-dict value), the except-all handler replaced the entire file contents with an empty dict — silently destroying all existing Claude state (API keys, preferences, onboarding flags, etc.). Now, corrupted state files are backed up to .claude.json.bak before being replaced, and the user is warned. Valid dict state is preserved and merged as before. The write itself uses atomic_write_text to prevent partial writes. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
clawteam profile doctor claudesilently destroyed all existing Claude state (~/.claude.json) when the file contained invalid JSON or a non-dict value. The bareexcept Exception: data = {}handler replaced the entire file with{"hasCompletedOnboarding": true}, discarding API keys, preferences, and other saved state..claude.json.bakbefore being replaced, and the user receives a clear warning. Valid dict state is preserved and merged as before.atomic_write_textfromclawteam.fileutilto prevent partial writes.Changes
clawteam/cli/commands.pyexcept Exception: data = {}with explicitjson.JSONDecodeErrorhandling, backup-before-wipe, and atomic writetests/test_profiles.pyTest plan
uv run pytest tests/test_profiles.py -v— 10/10 passeduv run pytest -q— full suite 547 passed, 0 failuresuv run ruff check— all checks passedMade with Cursor