fix(cli): handle malformed MCP config files in remove detection#2574
Merged
fahreddinozcan merged 1 commit intomasterfrom May 6, 2026
Merged
Conversation
readJsonConfig only caught file-read errors, not JSON.parse errors. During `ctx7 remove`, the detector iterates every agent's well-known config path; an unparseable JSON file at any of them (e.g. a hand-edited ~/.claude.json) crashed the command with an unhandled SyntaxError before it could do anything. Wrap the readJsonConfig call in hasMcpConfig with a try/catch that logs a warning naming the path and parse error and skips that agent. Keep readJsonConfig itself strict so write paths in setup and uninstallMcp continue to surface failures via their existing handling.
enesgules
approved these changes
May 6, 2026
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
ctx7 removecrashed with an unhandledSyntaxErrorwhenever any of the agents' well-known JSON config paths contained unparseable content (e.g. a hand-edited~/.claude.jsonwith a stray comma).readJsonConfigonly caught file-read errors, notJSON.parseerrors, and the detection path didn't wrap it.This patch wraps the
readJsonConfigcall inhasMcpConfigwith atry/catchthat logs a warning naming the offending file and parse error, then skips that agent for detection. Detection continues for the remaining agents and the user gets an actionable line instead of a stack trace.readJsonConfigitself stays strict so the write paths (setup,uninstallMcp) keep surfacing failures through their existing per-agent results-table error handling — silently swallowing parse errors there could risk overwriting a real-but-malformed user config.Before
After
Reported in #2561 where the user's pre-existing malformed
~/.claude.json(unrelated to ctx7) causedremoveto crash with no indication of which file was at fault.