[Bug]: uninstall leaves .claude/settings.json with a trailing comma when the user already has hooks — Claude Code then skips the whole file (deny rules and user hooks stop working)
code-review-graph version
2.3.9
Operating system
macOS
Python version
3.12.13
AI platform
claude-code
Output of code-review-graph status
N/A — the bug is in install/uninstall; no graph was built in the repro repo.Steps to reproduce
git init demo && cd demo && git commit --allow-empty -qm init
mkdir -p .claude
cat > .claude/settings.json <<'EOF'
{ "permissions": { "allow": ["Bash(npm test)"], "deny": ["Bash(git push:*)"] },
"hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "echo MY-OWN-HOOK" } ] } ] } }
EOF
uvx [email protected] install -y --platform claude-code
uvx [email protected] uninstall -y
python3 -c "import json; json.load(open('.claude/settings.json'))"Expected vs actual behavior
Summary. When a project's .claude/settings.json already contains the user's own hooks and permissions, install merges correctly, but uninstall rewrites the file with a trailing comma inside the hooks object. Claude Code reads settings.json as strict JSON, so the whole file is skipped: silently in claude -p / scheduled / CI runs, and with a "Settings Error" prompt in interactive mode.
Expected: after uninstall, .claude/settings.json is valid JSON and the user's own permissions and hooks still work, as they did before install.
Actual: the last step fails:
json.decoder.JSONDecodeError: Illegal trailing comma before end of object: line 21 column 6The file after uninstall ends like this:
"PreToolUse": [
{ "matcher": "Bash", "hooks": [ { "type": "command", "command": "echo MY-OWN-HOOK" } ] }
],
}
}(install itself is fine: the user's permissions, their PreToolUse hook and the crg PostToolUse/SessionStart entries all coexist, and a correct settings.json.bak is written.)
Impact (verified). Same repo, claude -p "... git push --dry-run ..." --allowedTools Bash:
| broken file (after uninstall) | same content, trailing comma removed | |
|---|---|---|
user's PreToolUse hook |
does not run | runs |
deny: Bash(git push:*) |
not enforced — git push --dry-run executes |
blocked (appears in permission_denials) |
| warning from Claude Code | none in claude -p; interactive mode shows "Settings Error — Files with errors are skipped entirely" with Fix / Exit / Continue without these settings |
— |
So install → uninstall removes a user's safety rules: silently in non-interactive runs, and in interactive mode whenever the user picks "Continue without these settings". Reproduced on my Mac and again in a clean macOS VM whose global ~/.claude/settings.json has no permissions or hooks.
Additional context
Likely cause
uninstall._remove_hooks() validates the rewritten text with json.loads(skills._strip_jsonc(rewritten)). _strip_jsonc intentionally removes trailing commas, so the validation passes, but the text written to disk still contains the comma. That is fine for JSONC targets, but .claude/settings.json (and possibly other strict-JSON targets) must be written as strict JSON.
Possible fixes: validate with plain json.loads(rewritten) for strict-JSON targets, or strip trailing commas from the text before writing.
Why the test suite doesn't catch it
tests/test_platform_lifecycle.py seeds pre-existing configs with an unrelated setting and another MCP server (write_preexisting_config), but not with the user's own hooks block in .claude/settings.json, and it reads configs back through json.loads(skills._strip_jsonc(raw)) — the same tolerant parse, so a trailing comma passes there too. A strict json.loads(raw) check for .claude/settings.json after uninstall, with a seeded user hook, would reproduce it.
Related (checked before filing, none cover this)
- #553 — trailing-comma regex corrupting string values on the install/read side (closed)
- #114, #263 — install overwriting existing Claude hooks (closed, fixed: install now merges correctly)
- #645, #1025 — uninstall command and its boundary fixes (merged;
uninstall.pyunchanged since v2.3.9)
Also observed (minor, same run)
.gemini/settings.json.bakis not the original file — it is the state after the MCP merge and before the hook merge. (The leftover.bakitself is already tracked as an xfail in the lifecycle tests; the "not the original" part may not be.)- Other files that get merged (
.mcp.json,.vscode/mcp.json,~/.copilot/mcp-config.json,~/.gemini/antigravity/mcp_config.json,~/.codex/config.toml) get no backup; after uninstall their content is restored but formatting is changed (single-line → indented), andconfig.tomlgains a blank line.
Source: tirth8205/code-review-graph