---
name: uninstall
description: Uninstall deliberation (remove MCP config and rules)
allowed-tools: Bash, Read, AskUserQuestion
timeout: 30000
---

# Uninstall

Remove deliberation from Claude Code: MCP registrations, installed rules, the local Grok cache,
and any short command aliases that `/setup` copied.

This runs as one confirmation turn, then ONE main Bash call. Do not batch the Bash call with the
AskUserQuestion.

## Step 1: Confirm

Ask with `AskUserQuestion` (this turn has NO Bash call): "Remove deliberation MCP servers, rules,
Grok cache, and short command aliases?" Options: "Yes, uninstall" / "No, cancel".

If cancelled, stop here.

## Step 2: Remove everything

> Run the block below as ONE Bash call. Do NOT split it, and do NOT batch it with any other tool
> call. Every removal is tolerant of absence (no error if already gone).
>
> **Run it with the Bash sandbox DISABLED.** It writes `~/.claude.json` (MCP removal) and deletes
> under `~/.claude/`; a sandbox blocks those and the servers stay registered. The block verifies
> the removal at the end and prints a `CRITICAL` line if any `deliberation*` entry survives.

It removes the namespaced `deliberation-*` servers, the unified `deliberation` server, the rules
dir, the Grok cache dir, and only the aliases that are byte-identical to the bundled commands (a
user-authored same-named command is left untouched).

```bash
set -u

# --- resolve plugin root (non-fatal): env var -> cache (highest semver) -> current checkout ---
# Only the byte-identical alias check below needs it; empty is fine - MCP/rules/cache still purge.
resolve_plugin_root() {
  if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/server/mcp/index.js" ]; then printf '%s' "$CLAUDE_PLUGIN_ROOT"; return 0; fi
  local c; c=$(find "$HOME/.claude/plugins/cache" -maxdepth 6 -path '*/deliberation/*/server/mcp/index.js' -type f 2>/dev/null | sort -V | tail -1)
  if [ -n "$c" ]; then printf '%s' "${c%/server/mcp/index.js}"; return 0; fi
  if [ -f "$PWD/server/mcp/index.js" ] && grep -q '"name": "deliberation"' "$PWD/.claude-plugin/plugin.json" 2>/dev/null; then printf '%s' "$PWD"; return 0; fi
  return 1
}
PLUGIN_ROOT="$(resolve_plugin_root || true)"

# --- MCP registrations (namespaced + unified) ---
for s in deliberation deliberation-codex deliberation-gemini deliberation-grok deliberation-openrouter; do
  claude mcp remove --scope user "$s" >/dev/null 2>&1 || true
done
echo "Removed MCP registrations (user scope)."

# --- rules dir ---
rm -rf "$HOME/.claude/rules/deliberation/" 2>/dev/null || true
echo "Removed rules dir."

# --- Grok dedup cache; metadata only, safe to drop. Canonical XDG. ---
# Mirror core/paths.js: a RELATIVE XDG_CACHE_HOME is ignored (else rm -rf would
# target a path relative to $PWD) and the default ~/.cache used.
if [ -n "${XDG_CACHE_HOME:-}" ] && [ "${XDG_CACHE_HOME#/}" != "${XDG_CACHE_HOME}" ]; then
  CACHE_BASE="$XDG_CACHE_HOME"
else
  CACHE_BASE="$HOME/.cache"
fi
rm -rf "$CACHE_BASE/deliberation/" 2>/dev/null || true
echo "Removed Grok file cache."

# --- short command aliases: remove ONLY if byte-identical to the bundled command ---
removed=""; kept=""
for c in ask-gpt ask-gemini ask-grok ask-openrouter ask-all consensus grok-files; do
  dest="$HOME/.claude/commands/$c.md"
  src="$PLUGIN_ROOT/commands/$c.md"
  [ ! -e "$dest" ] && continue
  if [ -n "$PLUGIN_ROOT" ] && [ -f "$src" ] && cmp -s "$src" "$dest"; then
    rm -f "$dest" && removed="$removed /$c"
  else
    kept="$kept /$c"
  fi
done
# Obsolete /ask-both (renamed to /ask-all in 1.7.0): remove only if it carries the bundled
# fingerprint, so a user-authored ask-both.md is left untouched.
ob="$HOME/.claude/commands/ask-both.md"
if [ -e "$ob" ] && grep -q "name: ask-both" "$ob" 2>/dev/null && grep -q "deliberation" "$ob" 2>/dev/null; then
  rm -f "$ob" && removed="$removed /ask-both"
elif [ -e "$ob" ]; then
  kept="$kept /ask-both"
fi
echo "Aliases removed:${removed:- none}"
[ -n "$kept" ] && echo "Aliases left untouched (differ from bundled / user-authored):$kept"

echo
# --- verify the removals landed (catches silent sandbox write failures on ~/.claude.json) ---
LEFT="$(node -e 'const fs=require("fs"),h=require("os").homedir();try{const j=JSON.parse(fs.readFileSync(h+"/.claude.json","utf8"));const m=j.mcpServers||{};process.stdout.write(Object.keys(m).filter(k=>k==="deliberation"||k.indexOf("deliberation-")===0).join(" "))}catch(e){process.stdout.write("")}')"
if [ -n "$LEFT" ]; then
  echo "CRITICAL: these MCP entries still remain: $LEFT"
  echo "A Bash sandbox likely blocked the write to ~/.claude.json. Re-run /deliberation:uninstall"
  echo "with the sandbox DISABLED (see /sandbox)."
  echo
fi
echo "Uninstall complete. Restart Claude Code so the removed MCP servers drop from the session."
echo "To reinstall: /deliberation:setup"
```

After it runs, report the printed summary. The plugin itself is removed via `/plugin` (this command
only cleans up the user-scope MCP registrations, rules, cache, and copied aliases).

## Notes

- Grok remote uploads: if you still have `XAI_API_KEY` and want to drain xAI-side uploads before
  uninstalling, run `/grok-files prune --older-than 0s --yes` (or `/grok-files gc` to see what is
  already gone) BEFORE Step 2.
- Config is left in place - it holds your OpenRouter model setup and API-key env names. Remove it
  manually if you want a full wipe: `~/.config/deliberation/config.json` (Windows:
  `%APPDATA%\deliberation\config.json`), or the path set by `DELIBERATION_CONFIG`.
