fix auto updates#16
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ilently resets settings to `{}` and then writes it back, destroying all existing user settings (permissions, model preferences, allowed/blocked tools, etc.).
This commit fixes the issue reported at packages/add-plugin/lib/install.ts:291
## Bug Analysis
**Why it happens:** In `installToPluginCache()`, when reading `~/.claude/settings.json`, if the file exists but `JSON.parse` throws (e.g., due to trailing commas, minor corruption, comments, BOM characters), the catch block silently falls through with `settings = {}`. The function then proceeds to write `{ "enabledPlugins": { ... } }` back to disk, overwriting the entire file.
**When it manifests:** Any time `settings.json` contains valid-for-Claude-but-invalid-for-strict-JSON content (trailing commas, comments, BOM, or actual corruption). JSON5-style files that Claude Code may tolerate would trigger this.
**Impact:** This is a data-loss bug. `settings.json` is a shared config file owned by Claude Code that contains many important user-managed settings beyond `enabledPlugins` — permissions, model preferences, allowed/blocked tools, etc. The "start fresh" pattern that's safe for plugin-specific files (`known_marketplaces.json`, `installed_plugins.json`) is destructive when applied to this shared config file.
**Contrast with other files:** For `known_marketplaces.json` and `installed_plugins.json`, starting fresh on parse failure is acceptable because `installToPluginCache` is the sole writer/owner of those files. But `settings.json` belongs to Claude Code and other tools may write to it.
## Fix Explanation
The fix introduces a `settingsCorrupted` flag. When `JSON.parse` fails on an existing `settings.json`, instead of proceeding with an empty object (which would overwrite all settings), the code:
1. Warns the user that `settings.json` couldn't be parsed
2. Informs them they may need to manually enable plugins
3. Skips writing to `settings.json` entirely
When the file doesn't exist (the normal first-run case), `settings` remains `{}` and `settingsCorrupted` stays `false`, so the file is correctly created with just `enabledPlugins`.
Also added `warn` to the import from `./ui.js`.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: quuu <qual1337@gmail.com>
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.
No description provided.