From bcba29402ddcba768e88666a2d85c44f16b17c87 Mon Sep 17 00:00:00 2001 From: okash1n <48118431+okash1n@users.noreply.github.com> Date: Tue, 6 Oct 2026 17:46:25 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20uninstall.sh=20=E3=81=8C=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E3=81=97=E3=81=AA=E3=81=84=20claude=20uninstall=20?= =?UTF-8?q?=E3=82=B5=E3=83=96=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=82=92?= =?UTF-8?q?=E5=91=BC=E3=82=93=E3=81=A7=E3=81=84=E3=81=9F=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=EF=BC=88v0.78.4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CLI 削除の確認に y と答えると、ネイティブ版・インストール方法を判別できない 場合・Git Bash で %LOCALAPPDATA%\Programs\claude が無い場合に claude uninstall を実行していた。Claude Code 2.1.291 の claude --help に uninstall コマンドは なく、Usage は claude [options] [command] [prompt] なので、この語はプロンプト として渡る形になる。ネイティブ版の分岐は失敗時に ~/.local/bin/claude だけを 消して完了と表示し、~/.local/share/claude が残っていた。 - uninstall.sh: claude uninstall の呼び出しを全廃し、公式のアンインストール 手順に合わせた。ネイティブ版は既定配置(ランチャーが ~/.local/share/claude/versions/ 内を指す symlink、データディレクトリが symlink を経由しない実ディレクトリ)と確認できた場合だけ ~/.local/bin/claude と ~/.local/share/claude を削除する。削除直前に同じ 確認をやり直し、再帰削除は検証済みの親ディレクトリの中から実ディレクトリに 対してだけ行う - uninstall.sh: Homebrew は brew uninstall --cask を使い、claude-code@latest cask も検出する。npm 版は従来どおり npm uninstall -g - uninstall.sh: カスタムランチャー、symlink、既定以外の場所への配置、判別 不能、Git Bash の旧配置は自動削除せず、公式ドキュメントの URL と方法別の 削除コマンドを表示する。削除後も claude が見つかる場合は警告する - ~/.claude と ~/.claude.json には触れない。確認プロンプトの数と順序、EOF を 「残す」と扱う点は変えていない - tests/unit/test-uninstall.sh: 使い捨ての HOME とスタブの claude / npm / brew による検証を 13 件追加(修正前コードでは 11 件が失敗) - tests/unit/test-codex-setup.sh: 同梱スクリプトがコマンド位置で呼ぶ claude / _claude_cli の第 1 階層サブコマンドが plugin / mcp 以外でない ことの静的ガードを追加(修正前コードでは uninstall.sh の 3 箇所を検出) - README.md / README.en.md / CHANGELOG.md: CLI 削除の範囲と、確認できない 配置では手動手順を表示することを追記 Git Bash の分岐は実機では未検証(_IS_MSYS を立てた擬似環境のテストのみ)。 Fixes #175 --- CHANGELOG.md | 11 ++ README.en.md | 2 + README.md | 2 + tests/unit/test-codex-setup.sh | 29 +++ tests/unit/test-uninstall.sh | 351 ++++++++++++++++++++++++++++++++- uninstall.sh | 173 ++++++++++++---- 6 files changed, 530 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e071ce..ff8caa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/). +## [0.78.4] - 2026-10-06 + +### Fixed +- **`uninstall.sh` が存在しない `claude uninstall` サブコマンドを呼んでいた問題を修正(#175)**: 「Claude Code CLI もアンインストールしますか?」に y と答えると、ネイティブ版(`~/.local/bin/claude` がある場合)、インストール方法を判別できない場合、Git Bash で `%LOCALAPPDATA%\Programs\claude` が無い場合に `claude uninstall` を実行していた。Claude Code 2.1.291 の `claude --help` のコマンド一覧に `uninstall` はなく、Usage は `claude [options] [command] [prompt]` なので、この語は削除コマンドではなくプロンプトとして渡る形になる(実 CLI で `claude uninstall` を実行した結果は確認していない)。ネイティブ版の分岐は、この呼び出しが失敗すると `~/.local/bin/claude` だけを削除して「アンインストールしました」と表示しており、ダウンロード済みの各バージョンが入った `~/.local/share/claude` が残っていた + - `claude uninstall` の呼び出しをすべてやめ、公式のアンインストール手順に合わせた。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude` を削除する。対象は既定の配置だと確認できた場合に限る(macOS / Linux / WSL では、ランチャーが `~/.local/share/claude/versions/` 内を指す symlink で、`~/.local/share/claude` が symlink を経由しない実ディレクトリであること)。削除の直前に同じ確認をやり直し、再帰削除はホームディレクトリ由来の固定パスに対してだけ行う。npm 版は従来どおり `npm uninstall -g @anthropic-ai/claude-code`、Homebrew 版は `brew uninstall --cask` を使い、これまで確認対象に入っていなかった `claude-code@latest` cask も検出する + - カスタムランチャー(`~/.local/bin/claude` が通常ファイルや別の場所を指す symlink)、`~/.local/share/claude` やその親が symlink の配置、`XDG_DATA_HOME` などで既定以外の場所へ移した配置、インストール方法を判別できない場合は自動削除せず、公式ドキュメントの URL と方法別の削除コマンドを表示する。削除に成功したあとも `claude` コマンドが見つかる場合は、別のインストールが残っている可能性を警告する + - Git Bash では、公式手順に記載のない `%LOCALAPPDATA%\Programs\claude` の再帰削除をやめ、`%USERPROFILE%\.local\bin\claude.exe` と `%USERPROFILE%\.local\share\claude` を対象にした。旧配置にある CLI は自動削除されず、手動の手順が表示される。Git Bash の分岐は実機では未検証で、テストは `_IS_MSYS` を立てた擬似環境での確認にとどまる + - 設定とセッション履歴(`~/.claude`、`~/.claude.json`)は従来どおり CLI の削除では触らず、削除後にその旨を表示する。確認プロンプトの数と順序、未入力(EOF)を「残す」として扱う点は変えていない + - **回帰テスト**: `tests/unit/test-uninstall.sh` に、使い捨ての HOME とスタブの `claude` / `npm` / `brew` で CLI 削除プロンプト以降の経路を確かめる検証を 13 件追加した(ネイティブ版の既定配置、カスタムランチャー、symlink のデータディレクトリ、symlink の親ディレクトリ、既定以外の場所への配置、判別不能、npm、Homebrew cask 2 種、n と EOF での辞退、削除関数が空・相対・HOME 外のパスを拒否すること、Git Bash 分岐の擬似環境)。修正前のコードでは 13 件中 11 件が失敗する(辞退の 2 件は従来から通る)。`tests/unit/test-codex-setup.sh` には、同梱スクリプトがコマンド位置で呼ぶ `claude <語>` / `_claude_cli <語>` の第 1 階層が、現在使っている `plugin` / `mcp` 以外でないことの静的検査を追加した。修正前のコードでは `uninstall.sh` の 3 箇所を検出する + - **既存インストールへの影響**: 以前に y を選んでランチャーだけが削除された環境には `~/.local/share/claude` が残っている場合がある。不要なら `rm -rf ~/.local/share/claude` で削除できる。今後ネイティブ版で y を選ぶと、これまで残っていた `~/.local/share/claude`(ダウンロード済みの全バージョン)も削除される + ## [0.78.2] - 2026-10-06 ### Fixed diff --git a/README.en.md b/README.en.md index 73fca00..f444369 100644 --- a/README.en.md +++ b/README.en.md @@ -509,6 +509,8 @@ Only files deployed by the starter kit (tracked in `~/.claude/.starter-kit-manif Some things the kit installed are offered rather than removed automatically, because they may outlive the kit: the Claude Code CLI, the Codex plugin, `cc-safety-net`, and local data under `~/.claude/security/` when the kit has a durable record of a verified `security-guidance` install. Regardless of fresh/update mode or legacy manifest selections, a plugin already present in the pre-install list is not adopted into this record, and its local data is not offered for cleanup. Each item is a separate prompt that defaults to keeping it. Accepting the local-data cleanup removes only known plugin-owned leaves such as its Python environments, session state, and logs; unknown files and directories in the shared location are preserved. Data moved elsewhere through environment-variable overrides is outside the cleanup scope. +Accepting the Claude Code CLI prompt removes only the CLI itself, following the official uninstall steps. A native install loses `~/.local/bin/claude` and `~/.local/share/claude` (the downloaded versions); an npm install or a Homebrew cask (`claude-code` / `claude-code@latest`) is removed with its own uninstall command. Settings and session history (`~/.claude`, `~/.claude.json`) are kept. When the install method or layout cannot be confirmed — a custom launcher, a symlinked data directory, or a location moved with `XDG_DATA_HOME` — nothing is removed automatically and the manual steps are shown instead. + ## Development Shell scripts are statically analyzed with [ShellCheck](https://www.shellcheck.net/). It runs automatically via GitHub Actions on PRs. To run locally: diff --git a/README.md b/README.md index e484a6f..ba7e86b 100644 --- a/README.md +++ b/README.md @@ -1024,6 +1024,8 @@ cd claude-code-starter-kit キットが導入したもののうち、キットより長く使う可能性があるものは自動削除せず個別に確認します(既定はすべて「残す」)。対象は Claude Code CLI、Codex プラグイン、`cc-safety-net`、そしてキットによる検証済みの導入履歴が記録された `security-guidance` が `~/.claude/security/` に作るローカルデータです。fresh / update の別や旧 manifest の選択内容にかかわらず、セットアップの導入前一覧にすでに存在したプラグインはこの履歴に採用せず、そのローカルデータには削除を提示しません。ローカルデータの削除を選んでも、Python 仮想環境・セッション状態・ログ等の既知の plugin-owned leaf だけを削除し、同じディレクトリにある未知のファイルやディレクトリは保持します。環境変数で別の場所へ移したデータは対象外です。 +Claude Code CLI の削除を選ぶと、CLI 本体だけを公式のアンインストール手順どおりに削除します。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude`(ダウンロード済みの各バージョン)を削除し、npm 版と Homebrew cask(`claude-code` / `claude-code@latest`)はそれぞれのアンインストールコマンドを実行します。設定とセッション履歴(`~/.claude`、`~/.claude.json`)は残ります。カスタムランチャー、symlink になっているデータディレクトリ、`XDG_DATA_HOME` で移した配置など、インストール方法や配置を確認できない場合は自動削除せず、手動の手順を表示します。 + --- ## ❓ FAQ diff --git a/tests/unit/test-codex-setup.sh b/tests/unit/test-codex-setup.sh index 5e261ad..8e4af3e 100644 --- a/tests/unit/test-codex-setup.sh +++ b/tests/unit/test-codex-setup.sh @@ -247,6 +247,35 @@ else fi fi +# The CLI treats a word it does not know as a prompt (`claude [options] +# [command] [prompt]`) and starts a session, so a shipped script must only pass +# subcommands that exist. The allowlist holds the first-level subcommands the +# shipped scripts call today; confirm a new one against `claude --help` before +# adding it. Known invocations are marked (`claude=plugin`) rather than dropping +# their whole line, so an unknown one sharing the line is still reported. +# `_claude_cli` is matched anywhere; a bare `claude` only in command position, +# which keeps display strings out. Not covered: flags before the word, +# arguments held in variables, second-level subcommands, and wrappers other +# than the listed keywords. +if ! git -C "$PROJECT_DIR" rev-parse --is-inside-work-tree &>/dev/null; then + skip "codex-setup: shipped scripts only call claude subcommands that exist" "needs a git checkout" +else + _claude_known_subcommands='plugin|mcp' + _claude_grep_bol='^[^:]+:[0-9]+:' + _unknown_claude_calls="$( + cd "$PROJECT_DIR" && git grep -nE '(^|[^A-Za-z0-9_])(_claude_cli|claude)[[:space:]]+[a-z]' \ + -- setup.sh install.sh uninstall.sh 'lib/*.sh' 'wizard/*.sh' 'mdm/*.sh' 'features/*.sh' \ + | grep -vE "${_claude_grep_bol}[[:space:]]*#" \ + | sed -E "s/(_claude_cli|claude)[[:space:]]+(${_claude_known_subcommands})([^A-Za-z0-9_-]|\$)/\\1=\\2\\3/g" \ + | grep -E "((${_claude_grep_bol}|[;&|(){!\`])[[:space:]]*|(${_claude_grep_bol}|[^A-Za-z0-9_])(if|elif|while|until|then|do|else|exec|command|time)[[:space:]]+)claude[[:space:]]+[a-z]|(${_claude_grep_bol}|[^A-Za-z0-9_])_claude_cli[[:space:]]+[a-z]" || true + )" + if assert_equals "" "$_unknown_claude_calls"; then + pass "codex-setup: shipped scripts only call claude subcommands that exist" + else + fail "codex-setup: claude was called with a word that is not a known subcommand: $_unknown_claude_calls" + fi +fi + # Legacy MCP removal should rely on scope-agnostic CLI removal setup_fake_claude export MOCK_CLAUDE_LIST_OUTPUT=$'codex\n' diff --git a/tests/unit/test-uninstall.sh b/tests/unit/test-uninstall.sh index ce5dd02..0a18b55 100644 --- a/tests/unit/test-uninstall.sh +++ b/tests/unit/test-uninstall.sh @@ -139,7 +139,9 @@ ln -s "$(command -v node)" "$_ut_bin/node" # the host. The e2e PATH keeps /usr/bin, where Linux distros commonly install # npm — stub it so `npm list -g cc-safety-net` fails and the prompt is # skipped deterministically. A controlled failing `claude` stub keeps its -# unavoidable CLI-uninstall prompt harmless; queued answers always decline it. +# unavoidable CLI-uninstall prompt harmless: the cases using this bin decline +# it, and the CLI removal cases further down accept it only against their own +# logging npm/brew/claude stubs. printf '#!/bin/sh\nexit 1\n' > "$_ut_bin/npm" chmod +x "$_ut_bin/npm" printf '%s\n' '#!/bin/bash @@ -1476,6 +1478,353 @@ else fail "uninstall: prompt-time security/tree inode exchange reached replacement data" fi +# ── Claude Code CLI removal ─────────────────────────────────────────────── +# +# The CLI has no `uninstall` subcommand, and a word it does not know is taken +# as a prompt. Accepting the CLI prompt must therefore remove a native install +# in the documented default layout by path, hand npm / Homebrew installs to +# their own uninstaller, and only print the manual steps for a layout it cannot +# verify. These cases answer "y", so every external command has to resolve to a +# logging stub: PATH is the case bin plus the system directories, never the +# host's brew / npm / claude. +_ut_cli_root="$_ut_tmp/cli-removal" +_ut_cli_bin="$_ut_cli_root/bin" +_ut_cli_bin_claude="$_ut_cli_root/bin-with-claude" +mkdir -p "$_ut_cli_bin" "$_ut_cli_bin_claude" +cat > "$_ut_cli_bin/npm" <<'EOF' +#!/bin/bash +printf 'npm %s\n' "$*" >> "${UNINSTALL_TOOL_LOG:-/dev/null}" +[[ "${UNINSTALL_NPM_HAS_CLAUDE:-}" == "1" && "$*" == *" @anthropic-ai/claude-code" ]] +EOF +cat > "$_ut_cli_bin/brew" <<'EOF' +#!/bin/bash +printf 'brew %s\n' "$*" >> "${UNINSTALL_TOOL_LOG:-/dev/null}" +[[ -n "${UNINSTALL_BREW_CASK:-}" && "$*" == *" --cask ${UNINSTALL_BREW_CASK}" ]] +EOF +cat > "$_ut_cli_bin_claude/claude" <<'EOF' +#!/bin/bash +printf 'claude %s\n' "$*" >> "${UNINSTALL_TOOL_LOG:-/dev/null}" +exit 1 +EOF +chmod +x "$_ut_cli_bin/npm" "$_ut_cli_bin/brew" "$_ut_cli_bin_claude/claude" +ln -s "$_ut_bin/jq" "$_ut_cli_bin/jq" +ln -s "$_ut_bin/node" "$_ut_cli_bin/node" +for _ut_cli_tool in jq node npm brew; do + ln -s "$_ut_cli_bin/$_ut_cli_tool" "$_ut_cli_bin_claude/$_ut_cli_tool" +done +for _ut_cli_dir in "$_ut_cli_bin" "$_ut_cli_bin_claude"; do + for _ut_cli_tool in npm brew; do + if [[ "$(PATH="$_ut_cli_dir:/usr/bin:/bin:/usr/sbin:/sbin" command -v "$_ut_cli_tool" || true)" \ + != "$_ut_cli_dir/$_ut_cli_tool" ]]; then + fail "uninstall: CLI removal e2e PATH did not bind the $_ut_cli_tool stub" + exit 1 + fi + done +done +if [[ "$(PATH="$_ut_cli_bin_claude:/usr/bin:/bin:/usr/sbin:/sbin" command -v claude || true)" \ + != "$_ut_cli_bin_claude/claude" ]]; then + fail "uninstall: CLI removal e2e PATH did not bind the claude stub" + exit 1 +fi + +_ut_cli_prepare() { # ; sets _ut_cli_home / _ut_cli_log / _ut_cli_out + _ut_cli_home="$_ut_cli_root/$1/home" + _ut_cli_log="$_ut_cli_root/$1/tool.log" + _ut_cli_out="$_ut_cli_root/$1/output" + mkdir -p "$_ut_cli_home/.claude" "$_ut_cli_home/tmp" "$_ut_cli_home/appdata" \ + "$_ut_cli_home/localappdata" "$_ut_cli_home/npm" \ + "$_ut_cli_home/.local/bin" "$_ut_cli_home/.local/state/claude" + : > "$_ut_cli_log" + printf '{"managed":true}\n' > "$_ut_cli_home/.claude/settings.json" + printf 'user data\n' > "$_ut_cli_home/.claude/user-file" + printf '{"installMethod":"native"}\n' > "$_ut_cli_home/.claude.json" + printf 'lock\n' > "$_ut_cli_home/.local/state/claude/lock" + jq -n --arg settings "$_ut_cli_home/.claude/settings.json" \ + '{version:"2", profile:"standard", language:"en", timestamp:"test", + files:[$settings], cleanup_paths:[]}' \ + > "$_ut_cli_home/.claude/.starter-kit-manifest.json" +} + +_ut_cli_version_store() { # : versions/ holding a logging launcher target + mkdir -p "$1/versions" + cp "$_ut_cli_bin_claude/claude" "$1/versions/9.9.9" + printf 'older version\n' > "$1/versions/9.9.8" +} + +_ut_cli_run() { # [ENV=value ...]; sets _ut_cli_rc + local answers="$1" bin="$2" + shift 2 + _ut_cli_rc=0 + printf '%b' "$answers" | env -i HOME="$_ut_cli_home" TMPDIR="$_ut_cli_home/tmp" \ + APPDATA="$_ut_cli_home/appdata" LOCALAPPDATA="$_ut_cli_home/localappdata" \ + NPM_CONFIG_PREFIX="$_ut_cli_home/npm" npm_config_prefix="$_ut_cli_home/npm" \ + STARTER_KIT_DIR="$_ut_cli_home/nonexistent-kit" \ + UNINSTALL_TOOL_LOG="$_ut_cli_log" \ + PATH="$bin:/usr/bin:/bin:/usr/sbin:/sbin" LC_ALL=C TERM=dumb "$@" \ + bash "$PROJECT_DIR/uninstall.sh" > "$_ut_cli_out" 2>&1 || _ut_cli_rc=$? +} + +_ut_cli_gone() { [[ ! -e "$1" && ! -L "$1" ]]; } + +# Holds for every case: the run succeeds, settings and session data survive, +# and the CLI is only ever run with the list subcommands of the Codex cleanup. +_ut_cli_common_ok() { + local unexpected + unexpected="$(grep '^claude ' "$_ut_cli_log" \ + | grep -vxE 'claude (plugin|mcp) list' || true)" + [[ "$_ut_cli_rc" -eq 0 && -z "$unexpected" ]] \ + && grep -qx 'user data' "$_ut_cli_home/.claude/user-file" \ + && [[ -f "$_ut_cli_home/.claude.json" ]] \ + && [[ -f "$_ut_cli_home/.local/state/claude/lock" ]] +} + +_ut_cli_manual_only() { # manual steps shown, nothing uninstalled + grep -q 'not removed automatically' "$_ut_cli_out" \ + && grep -qF 'https://code.claude.com/docs/en/setup#uninstall-claude-code' "$_ut_cli_out" \ + && ! grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ + && ! grep -qE '^(npm|brew) uninstall' "$_ut_cli_log" +} + +_ut_cli_fail() { # ; keeps the evidence in the test log + fail "$1 (rc=$_ut_cli_rc)" + { + printf ' --- tool log ---\n' + sed 's/^/ /' "$_ut_cli_log" + printf ' --- output tail ---\n' + tail -n 15 "$_ut_cli_out" | sed 's/^/ /' + } >&2 || true +} + +# Native install in the default layout: launcher and version store both go. +_ut_cli_prepare native +_ut_cli_version_store "$_ut_cli_home/.local/share/claude" +ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" +_ut_cli_run 'y\ny\n' "$_ut_cli_bin" +if _ut_cli_common_ok \ + && _ut_cli_gone "$_ut_cli_home/.local/bin/claude" \ + && _ut_cli_gone "$_ut_cli_home/.local/share/claude" \ + && [[ -d "$_ut_cli_home/.local/bin" && -d "$_ut_cli_home/.local/share" ]] \ + && grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ + && grep -q 'were not removed' "$_ut_cli_out" \ + && ! grep -q 'still found' "$_ut_cli_out" \ + && ! grep -qE '^(npm|brew) uninstall' "$_ut_cli_log"; then + pass "uninstall: native CLI in the default layout is removed with its version store" +else + _ut_cli_fail "uninstall: native CLI removal left the launcher or ~/.local/share/claude, or ran an unknown claude subcommand" +fi + +# A regular file at ~/.local/bin/claude is a custom launcher, not a native install. +_ut_cli_prepare custom-launcher +mkdir -p "$_ut_cli_home/.local/share/claude/versions" +printf 'kept\n' > "$_ut_cli_home/.local/share/claude/versions/keep" +cp "$_ut_cli_bin_claude/claude" "$_ut_cli_home/.local/bin/claude" +_ut_cli_run 'y\ny\n' "$_ut_cli_bin" +if _ut_cli_common_ok && _ut_cli_manual_only \ + && [[ -f "$_ut_cli_home/.local/bin/claude" && ! -L "$_ut_cli_home/.local/bin/claude" ]] \ + && grep -qx 'kept' "$_ut_cli_home/.local/share/claude/versions/keep"; then + pass "uninstall: custom launcher at ~/.local/bin/claude is kept and manual steps are shown" +else + _ut_cli_fail "uninstall: custom launcher was removed or treated as a native install" +fi + +# ~/.local/share/claude is a symlink: neither the link nor its referent goes. +_ut_cli_prepare data-symlink +_ut_cli_external="$_ut_cli_root/data-symlink/external" +_ut_cli_version_store "$_ut_cli_external" +mkdir -p "$_ut_cli_home/.local/share" +ln -s "$_ut_cli_external" "$_ut_cli_home/.local/share/claude" +ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" +_ut_cli_run 'y\ny\n' "$_ut_cli_bin" +if _ut_cli_common_ok && _ut_cli_manual_only \ + && [[ -L "$_ut_cli_home/.local/bin/claude" ]] \ + && [[ -L "$_ut_cli_home/.local/share/claude" ]] \ + && [[ -f "$_ut_cli_external/versions/9.9.9" && -f "$_ut_cli_external/versions/9.9.8" ]]; then + pass "uninstall: symlinked ~/.local/share/claude and its referent are kept" +else + _ut_cli_fail "uninstall: CLI removal followed a symlinked data directory" +fi + +# A symlinked ancestor (~/.local/share) is no authority to delete its referent either. +_ut_cli_prepare ancestor-symlink +_ut_cli_external="$_ut_cli_root/ancestor-symlink/external-share" +_ut_cli_version_store "$_ut_cli_external/claude" +ln -s "$_ut_cli_external" "$_ut_cli_home/.local/share" +ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" +_ut_cli_run 'y\ny\n' "$_ut_cli_bin" +if _ut_cli_common_ok && _ut_cli_manual_only \ + && [[ -L "$_ut_cli_home/.local/bin/claude" ]] \ + && [[ -L "$_ut_cli_home/.local/share" ]] \ + && [[ -f "$_ut_cli_external/claude/versions/9.9.9" \ + && -f "$_ut_cli_external/claude/versions/9.9.8" ]]; then + pass "uninstall: version store beneath a symlinked ~/.local/share is kept" +else + _ut_cli_fail "uninstall: CLI removal crossed a symlinked ancestor" +fi + +# Launcher pointing outside ~/.local/share/claude (e.g. XDG_DATA_HOME): the +# relocated store is not removed, and neither is the unrelated default path. +_ut_cli_prepare relocated +_ut_cli_external="$_ut_cli_root/relocated/xdg/claude" +_ut_cli_version_store "$_ut_cli_external" +mkdir -p "$_ut_cli_home/.local/share/claude/versions" +printf 'kept\n' > "$_ut_cli_home/.local/share/claude/versions/keep" +ln -s "$_ut_cli_external/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" +_ut_cli_run 'y\ny\n' "$_ut_cli_bin" +if _ut_cli_common_ok && _ut_cli_manual_only \ + && [[ -L "$_ut_cli_home/.local/bin/claude" ]] \ + && grep -qx 'kept' "$_ut_cli_home/.local/share/claude/versions/keep" \ + && [[ -f "$_ut_cli_external/versions/9.9.9" && -f "$_ut_cli_external/versions/9.9.8" ]]; then + pass "uninstall: relocated native install is kept and manual steps are shown" +else + _ut_cli_fail "uninstall: CLI removal touched a relocated install or the default data path" +fi + +# Only a `claude` on PATH: the install method is unknown, so nothing is run. +_ut_cli_prepare unknown +_ut_cli_run 'y\ny\n' "$_ut_cli_bin_claude" +if _ut_cli_common_ok && _ut_cli_manual_only \ + && [[ -x "$_ut_cli_bin_claude/claude" ]] \ + && grep -qx 'npm list -g @anthropic-ai/claude-code' "$_ut_cli_log" \ + && grep -qx 'brew list --cask claude-code' "$_ut_cli_log" \ + && grep -qx 'brew list --cask claude-code@latest' "$_ut_cli_log"; then + pass "uninstall: unknown CLI install method only prints the manual steps" +else + _ut_cli_fail "uninstall: unknown CLI install method ran a command instead of printing manual steps" +fi + +# npm global install: delegated to npm. The stub leaves its claude on PATH, +# which is what the leftover-install warning reports. +_ut_cli_prepare npm +_ut_cli_run 'y\ny\n' "$_ut_cli_bin_claude" UNINSTALL_NPM_HAS_CLAUDE=1 +if _ut_cli_common_ok \ + && grep -qx 'npm uninstall -g @anthropic-ai/claude-code' "$_ut_cli_log" \ + && ! grep -q '^brew uninstall' "$_ut_cli_log" \ + && grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ + && grep -q 'were not removed' "$_ut_cli_out" \ + && grep -qF "still found: $_ut_cli_bin_claude/claude" "$_ut_cli_out"; then + pass "uninstall: npm CLI install is removed through npm uninstall -g" +else + _ut_cli_fail "uninstall: npm CLI install was not handed to npm uninstall -g" +fi + +# Homebrew: both casks are detected and removed with --cask. +for _ut_cli_cask in claude-code claude-code@latest; do + _ut_cli_prepare "brew-$_ut_cli_cask" + _ut_cli_run 'y\ny\n' "$_ut_cli_bin_claude" UNINSTALL_BREW_CASK="$_ut_cli_cask" + if _ut_cli_common_ok \ + && grep -qxF "brew uninstall --cask $_ut_cli_cask" "$_ut_cli_log" \ + && [[ "$(grep -c '^brew uninstall' "$_ut_cli_log")" -eq 1 ]] \ + && ! grep -q '^npm uninstall' "$_ut_cli_log" \ + && grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out"; then + pass "uninstall: Homebrew cask $_ut_cli_cask is removed through brew uninstall --cask" + else + _ut_cli_fail "uninstall: Homebrew cask $_ut_cli_cask was not handed to brew uninstall --cask" + fi +done + +# Declining (an explicit "n", or EOF at the prompt) leaves a native install alone. +for _ut_cli_answers in 'y\nn\n' 'y\n'; do + _ut_cli_prepare "declined-${#_ut_cli_answers}" + _ut_cli_version_store "$_ut_cli_home/.local/share/claude" + ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" + _ut_cli_run "$_ut_cli_answers" "$_ut_cli_bin" + if _ut_cli_common_ok \ + && [[ -L "$_ut_cli_home/.local/bin/claude" ]] \ + && [[ -f "$_ut_cli_home/.local/share/claude/versions/9.9.9" \ + && -f "$_ut_cli_home/.local/share/claude/versions/9.9.8" ]] \ + && grep -q 'Skipped Claude Code CLI uninstall' "$_ut_cli_out" \ + && ! grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ + && ! grep -q 'claude-code' "$_ut_cli_log"; then + pass "uninstall: declining the CLI prompt (answers '$_ut_cli_answers') keeps a native install" + else + _ut_cli_fail "uninstall: declined CLI prompt (answers '$_ut_cli_answers') still changed the install" + fi +done + +# The removal helper deletes only the pair it has just re-verified under HOME. +# Empty, relative (resolving to the real install from the working directory), +# and native-shaped paths outside HOME must all be refused; the same call with +# the detected pair must then succeed, which keeps the refusals from passing +# vacuously. +_ut_cli_prepare remove-guard +_ut_cli_version_store "$_ut_cli_home/.local/share/claude" +ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" +_ut_cli_foreign="$_ut_cli_root/remove-guard/foreign" +mkdir -p "$_ut_cli_foreign/.local/bin" +_ut_cli_version_store "$_ut_cli_foreign/.local/share/claude" +ln -s "$_ut_cli_foreign/.local/share/claude/versions/9.9.9" "$_ut_cli_foreign/.local/bin/claude" +{ + _ut_extract_fn "$PROJECT_DIR/uninstall.sh" "_claude_cli_detect_native" + _ut_extract_fn "$PROJECT_DIR/uninstall.sh" "_claude_cli_remove_native" +} > "$_ut_cli_root/remove-guard/functions.sh" +_ut_cli_guard_out="$(cd "$_ut_cli_home" && env -i HOME="$_ut_cli_home" \ + PATH="/usr/bin:/bin:/usr/sbin:/sbin" LC_ALL=C TERM=dumb bash -c ' + set -euo pipefail + _IS_MSYS=false + source "$1" + accepted="" + _claude_cli_remove_native "" "" && accepted="${accepted}empty " + _claude_cli_remove_native ".local/bin/claude" ".local/share/claude" \ + && accepted="${accepted}relative " + _claude_cli_remove_native "$2/.local/bin/claude" "$2/.local/share/claude" \ + && accepted="${accepted}foreign " + _claude_cli_remove_native "$HOME/.local/bin/claude" "$2/.local/share/claude" \ + && accepted="${accepted}mixed " + printf "accepted=[%s]" "$accepted" + [[ -L "$HOME/.local/bin/claude" && -f "$HOME/.local/share/claude/versions/9.9.9" ]] \ + && printf " kept" + HOME="${HOME##*/}" + (cd "$3" && _claude_cli_detect_native) || printf " relative-home-rc=%s" "$?" + HOME="$3/${HOME}" + _claude_cli_detect_native \ + && _claude_cli_remove_native "$_CLAUDE_CLI_NATIVE_LAUNCHER" "$_CLAUDE_CLI_NATIVE_DATA" \ + && printf " removed" +' _ "$_ut_cli_root/remove-guard/functions.sh" "$_ut_cli_foreign" \ + "$_ut_cli_root/remove-guard" 2>&1 || true)" +if [[ "$_ut_cli_guard_out" == "accepted=[] kept relative-home-rc=1 removed" ]] \ + && _ut_cli_gone "$_ut_cli_home/.local/bin/claude" \ + && _ut_cli_gone "$_ut_cli_home/.local/share/claude" \ + && [[ -L "$_ut_cli_foreign/.local/bin/claude" ]] \ + && [[ -f "$_ut_cli_foreign/.local/share/claude/versions/9.9.9" \ + && -f "$_ut_cli_foreign/.local/share/claude/versions/9.9.8" ]]; then + pass "uninstall: native CLI removal refuses empty, relative, and outside-HOME paths" +else + fail "uninstall: native CLI removal accepted a path it had not verified under HOME (got: $_ut_cli_guard_out)" +fi + +# Git Bash branch, simulated with _IS_MSYS=true and a pass-through cygpath (no +# real Windows involved): the layout is looked up under USERPROFILE, the +# launcher is the regular file claude.exe, and a symlink in its place is not a +# native install. +_ut_cli_win="$_ut_cli_root/remove-guard/winhome" +mkdir -p "$_ut_cli_win/.local/bin" "$_ut_cli_win/.local/share/claude/versions" +printf 'binary\n' > "$_ut_cli_win/.local/bin/claude.exe" +printf 'version\n' > "$_ut_cli_win/.local/share/claude/versions/9.9.9" +_ut_cli_guard_out="$(env -i HOME="$_ut_cli_home" USERPROFILE="$_ut_cli_win" \ + PATH="/usr/bin:/bin:/usr/sbin:/sbin" LC_ALL=C TERM=dumb bash -c ' + set -euo pipefail + _IS_MSYS=true + cygpath() { printf "%s\n" "$2"; } + source "$1" + mv "$USERPROFILE/.local/bin/claude.exe" "$USERPROFILE/.local/bin/real.exe" + ln -s "$USERPROFILE/.local/bin/real.exe" "$USERPROFILE/.local/bin/claude.exe" + _claude_cli_detect_native || printf "symlink-rc=%s" "$?" + rm -f "$USERPROFILE/.local/bin/claude.exe" + mv "$USERPROFILE/.local/bin/real.exe" "$USERPROFILE/.local/bin/claude.exe" + _claude_cli_detect_native \ + && [[ "$_CLAUDE_CLI_NATIVE_LAUNCHER" == "$USERPROFILE/.local/bin/claude.exe" ]] \ + && _claude_cli_remove_native "$_CLAUDE_CLI_NATIVE_LAUNCHER" "$_CLAUDE_CLI_NATIVE_DATA" \ + && printf " removed" +' _ "$_ut_cli_root/remove-guard/functions.sh" 2>&1 || true)" +if [[ "$_ut_cli_guard_out" == "symlink-rc=2 removed" ]] \ + && _ut_cli_gone "$_ut_cli_win/.local/bin/claude.exe" \ + && _ut_cli_gone "$_ut_cli_win/.local/share/claude" \ + && [[ -d "$_ut_cli_win/.local/bin" && -d "$_ut_cli_win/.local/share" ]]; then + pass "uninstall: simulated Git Bash layout resolves claude.exe under USERPROFILE" +else + fail "uninstall: simulated Git Bash native CLI detection or removal misbehaved (got: $_ut_cli_guard_out)" +fi + _ut_host_claude_after="$(_ut_host_command_fingerprint claude)" _ut_host_safety_after="$(_ut_host_command_fingerprint cc-safety-net)" if [[ "$_ut_host_claude_before" == "$_ut_host_claude_after" \ diff --git a/uninstall.sh b/uninstall.sh index a1bd282..f330f7b 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1318,6 +1318,9 @@ _load_strings() { STR_CLI_UNINSTALL_FAILED="Claude Code CLI のアンインストールに失敗しました。手動で削除してください。" STR_CLI_UNINSTALL_SKIP="Claude Code CLI のアンインストールをスキップしました" STR_CLI_NOT_INSTALLED="Claude Code CLI はインストールされていません" + STR_CLI_UNINSTALL_MANUAL="インストール方法または配置を確認できないため、Claude Code CLI は自動削除しませんでした(検出: %s)。公式手順に沿って手動で削除してください:" + STR_CLI_UNINSTALL_KEPT_CONFIG="設定とセッション履歴(~/.claude、~/.claude.json)は削除していません" + STR_CLI_UNINSTALL_STILL_FOUND="claude コマンドがまだ見つかります: %s(別のインストールが残っている可能性があります)" STR_CODEX_PLUGIN_REMOVE_ASK="Codex プラグインを削除しますか? [y/N] " STR_CODEX_PLUGIN_REMOVED="Codex プラグインを削除しました" STR_CODEX_PLUGIN_REMOVE_FAILED="Codex プラグインの削除に失敗しました。手動で実行してください:" @@ -1354,6 +1357,9 @@ _load_strings() { STR_CLI_UNINSTALL_FAILED="Failed to uninstall Claude Code CLI. Please remove it manually." STR_CLI_UNINSTALL_SKIP="Skipped Claude Code CLI uninstall" STR_CLI_NOT_INSTALLED="Claude Code CLI is not installed" + STR_CLI_UNINSTALL_MANUAL="Could not confirm how Claude Code CLI was installed, so it was not removed automatically (found: %s). Remove it manually with the official steps:" + STR_CLI_UNINSTALL_KEPT_CONFIG="Settings and session history (~/.claude, ~/.claude.json) were not removed" + STR_CLI_UNINSTALL_STILL_FOUND="A claude command is still found: %s (another installation may remain)" STR_CODEX_PLUGIN_REMOVE_ASK="Remove Codex plugin? [y/N] " STR_CODEX_PLUGIN_REMOVED="Codex plugin removed" STR_CODEX_PLUGIN_REMOVE_FAILED="Failed to remove Codex plugin. Remove it manually:" @@ -1797,60 +1803,153 @@ fi # --------------------------------------------------------------------------- # Claude Code CLI uninstall # --------------------------------------------------------------------------- +# The CLI has no uninstall subcommand, and a word it does not know is taken as +# a prompt that starts a session. Removal therefore follows the documented +# per-method steps and never touches ~/.claude or ~/.claude.json, which hold +# settings and session history. +_CLAUDE_CLI_UNINSTALL_DOC="https://code.claude.com/docs/en/setup#uninstall-claude-code" +_CLAUDE_CLI_NATIVE_LAUNCHER="" +_CLAUDE_CLI_NATIVE_DATA="" + +_claude_cli_detect_native() { + # Return 0 and set _CLAUDE_CLI_NATIVE_LAUNCHER / _CLAUDE_CLI_NATIVE_DATA only + # for a native install in the documented default layout under the home + # directory. Return 1 when no native launcher exists, and 2 when one exists + # in any other shape (custom launcher, relocated or symlinked data + # directory); that shape is never removed automatically. + local base="${HOME:-}" launcher data target target_dir + _CLAUDE_CLI_NATIVE_LAUNCHER="" + _CLAUDE_CLI_NATIVE_DATA="" + if [[ "$_IS_MSYS" == "true" && -n "${USERPROFILE:-}" ]]; then + base="$(cygpath -u "$USERPROFILE" 2>/dev/null || true)" + fi + while [[ "$base" == */ ]]; do + base="${base%/}" + done + [[ -n "$base" && "$base" == /* ]] || return 1 + launcher="$base/.local/bin/claude" + [[ "$_IS_MSYS" != "true" ]] || launcher="$launcher.exe" + [[ -e "$launcher" || -L "$launcher" ]] || return 1 + + # The data directory is addressed by its physical path, so a symlink at + # ~/.local, ~/.local/share or ~/.local/share/claude fails the comparison. + base="$(cd -P "$base" 2>/dev/null && pwd -P)" || return 2 + data="$base/.local/share/claude" + [[ -d "$data" && ! -L "$data" ]] || return 2 + [[ "$(cd -P "$data" 2>/dev/null && pwd -P)" == "$data" ]] || return 2 + if [[ "$_IS_MSYS" == "true" ]]; then + [[ -f "$launcher" && ! -L "$launcher" ]] || return 2 + else + # A native launcher is a symlink into /versions; a regular file or a + # symlink to anywhere else is a custom launcher. + [[ -L "$launcher" ]] || return 2 + target="$(readlink "$launcher" 2>/dev/null)" || return 2 + [[ "$target" == /*/* ]] || return 2 + target_dir="$(cd -P "${target%/*}" 2>/dev/null && pwd -P)" || return 2 + [[ "$target_dir" == "$data/versions" ]] || return 2 + fi + _CLAUDE_CLI_NATIVE_LAUNCHER="$launcher" + _CLAUDE_CLI_NATIVE_DATA="$data" +} + +_claude_cli_remove_native() { # , as set by _claude_cli_detect_native + # The layout is detected again right before deleting and must still be the + # pair that was shown to the user. The recursive delete then runs from inside + # the verified parent on a real (non-symlink) child, so it cannot follow a + # path that changed in between or reach outside the home directory. + local launcher="$1" data="$2" parent + _claude_cli_detect_native || return 1 + [[ "$launcher" == "$_CLAUDE_CLI_NATIVE_LAUNCHER" \ + && "$data" == "$_CLAUDE_CLI_NATIVE_DATA" ]] || return 1 + parent="${data%/claude}" + [[ "$parent" == /* && "$parent/claude" == "$data" ]] || return 1 + rm -f -- "$launcher" 2>/dev/null || return 1 + ( + cd -P "$parent" 2>/dev/null || exit 1 + [[ "$(pwd -P)" == "$parent" && -d ./claude && ! -L ./claude ]] || exit 1 + rm -rf -- ./claude 2>/dev/null + ) || return 1 + [[ ! -e "$launcher" && ! -L "$launcher" && ! -e "$data" && ! -L "$data" ]] +} + +_claude_cli_manual_steps() { + info " $_CLAUDE_CLI_UNINSTALL_DOC" + if [[ "$_IS_MSYS" == "true" ]]; then + info " native: Remove-Item -Path \"\$env:USERPROFILE\\.local\\bin\\claude.exe\" -Force" + info " Remove-Item -Path \"\$env:USERPROFILE\\.local\\share\\claude\" -Recurse -Force" + info " WinGet: winget uninstall Anthropic.ClaudeCode" + else + info " native: rm -f ~/.local/bin/claude && rm -rf ~/.local/share/claude" + info " brew: brew uninstall --cask claude-code (or claude-code@latest)" + fi + info " npm: npm uninstall -g @anthropic-ai/claude-code" +} + if command -v claude &>/dev/null; then printf "\n" read -r -p "$STR_CLI_UNINSTALL_ASK " cli_confirm || cli_confirm="n" case "$cli_confirm" in y|Y|yes|YES) - if [[ "$_IS_MSYS" == "true" ]]; then - # Windows native (Git Bash): Claude was installed via PowerShell installer - # Binary is typically at %LOCALAPPDATA%\Programs\claude\claude.exe + _cli_found="$(command -v claude)" + _cli_removed=false + _cli_native_rc=0 + _claude_cli_detect_native || _cli_native_rc=$? + if [[ "$_cli_native_rc" -eq 0 ]]; then info "$STR_CLI_UNINSTALL_NATIVE" - _win_claude_dir="$(cygpath -u "${LOCALAPPDATA:-}/Programs/claude" 2>/dev/null)" - if [[ -n "$_win_claude_dir" ]] && [[ -d "$_win_claude_dir" ]]; then - rm -rf "$_win_claude_dir" 2>/dev/null && ok "$STR_CLI_UNINSTALL_DONE" || warn "$STR_CLI_UNINSTALL_FAILED" - elif claude uninstall 2>/dev/null; then + info " $_CLAUDE_CLI_NATIVE_LAUNCHER" + info " $_CLAUDE_CLI_NATIVE_DATA" + if _claude_cli_remove_native "$_CLAUDE_CLI_NATIVE_LAUNCHER" "$_CLAUDE_CLI_NATIVE_DATA"; then + ok "$STR_CLI_UNINSTALL_DONE" + _cli_removed=true + else + warn "$STR_CLI_UNINSTALL_FAILED" + _claude_cli_manual_steps + fi + elif [[ "$_cli_native_rc" -ne 1 ]]; then + # A launcher exists, but not in the default native layout. + # shellcheck disable=SC2059 + warn "$(printf "$STR_CLI_UNINSTALL_MANUAL" "$_cli_found")" + _claude_cli_manual_steps + elif npm list -g @anthropic-ai/claude-code &>/dev/null; then + info "$STR_CLI_UNINSTALL_NPM" + if npm uninstall -g @anthropic-ai/claude-code 2>/dev/null; then ok "$STR_CLI_UNINSTALL_DONE" + _cli_removed=true else warn "$STR_CLI_UNINSTALL_FAILED" + info " npm uninstall -g @anthropic-ai/claude-code" fi else - # Unix (macOS / Linux / WSL) - local_bin_claude="$HOME/.local/bin/claude" - if [[ -f "$local_bin_claude" ]] || [[ -L "$local_bin_claude" ]]; then - # Native installer: use claude uninstall - info "$STR_CLI_UNINSTALL_NATIVE" - if claude uninstall 2>/dev/null; then - ok "$STR_CLI_UNINSTALL_DONE" - else - # Fallback: remove binary directly - rm -f "$local_bin_claude" - ok "$STR_CLI_UNINSTALL_DONE" - fi - elif npm list -g @anthropic-ai/claude-code &>/dev/null 2>&1; then - # npm installation - info "$STR_CLI_UNINSTALL_NPM" - if npm uninstall -g @anthropic-ai/claude-code 2>/dev/null; then - ok "$STR_CLI_UNINSTALL_DONE" - else - warn "$STR_CLI_UNINSTALL_FAILED" - fi - elif brew list claude-code &>/dev/null 2>&1; then - # Homebrew installation + _cli_brew_cask="" + if [[ "$_IS_MSYS" != "true" ]]; then + for _cli_cask in claude-code claude-code@latest; do + if brew list --cask "$_cli_cask" &>/dev/null; then + _cli_brew_cask="$_cli_cask" + break + fi + done + fi + if [[ -n "$_cli_brew_cask" ]]; then info "$STR_CLI_UNINSTALL_BREW" - if brew uninstall claude-code 2>/dev/null; then + if brew uninstall --cask "$_cli_brew_cask" 2>/dev/null; then ok "$STR_CLI_UNINSTALL_DONE" + _cli_removed=true else warn "$STR_CLI_UNINSTALL_FAILED" + info " brew uninstall --cask $_cli_brew_cask" fi else - # Unknown installation method — try claude uninstall - info "$STR_CLI_UNINSTALL_NATIVE" - if claude uninstall 2>/dev/null; then - ok "$STR_CLI_UNINSTALL_DONE" - else - warn "$STR_CLI_UNINSTALL_FAILED" - fi + # shellcheck disable=SC2059 + warn "$(printf "$STR_CLI_UNINSTALL_MANUAL" "$_cli_found")" + _claude_cli_manual_steps + fi + fi + if [[ "$_cli_removed" == "true" ]]; then + info "$STR_CLI_UNINSTALL_KEPT_CONFIG" + hash -r 2>/dev/null || true + if command -v claude &>/dev/null; then + # shellcheck disable=SC2059 + warn "$(printf "$STR_CLI_UNINSTALL_STILL_FOUND" "$(command -v claude)")" fi fi ;; From e48c575de87df839ec1b68f7577981383c255615 Mon Sep 17 00:00:00 2001 From: okash1n <48118431+okash1n@users.noreply.github.com> Date: Tue, 6 Oct 2026 18:27:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20uninstall.sh=20=E3=81=AE=20CLI=20?= =?UTF-8?q?=E5=89=8A=E9=99=A4=E3=81=8C=20symlink=20=E3=81=AE=20~/.local/bi?= =?UTF-8?q?n=20=E7=B5=8C=E7=94=B1=E3=81=A7=20HOME=20=E5=A4=96=E3=82=92?= =?UTF-8?q?=E6=B6=88=E3=81=97=E5=BE=97=E3=81=9F=E5=95=8F=E9=A1=8C=E3=81=AA?= =?UTF-8?q?=E3=81=A9=E3=82=92=E4=BF=AE=E6=AD=A3=EF=BC=88v0.78.4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit claude uninstall 廃止の修正(#175)に対するレビュー指摘への対応。 - uninstall.sh: ネイティブ版の検出で、~/.local/bin の物理パスも既定の場所と 一致することを確認するようにした。これまでは ~/.local/bin が HOME 外への symlink でも、その中の claude が ~/.local/share/claude/versions/ 内を指して いれば既定配置と判定し、symlink の先にあるランチャーを削除していた。 ランチャーの削除も、データディレクトリと同じく物理パスを確認した親 ディレクトリの中から行う - uninstall.sh: 確認プロンプトの待機中に claude が PATH から消えると、y の 直後の command -v が失敗して何も表示せず終了コード 1 で終わっていた。 インストールされていないと表示して残りの処理を続ける - uninstall.sh: CLI 削除後の表示を「CLI の削除では ~/.claude と ~/.claude.json に触れていません」に改めた。同じ実行でキット管理ファイル (settings.json など)を削除した直後に「設定は削除していません」と読める 文言だった - tests/unit/test-uninstall.sh: symlink の ~/.local/bin、npm / Homebrew / ネイティブ版の削除失敗が失敗として表示されること、プロンプト待機中に claude が消えた場合の 5 件を追加し、既存 2 件に、検出後に ~/.local/bin が 差し替えられた場合の拒否と、Git Bash 擬似環境でデータディレクトリ・ ~/.local/bin が symlink の場合の拒否を加えた。CLI 削除の検証は計 18 件で、 main の uninstall.sh では 16 件が失敗する - README.md / README.en.md / CHANGELOG.md: 上記に合わせて記述と件数を更新 --- CHANGELOG.md | 6 +- README.en.md | 2 +- README.md | 2 +- tests/unit/test-uninstall.sh | 195 +++++++++++++++++++++++++++++++---- uninstall.sh | 43 +++++--- 5 files changed, 207 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff8caa0..deef802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this ### Fixed - **`uninstall.sh` が存在しない `claude uninstall` サブコマンドを呼んでいた問題を修正(#175)**: 「Claude Code CLI もアンインストールしますか?」に y と答えると、ネイティブ版(`~/.local/bin/claude` がある場合)、インストール方法を判別できない場合、Git Bash で `%LOCALAPPDATA%\Programs\claude` が無い場合に `claude uninstall` を実行していた。Claude Code 2.1.291 の `claude --help` のコマンド一覧に `uninstall` はなく、Usage は `claude [options] [command] [prompt]` なので、この語は削除コマンドではなくプロンプトとして渡る形になる(実 CLI で `claude uninstall` を実行した結果は確認していない)。ネイティブ版の分岐は、この呼び出しが失敗すると `~/.local/bin/claude` だけを削除して「アンインストールしました」と表示しており、ダウンロード済みの各バージョンが入った `~/.local/share/claude` が残っていた - - `claude uninstall` の呼び出しをすべてやめ、公式のアンインストール手順に合わせた。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude` を削除する。対象は既定の配置だと確認できた場合に限る(macOS / Linux / WSL では、ランチャーが `~/.local/share/claude/versions/` 内を指す symlink で、`~/.local/share/claude` が symlink を経由しない実ディレクトリであること)。削除の直前に同じ確認をやり直し、再帰削除はホームディレクトリ由来の固定パスに対してだけ行う。npm 版は従来どおり `npm uninstall -g @anthropic-ai/claude-code`、Homebrew 版は `brew uninstall --cask` を使い、これまで確認対象に入っていなかった `claude-code@latest` cask も検出する - - カスタムランチャー(`~/.local/bin/claude` が通常ファイルや別の場所を指す symlink)、`~/.local/share/claude` やその親が symlink の配置、`XDG_DATA_HOME` などで既定以外の場所へ移した配置、インストール方法を判別できない場合は自動削除せず、公式ドキュメントの URL と方法別の削除コマンドを表示する。削除に成功したあとも `claude` コマンドが見つかる場合は、別のインストールが残っている可能性を警告する + - `claude uninstall` の呼び出しをすべてやめ、公式のアンインストール手順に合わせた。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude` を削除する。対象は既定の配置だと確認できた場合に限る(macOS / Linux / WSL では、ランチャーが `~/.local/share/claude/versions/` 内を指す symlink で、`~/.local/bin` と `~/.local/share/claude` がどちらも symlink を経由しない実ディレクトリであること)。削除の直前に同じ確認をやり直し、ランチャーの削除と再帰削除は、ホームディレクトリ由来の固定パスに対してだけ、確認済みの親ディレクトリの中から行う。npm 版は従来どおり `npm uninstall -g @anthropic-ai/claude-code`、Homebrew 版は `brew uninstall --cask` を使い、これまで確認対象に入っていなかった `claude-code@latest` cask も検出する + - カスタムランチャー(`~/.local/bin/claude` が通常ファイルや別の場所を指す symlink)、`~/.local/bin`・`~/.local/share/claude` やその親が symlink の配置、`XDG_DATA_HOME` などで既定以外の場所へ移した配置、インストール方法を判別できない場合は自動削除せず、公式ドキュメントの URL と方法別の削除コマンドを表示する。削除に成功したあとも `claude` コマンドが見つかる場合は、別のインストールが残っている可能性を警告する。確認プロンプトの待機中に `claude` コマンドが見つからなくなった場合は、インストールされていないと表示して残りの処理を続ける - Git Bash では、公式手順に記載のない `%LOCALAPPDATA%\Programs\claude` の再帰削除をやめ、`%USERPROFILE%\.local\bin\claude.exe` と `%USERPROFILE%\.local\share\claude` を対象にした。旧配置にある CLI は自動削除されず、手動の手順が表示される。Git Bash の分岐は実機では未検証で、テストは `_IS_MSYS` を立てた擬似環境での確認にとどまる - 設定とセッション履歴(`~/.claude`、`~/.claude.json`)は従来どおり CLI の削除では触らず、削除後にその旨を表示する。確認プロンプトの数と順序、未入力(EOF)を「残す」として扱う点は変えていない - - **回帰テスト**: `tests/unit/test-uninstall.sh` に、使い捨ての HOME とスタブの `claude` / `npm` / `brew` で CLI 削除プロンプト以降の経路を確かめる検証を 13 件追加した(ネイティブ版の既定配置、カスタムランチャー、symlink のデータディレクトリ、symlink の親ディレクトリ、既定以外の場所への配置、判別不能、npm、Homebrew cask 2 種、n と EOF での辞退、削除関数が空・相対・HOME 外のパスを拒否すること、Git Bash 分岐の擬似環境)。修正前のコードでは 13 件中 11 件が失敗する(辞退の 2 件は従来から通る)。`tests/unit/test-codex-setup.sh` には、同梱スクリプトがコマンド位置で呼ぶ `claude <語>` / `_claude_cli <語>` の第 1 階層が、現在使っている `plugin` / `mcp` 以外でないことの静的検査を追加した。修正前のコードでは `uninstall.sh` の 3 箇所を検出する + - **回帰テスト**: `tests/unit/test-uninstall.sh` に、使い捨ての HOME とスタブの `claude` / `npm` / `brew` で CLI 削除プロンプト以降の経路を確かめる検証を 18 件追加した(ネイティブ版の既定配置、カスタムランチャー、symlink のデータディレクトリ、symlink の親ディレクトリ、symlink の `~/.local/bin`、既定以外の場所への配置、判別不能、npm、Homebrew cask 2 種、npm・Homebrew・ネイティブ版それぞれの削除失敗が完了ではなく失敗として表示されること、n と EOF での辞退、プロンプト待機中に `claude` が削除された場合、削除関数が空・相対・HOME 外のパスと、検出後に symlink へ差し替えられた `~/.local/bin` を拒否すること、Git Bash 分岐の擬似環境)。修正前のコードでは 18 件中 16 件が失敗する(辞退の 2 件は従来から通る)。`tests/unit/test-codex-setup.sh` には、同梱スクリプトがコマンド位置で呼ぶ `claude <語>` / `_claude_cli <語>` の第 1 階層が、現在使っている `plugin` / `mcp` 以外でないことの静的検査を追加した。修正前のコードでは `uninstall.sh` の 3 箇所を検出する - **既存インストールへの影響**: 以前に y を選んでランチャーだけが削除された環境には `~/.local/share/claude` が残っている場合がある。不要なら `rm -rf ~/.local/share/claude` で削除できる。今後ネイティブ版で y を選ぶと、これまで残っていた `~/.local/share/claude`(ダウンロード済みの全バージョン)も削除される ## [0.78.2] - 2026-10-06 diff --git a/README.en.md b/README.en.md index f444369..37476cf 100644 --- a/README.en.md +++ b/README.en.md @@ -509,7 +509,7 @@ Only files deployed by the starter kit (tracked in `~/.claude/.starter-kit-manif Some things the kit installed are offered rather than removed automatically, because they may outlive the kit: the Claude Code CLI, the Codex plugin, `cc-safety-net`, and local data under `~/.claude/security/` when the kit has a durable record of a verified `security-guidance` install. Regardless of fresh/update mode or legacy manifest selections, a plugin already present in the pre-install list is not adopted into this record, and its local data is not offered for cleanup. Each item is a separate prompt that defaults to keeping it. Accepting the local-data cleanup removes only known plugin-owned leaves such as its Python environments, session state, and logs; unknown files and directories in the shared location are preserved. Data moved elsewhere through environment-variable overrides is outside the cleanup scope. -Accepting the Claude Code CLI prompt removes only the CLI itself, following the official uninstall steps. A native install loses `~/.local/bin/claude` and `~/.local/share/claude` (the downloaded versions); an npm install or a Homebrew cask (`claude-code` / `claude-code@latest`) is removed with its own uninstall command. Settings and session history (`~/.claude`, `~/.claude.json`) are kept. When the install method or layout cannot be confirmed — a custom launcher, a symlinked data directory, or a location moved with `XDG_DATA_HOME` — nothing is removed automatically and the manual steps are shown instead. +Accepting the Claude Code CLI prompt removes only the CLI itself, following the official uninstall steps. A native install loses `~/.local/bin/claude` and `~/.local/share/claude` (the downloaded versions); an npm install or a Homebrew cask (`claude-code` / `claude-code@latest`) is removed with its own uninstall command. Removing the CLI does not touch settings or session history (`~/.claude`, `~/.claude.json`). When the install method or layout cannot be confirmed — a custom launcher, a symlinked `~/.local/bin` or data directory, or a location moved with `XDG_DATA_HOME` — nothing is removed automatically and the manual steps are shown instead. ## Development diff --git a/README.md b/README.md index ba7e86b..ad41ee8 100644 --- a/README.md +++ b/README.md @@ -1024,7 +1024,7 @@ cd claude-code-starter-kit キットが導入したもののうち、キットより長く使う可能性があるものは自動削除せず個別に確認します(既定はすべて「残す」)。対象は Claude Code CLI、Codex プラグイン、`cc-safety-net`、そしてキットによる検証済みの導入履歴が記録された `security-guidance` が `~/.claude/security/` に作るローカルデータです。fresh / update の別や旧 manifest の選択内容にかかわらず、セットアップの導入前一覧にすでに存在したプラグインはこの履歴に採用せず、そのローカルデータには削除を提示しません。ローカルデータの削除を選んでも、Python 仮想環境・セッション状態・ログ等の既知の plugin-owned leaf だけを削除し、同じディレクトリにある未知のファイルやディレクトリは保持します。環境変数で別の場所へ移したデータは対象外です。 -Claude Code CLI の削除を選ぶと、CLI 本体だけを公式のアンインストール手順どおりに削除します。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude`(ダウンロード済みの各バージョン)を削除し、npm 版と Homebrew cask(`claude-code` / `claude-code@latest`)はそれぞれのアンインストールコマンドを実行します。設定とセッション履歴(`~/.claude`、`~/.claude.json`)は残ります。カスタムランチャー、symlink になっているデータディレクトリ、`XDG_DATA_HOME` で移した配置など、インストール方法や配置を確認できない場合は自動削除せず、手動の手順を表示します。 +Claude Code CLI の削除を選ぶと、CLI 本体だけを公式のアンインストール手順どおりに削除します。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude`(ダウンロード済みの各バージョン)を削除し、npm 版と Homebrew cask(`claude-code` / `claude-code@latest`)はそれぞれのアンインストールコマンドを実行します。CLI の削除では、設定とセッション履歴(`~/.claude`、`~/.claude.json`)には触れません。カスタムランチャー、symlink になっている `~/.local/bin` やデータディレクトリ、`XDG_DATA_HOME` で移した配置など、インストール方法や配置を確認できない場合は自動削除せず、手動の手順を表示します。 --- diff --git a/tests/unit/test-uninstall.sh b/tests/unit/test-uninstall.sh index 0a18b55..2cea77d 100644 --- a/tests/unit/test-uninstall.sh +++ b/tests/unit/test-uninstall.sh @@ -1491,14 +1491,18 @@ _ut_cli_root="$_ut_tmp/cli-removal" _ut_cli_bin="$_ut_cli_root/bin" _ut_cli_bin_claude="$_ut_cli_root/bin-with-claude" mkdir -p "$_ut_cli_bin" "$_ut_cli_bin_claude" +# UNINSTALL_TOOL_UNINSTALL_FAILS=1 keeps the package listed but makes the +# uninstall itself fail, for the cases that pin the failure report. cat > "$_ut_cli_bin/npm" <<'EOF' #!/bin/bash printf 'npm %s\n' "$*" >> "${UNINSTALL_TOOL_LOG:-/dev/null}" +[[ "${UNINSTALL_TOOL_UNINSTALL_FAILS:-}" == "1" && "${1:-}" == "uninstall" ]] && exit 1 [[ "${UNINSTALL_NPM_HAS_CLAUDE:-}" == "1" && "$*" == *" @anthropic-ai/claude-code" ]] EOF cat > "$_ut_cli_bin/brew" <<'EOF' #!/bin/bash printf 'brew %s\n' "$*" >> "${UNINSTALL_TOOL_LOG:-/dev/null}" +[[ "${UNINSTALL_TOOL_UNINSTALL_FAILS:-}" == "1" && "${1:-}" == "uninstall" ]] && exit 1 [[ -n "${UNINSTALL_BREW_CASK:-}" && "$*" == *" --cask ${UNINSTALL_BREW_CASK}" ]] EOF cat > "$_ut_cli_bin_claude/claude" <<'EOF' @@ -1551,17 +1555,23 @@ _ut_cli_version_store() { # : versions/ holding a logging launcher tar printf 'older version\n' > "$1/versions/9.9.8" } -_ut_cli_run() { # [ENV=value ...]; sets _ut_cli_rc - local answers="$1" bin="$2" - shift 2 - _ut_cli_rc=0 - printf '%b' "$answers" | env -i HOME="$_ut_cli_home" TMPDIR="$_ut_cli_home/tmp" \ +_ut_cli_exec() { # [ENV=value ...]; answers on stdin + local bin="$1" + shift + env -i HOME="$_ut_cli_home" TMPDIR="$_ut_cli_home/tmp" \ APPDATA="$_ut_cli_home/appdata" LOCALAPPDATA="$_ut_cli_home/localappdata" \ NPM_CONFIG_PREFIX="$_ut_cli_home/npm" npm_config_prefix="$_ut_cli_home/npm" \ STARTER_KIT_DIR="$_ut_cli_home/nonexistent-kit" \ UNINSTALL_TOOL_LOG="$_ut_cli_log" \ PATH="$bin:/usr/bin:/bin:/usr/sbin:/sbin" LC_ALL=C TERM=dumb "$@" \ - bash "$PROJECT_DIR/uninstall.sh" > "$_ut_cli_out" 2>&1 || _ut_cli_rc=$? + bash "$PROJECT_DIR/uninstall.sh" > "$_ut_cli_out" 2>&1 +} + +_ut_cli_run() { # [ENV=value ...]; sets _ut_cli_rc + local answers="$1" + shift + _ut_cli_rc=0 + printf '%b' "$answers" | _ut_cli_exec "$@" || _ut_cli_rc=$? } _ut_cli_gone() { [[ ! -e "$1" && ! -L "$1" ]]; } @@ -1585,6 +1595,12 @@ _ut_cli_manual_only() { # manual steps shown, nothing uninstalled && ! grep -qE '^(npm|brew) uninstall' "$_ut_cli_log" } +_ut_cli_failure_reported() { # a failed removal is reported as failed, never as done + grep -q 'Failed to uninstall Claude Code CLI' "$_ut_cli_out" \ + && ! grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ + && ! grep -q 'did not touch' "$_ut_cli_out" +} + _ut_cli_fail() { # ; keeps the evidence in the test log fail "$1 (rc=$_ut_cli_rc)" { @@ -1605,7 +1621,7 @@ if _ut_cli_common_ok \ && _ut_cli_gone "$_ut_cli_home/.local/share/claude" \ && [[ -d "$_ut_cli_home/.local/bin" && -d "$_ut_cli_home/.local/share" ]] \ && grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ - && grep -q 'were not removed' "$_ut_cli_out" \ + && grep -q 'Removing the CLI did not touch' "$_ut_cli_out" \ && ! grep -q 'still found' "$_ut_cli_out" \ && ! grep -qE '^(npm|brew) uninstall' "$_ut_cli_log"; then pass "uninstall: native CLI in the default layout is removed with its version store" @@ -1661,6 +1677,25 @@ else _ut_cli_fail "uninstall: CLI removal crossed a symlinked ancestor" fi +# ~/.local/bin is a symlink to a directory outside HOME that holds a +# native-shaped launcher: removing "~/.local/bin/claude" would delete there. +_ut_cli_prepare bin-symlink +_ut_cli_external="$_ut_cli_root/bin-symlink/external-bin" +mkdir -p "$_ut_cli_external" +_ut_cli_version_store "$_ut_cli_home/.local/share/claude" +rmdir "$_ut_cli_home/.local/bin" +ln -s "$_ut_cli_external" "$_ut_cli_home/.local/bin" +ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_external/claude" +_ut_cli_run 'y\ny\n' "$_ut_cli_bin" +if _ut_cli_common_ok && _ut_cli_manual_only \ + && [[ -L "$_ut_cli_home/.local/bin" && -L "$_ut_cli_external/claude" ]] \ + && [[ -f "$_ut_cli_home/.local/share/claude/versions/9.9.9" \ + && -f "$_ut_cli_home/.local/share/claude/versions/9.9.8" ]]; then + pass "uninstall: launcher beneath a symlinked ~/.local/bin is kept with its version store" +else + _ut_cli_fail "uninstall: CLI removal deleted a launcher through a symlinked ~/.local/bin" +fi + # Launcher pointing outside ~/.local/share/claude (e.g. XDG_DATA_HOME): the # relocated store is not removed, and neither is the unrelated default path. _ut_cli_prepare relocated @@ -1700,7 +1735,7 @@ if _ut_cli_common_ok \ && grep -qx 'npm uninstall -g @anthropic-ai/claude-code' "$_ut_cli_log" \ && ! grep -q '^brew uninstall' "$_ut_cli_log" \ && grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ - && grep -q 'were not removed' "$_ut_cli_out" \ + && grep -q 'Removing the CLI did not touch' "$_ut_cli_out" \ && grep -qF "still found: $_ut_cli_bin_claude/claude" "$_ut_cli_out"; then pass "uninstall: npm CLI install is removed through npm uninstall -g" else @@ -1722,6 +1757,53 @@ for _ut_cli_cask in claude-code claude-code@latest; do fi done +# A removal that fails is reported as failed, with the way to finish by hand, +# and never as done. +_ut_cli_prepare npm-fails +_ut_cli_run 'y\ny\n' "$_ut_cli_bin_claude" UNINSTALL_NPM_HAS_CLAUDE=1 \ + UNINSTALL_TOOL_UNINSTALL_FAILS=1 +if _ut_cli_common_ok && _ut_cli_failure_reported \ + && grep -qx 'npm uninstall -g @anthropic-ai/claude-code' "$_ut_cli_log" \ + && grep -qF ' npm uninstall -g @anthropic-ai/claude-code' "$_ut_cli_out"; then + pass "uninstall: failed npm uninstall of the CLI is reported as a failure" +else + _ut_cli_fail "uninstall: failed npm uninstall of the CLI was not reported as a failure" +fi + +_ut_cli_prepare brew-fails +_ut_cli_run 'y\ny\n' "$_ut_cli_bin_claude" UNINSTALL_BREW_CASK=claude-code \ + UNINSTALL_TOOL_UNINSTALL_FAILS=1 +if _ut_cli_common_ok && _ut_cli_failure_reported \ + && grep -qx 'brew uninstall --cask claude-code' "$_ut_cli_log" \ + && grep -qF ' brew uninstall --cask claude-code' "$_ut_cli_out"; then + pass "uninstall: failed brew uninstall of the CLI is reported as a failure" +else + _ut_cli_fail "uninstall: failed brew uninstall of the CLI was not reported as a failure" +fi + +# Native: a read-only ~/.local/bin makes the launcher delete fail (root would +# ignore the permission, so the case is skipped there). +_ut_cli_prepare native-fails +_ut_cli_version_store "$_ut_cli_home/.local/share/claude" +ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" +if [[ "$(/usr/bin/id -u)" -eq 0 ]]; then + skip "uninstall: failed native CLI removal is reported as a failure" \ + "root ignores directory permissions" +else + chmod a-w "$_ut_cli_home/.local/bin" + _ut_cli_run 'y\ny\n' "$_ut_cli_bin" + chmod u+w "$_ut_cli_home/.local/bin" + if _ut_cli_common_ok && _ut_cli_failure_reported \ + && grep -qF 'https://code.claude.com/docs/en/setup#uninstall-claude-code' "$_ut_cli_out" \ + && [[ -L "$_ut_cli_home/.local/bin/claude" ]] \ + && [[ -f "$_ut_cli_home/.local/share/claude/versions/9.9.9" \ + && -f "$_ut_cli_home/.local/share/claude/versions/9.9.8" ]]; then + pass "uninstall: failed native CLI removal is reported as a failure" + else + _ut_cli_fail "uninstall: failed native CLI removal was not reported as a failure" + fi +fi + # Declining (an explicit "n", or EOF at the prompt) leaves a native install alone. for _ut_cli_answers in 'y\nn\n' 'y\n'; do _ut_cli_prepare "declined-${#_ut_cli_answers}" @@ -1741,11 +1823,49 @@ for _ut_cli_answers in 'y\nn\n' 'y\n'; do fi done +# The launcher disappears while the CLI prompt waits (removed from another +# terminal): the run says so and carries on to its end instead of dying on the +# second lookup. The prompt itself is not echoed on a pipe; the blank line it +# is preceded by is the only one that can follow the last Codex cleanup call, +# and it is printed after the existence check. +_ut_cli_prepare vanished +_ut_cli_version_store "$_ut_cli_home/.local/share/claude" +ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" +_ut_cli_prompt_seen="$_ut_cli_root/vanished/prompt-seen" +_ut_cli_rc=0 +{ + printf 'y\n' + _ut_poll=0 + while [[ "$_ut_poll" -lt 500 ]]; do + if grep -qx 'claude mcp list' "$_ut_cli_log" 2>/dev/null \ + && [[ -z "$(tail -n 1 "$_ut_cli_out" 2>/dev/null)" ]]; then + : > "$_ut_cli_prompt_seen" + break + fi + sleep 0.01 + _ut_poll=$((_ut_poll + 1)) + done + rm -f "$_ut_cli_home/.local/bin/claude" + printf 'y\n' +} | _ut_cli_exec "$_ut_cli_bin" || _ut_cli_rc=$? +if _ut_cli_common_ok \ + && [[ -f "$_ut_cli_prompt_seen" ]] \ + && grep -q 'Claude Code CLI is not installed' "$_ut_cli_out" \ + && grep -q 'user files remain' "$_ut_cli_out" \ + && ! grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ + && [[ -f "$_ut_cli_home/.local/share/claude/versions/9.9.9" ]]; then + pass "uninstall: CLI that vanishes while its prompt waits does not abort the run" +else + _ut_cli_fail "uninstall: run aborted or misreported when the CLI vanished at its prompt" +fi + # The removal helper deletes only the pair it has just re-verified under HOME. # Empty, relative (resolving to the real install from the working directory), # and native-shaped paths outside HOME must all be refused; the same call with # the detected pair must then succeed, which keeps the refusals from passing -# vacuously. +# vacuously. A pair that was valid when detected is refused as well once +# ~/.local/bin has been replaced by a symlink to a directory outside HOME +# holding a launcher of the same shape. _ut_cli_prepare remove-guard _ut_cli_version_store "$_ut_cli_home/.local/share/claude" ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_home/.local/bin/claude" @@ -1753,6 +1873,9 @@ _ut_cli_foreign="$_ut_cli_root/remove-guard/foreign" mkdir -p "$_ut_cli_foreign/.local/bin" _ut_cli_version_store "$_ut_cli_foreign/.local/share/claude" ln -s "$_ut_cli_foreign/.local/share/claude/versions/9.9.9" "$_ut_cli_foreign/.local/bin/claude" +_ut_cli_swapped="$_ut_cli_root/remove-guard/swapped-bin" +mkdir -p "$_ut_cli_swapped" +ln -s "$_ut_cli_home/.local/share/claude/versions/9.9.9" "$_ut_cli_swapped/claude" { _ut_extract_fn "$PROJECT_DIR/uninstall.sh" "_claude_cli_detect_native" _ut_extract_fn "$PROJECT_DIR/uninstall.sh" "_claude_cli_remove_native" @@ -1763,13 +1886,22 @@ _ut_cli_guard_out="$(cd "$_ut_cli_home" && env -i HOME="$_ut_cli_home" \ _IS_MSYS=false source "$1" accepted="" + _claude_cli_detect_native + launcher="$_CLAUDE_CLI_NATIVE_LAUNCHER" + data="$_CLAUDE_CLI_NATIVE_DATA" _claude_cli_remove_native "" "" && accepted="${accepted}empty " _claude_cli_remove_native ".local/bin/claude" ".local/share/claude" \ && accepted="${accepted}relative " _claude_cli_remove_native "$2/.local/bin/claude" "$2/.local/share/claude" \ && accepted="${accepted}foreign " - _claude_cli_remove_native "$HOME/.local/bin/claude" "$2/.local/share/claude" \ + _claude_cli_remove_native "$launcher" "$2/.local/share/claude" \ && accepted="${accepted}mixed " + mv "$HOME/.local/bin" "$HOME/.local/bin.real" + ln -s "$4" "$HOME/.local/bin" + _claude_cli_detect_native || printf "swapped-rc=%s " "$?" + _claude_cli_remove_native "$launcher" "$data" && accepted="${accepted}swapped " + rm -f "$HOME/.local/bin" + mv "$HOME/.local/bin.real" "$HOME/.local/bin" printf "accepted=[%s]" "$accepted" [[ -L "$HOME/.local/bin/claude" && -f "$HOME/.local/share/claude/versions/9.9.9" ]] \ && printf " kept" @@ -1780,10 +1912,11 @@ _ut_cli_guard_out="$(cd "$_ut_cli_home" && env -i HOME="$_ut_cli_home" \ && _claude_cli_remove_native "$_CLAUDE_CLI_NATIVE_LAUNCHER" "$_CLAUDE_CLI_NATIVE_DATA" \ && printf " removed" ' _ "$_ut_cli_root/remove-guard/functions.sh" "$_ut_cli_foreign" \ - "$_ut_cli_root/remove-guard" 2>&1 || true)" -if [[ "$_ut_cli_guard_out" == "accepted=[] kept relative-home-rc=1 removed" ]] \ + "$_ut_cli_root/remove-guard" "$_ut_cli_swapped" 2>&1 || true)" +if [[ "$_ut_cli_guard_out" == "swapped-rc=2 accepted=[] kept relative-home-rc=1 removed" ]] \ && _ut_cli_gone "$_ut_cli_home/.local/bin/claude" \ && _ut_cli_gone "$_ut_cli_home/.local/share/claude" \ + && [[ -L "$_ut_cli_swapped/claude" ]] \ && [[ -L "$_ut_cli_foreign/.local/bin/claude" ]] \ && [[ -f "$_ut_cli_foreign/.local/share/claude/versions/9.9.9" \ && -f "$_ut_cli_foreign/.local/share/claude/versions/9.9.8" ]]; then @@ -1795,9 +1928,14 @@ fi # Git Bash branch, simulated with _IS_MSYS=true and a pass-through cygpath (no # real Windows involved): the layout is looked up under USERPROFILE, the # launcher is the regular file claude.exe, and a symlink in its place is not a -# native install. +# native install. This branch has no launcher target to compare, so a data or +# launcher directory moved elsewhere and linked back is told apart from the +# default layout by the physical-path checks alone: each must be refused and +# leave claude.exe and the moved files in place. _ut_cli_win="$_ut_cli_root/remove-guard/winhome" -mkdir -p "$_ut_cli_win/.local/bin" "$_ut_cli_win/.local/share/claude/versions" +_ut_cli_win_external="$_ut_cli_root/remove-guard/win-external" +mkdir -p "$_ut_cli_win/.local/bin" "$_ut_cli_win/.local/share/claude/versions" \ + "$_ut_cli_win_external" printf 'binary\n' > "$_ut_cli_win/.local/bin/claude.exe" printf 'version\n' > "$_ut_cli_win/.local/share/claude/versions/9.9.9" _ut_cli_guard_out="$(env -i HOME="$_ut_cli_home" USERPROFILE="$_ut_cli_win" \ @@ -1806,17 +1944,32 @@ _ut_cli_guard_out="$(env -i HOME="$_ut_cli_home" USERPROFILE="$_ut_cli_win" \ _IS_MSYS=true cygpath() { printf "%s\n" "$2"; } source "$1" - mv "$USERPROFILE/.local/bin/claude.exe" "$USERPROFILE/.local/bin/real.exe" - ln -s "$USERPROFILE/.local/bin/real.exe" "$USERPROFILE/.local/bin/claude.exe" + win="$(cd -P "$USERPROFILE" && pwd -P)" + mv "$win/.local/bin/claude.exe" "$win/.local/bin/real.exe" + ln -s "$win/.local/bin/real.exe" "$win/.local/bin/claude.exe" _claude_cli_detect_native || printf "symlink-rc=%s" "$?" - rm -f "$USERPROFILE/.local/bin/claude.exe" - mv "$USERPROFILE/.local/bin/real.exe" "$USERPROFILE/.local/bin/claude.exe" + rm -f "$win/.local/bin/claude.exe" + mv "$win/.local/bin/real.exe" "$win/.local/bin/claude.exe" + for moved in data:share/claude bin:bin; do + label="${moved%%:*}" + moved="$win/.local/${moved#*:}" + mv "$moved" "$2/$label" + ln -s "$2/$label" "$moved" + _claude_cli_detect_native || printf " %s-symlink-rc=%s" "$label" "$?" + _claude_cli_remove_native "$win/.local/bin/claude.exe" "$win/.local/share/claude" \ + && printf " %s-symlink-removed" "$label" + rm -f "$moved" + mv "$2/$label" "$moved" + done + [[ -f "$win/.local/bin/claude.exe" && -f "$win/.local/share/claude/versions/9.9.9" ]] \ + && printf " kept" _claude_cli_detect_native \ - && [[ "$_CLAUDE_CLI_NATIVE_LAUNCHER" == "$USERPROFILE/.local/bin/claude.exe" ]] \ + && [[ "$_CLAUDE_CLI_NATIVE_LAUNCHER" == "$win/.local/bin/claude.exe" ]] \ && _claude_cli_remove_native "$_CLAUDE_CLI_NATIVE_LAUNCHER" "$_CLAUDE_CLI_NATIVE_DATA" \ && printf " removed" -' _ "$_ut_cli_root/remove-guard/functions.sh" 2>&1 || true)" -if [[ "$_ut_cli_guard_out" == "symlink-rc=2 removed" ]] \ +' _ "$_ut_cli_root/remove-guard/functions.sh" "$_ut_cli_win_external" 2>&1 || true)" +if [[ "$_ut_cli_guard_out" \ + == "symlink-rc=2 data-symlink-rc=2 bin-symlink-rc=2 kept removed" ]] \ && _ut_cli_gone "$_ut_cli_win/.local/bin/claude.exe" \ && _ut_cli_gone "$_ut_cli_win/.local/share/claude" \ && [[ -d "$_ut_cli_win/.local/bin" && -d "$_ut_cli_win/.local/share" ]]; then diff --git a/uninstall.sh b/uninstall.sh index f330f7b..c201c30 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1319,7 +1319,7 @@ _load_strings() { STR_CLI_UNINSTALL_SKIP="Claude Code CLI のアンインストールをスキップしました" STR_CLI_NOT_INSTALLED="Claude Code CLI はインストールされていません" STR_CLI_UNINSTALL_MANUAL="インストール方法または配置を確認できないため、Claude Code CLI は自動削除しませんでした(検出: %s)。公式手順に沿って手動で削除してください:" - STR_CLI_UNINSTALL_KEPT_CONFIG="設定とセッション履歴(~/.claude、~/.claude.json)は削除していません" + STR_CLI_UNINSTALL_KEPT_CONFIG="CLI の削除では ~/.claude と ~/.claude.json(設定とセッション履歴)に触れていません" STR_CLI_UNINSTALL_STILL_FOUND="claude コマンドがまだ見つかります: %s(別のインストールが残っている可能性があります)" STR_CODEX_PLUGIN_REMOVE_ASK="Codex プラグインを削除しますか? [y/N] " STR_CODEX_PLUGIN_REMOVED="Codex プラグインを削除しました" @@ -1358,7 +1358,7 @@ _load_strings() { STR_CLI_UNINSTALL_SKIP="Skipped Claude Code CLI uninstall" STR_CLI_NOT_INSTALLED="Claude Code CLI is not installed" STR_CLI_UNINSTALL_MANUAL="Could not confirm how Claude Code CLI was installed, so it was not removed automatically (found: %s). Remove it manually with the official steps:" - STR_CLI_UNINSTALL_KEPT_CONFIG="Settings and session history (~/.claude, ~/.claude.json) were not removed" + STR_CLI_UNINSTALL_KEPT_CONFIG="Removing the CLI did not touch ~/.claude or ~/.claude.json (settings and session history)" STR_CLI_UNINSTALL_STILL_FOUND="A claude command is still found: %s (another installation may remain)" STR_CODEX_PLUGIN_REMOVE_ASK="Remove Codex plugin? [y/N] " STR_CODEX_PLUGIN_REMOVED="Codex plugin removed" @@ -1815,9 +1815,9 @@ _claude_cli_detect_native() { # Return 0 and set _CLAUDE_CLI_NATIVE_LAUNCHER / _CLAUDE_CLI_NATIVE_DATA only # for a native install in the documented default layout under the home # directory. Return 1 when no native launcher exists, and 2 when one exists - # in any other shape (custom launcher, relocated or symlinked data - # directory); that shape is never removed automatically. - local base="${HOME:-}" launcher data target target_dir + # in any other shape (custom launcher, relocated or symlinked launcher or + # data directory); that shape is never removed automatically. + local base="${HOME:-}" bin launcher data target target_dir _CLAUDE_CLI_NATIVE_LAUNCHER="" _CLAUDE_CLI_NATIVE_DATA="" if [[ "$_IS_MSYS" == "true" && -n "${USERPROFILE:-}" ]]; then @@ -1831,9 +1831,13 @@ _claude_cli_detect_native() { [[ "$_IS_MSYS" != "true" ]] || launcher="$launcher.exe" [[ -e "$launcher" || -L "$launcher" ]] || return 1 - # The data directory is addressed by its physical path, so a symlink at - # ~/.local, ~/.local/share or ~/.local/share/claude fails the comparison. + # Both locations are addressed by their physical path, so a symlink at + # ~/.local, ~/.local/bin, ~/.local/share or ~/.local/share/claude fails the + # comparison instead of redirecting a delete to wherever it points. base="$(cd -P "$base" 2>/dev/null && pwd -P)" || return 2 + bin="$base/.local/bin" + [[ "$(cd -P "$bin" 2>/dev/null && pwd -P)" == "$bin" ]] || return 2 + launcher="$bin/${launcher##*/}" data="$base/.local/share/claude" [[ -d "$data" && ! -L "$data" ]] || return 2 [[ "$(cd -P "$data" 2>/dev/null && pwd -P)" == "$data" ]] || return 2 @@ -1854,16 +1858,22 @@ _claude_cli_detect_native() { _claude_cli_remove_native() { # , as set by _claude_cli_detect_native # The layout is detected again right before deleting and must still be the - # pair that was shown to the user. The recursive delete then runs from inside - # the verified parent on a real (non-symlink) child, so it cannot follow a - # path that changed in between or reach outside the home directory. - local launcher="$1" data="$2" parent + # pair that was shown to the user. Each delete then runs from inside its + # verified parent directory (the recursive one only on a real, non-symlink + # child), so it cannot follow a path that changed in between or reach outside + # the home directory. + local launcher="$1" data="$2" bin parent _claude_cli_detect_native || return 1 [[ "$launcher" == "$_CLAUDE_CLI_NATIVE_LAUNCHER" \ && "$data" == "$_CLAUDE_CLI_NATIVE_DATA" ]] || return 1 + bin="${launcher%/*}" parent="${data%/claude}" - [[ "$parent" == /* && "$parent/claude" == "$data" ]] || return 1 - rm -f -- "$launcher" 2>/dev/null || return 1 + [[ "$bin" == /* && "$parent" == /* && "$parent/claude" == "$data" ]] || return 1 + ( + cd -P "$bin" 2>/dev/null || exit 1 + [[ "$(pwd -P)" == "$bin" ]] || exit 1 + rm -f -- "./${launcher##*/}" 2>/dev/null + ) || return 1 ( cd -P "$parent" 2>/dev/null || exit 1 [[ "$(pwd -P)" == "$parent" && -d ./claude && ! -L ./claude ]] || exit 1 @@ -1890,11 +1900,14 @@ if command -v claude &>/dev/null; then read -r -p "$STR_CLI_UNINSTALL_ASK " cli_confirm || cli_confirm="n" case "$cli_confirm" in y|Y|yes|YES) - _cli_found="$(command -v claude)" + _cli_found="$(command -v claude 2>/dev/null || true)" _cli_removed=false _cli_native_rc=0 _claude_cli_detect_native || _cli_native_rc=$? - if [[ "$_cli_native_rc" -eq 0 ]]; then + if [[ -z "$_cli_found" ]]; then + # Gone since the check above: removed elsewhere while the prompt waited. + info "$STR_CLI_NOT_INSTALLED" + elif [[ "$_cli_native_rc" -eq 0 ]]; then info "$STR_CLI_UNINSTALL_NATIVE" info " $_CLAUDE_CLI_NATIVE_LAUNCHER" info " $_CLAUDE_CLI_NATIVE_DATA" From ba967b76982d6304a5730db608e2763003949626 Mon Sep 17 00:00:00 2001 From: okash1n <48118431+okash1n@users.noreply.github.com> Date: Tue, 6 Oct 2026 20:32:35 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20uninstall.sh=20=E3=81=8C=E6=97=A2?= =?UTF-8?q?=E5=AE=9A=E9=85=8D=E7=BD=AE=E4=BB=A5=E5=A4=96=E3=81=AE=20~/.loc?= =?UTF-8?q?al/bin/claude=20=E3=81=8C=E3=81=82=E3=82=8B=E3=81=A8=20npm=20/?= =?UTF-8?q?=20Homebrew=20=E7=89=88=E3=82=92=E5=89=8A=E9=99=A4=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=88v0.78.4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit claude uninstall 廃止の修正(#175)に対するレビュー指摘(2 巡目)への対応。 - uninstall.sh: ~/.local/bin/claude に既定配置以外のもの(カスタムランチャー、 別の場所を指す symlink など)があると、npm / Homebrew の確認に進まず、手動 手順だけを表示していた。npm の prefix を ~/.local にしている環境では npm 版 のリンクがこの場所にあるため、npm 版なのに npm uninstall -g が実行されず、 インストール方法を確認できないと表示されていた。既定配置のネイティブ版で ない場合は、ランチャーの有無にかかわらず npm、Homebrew cask の順に確認し、 どちらにも見つからない場合だけ手動手順を表示する。既定配置以外のランチャー 自体は引き続きこのスクリプトからは削除せず、残っていれば「まだ見つかり ます」の警告で知らせる - tests/unit/test-uninstall.sh: 上記の 2 件(npm の prefix が ~/.local の配置、 Homebrew cask とカスタムランチャーの併存)を追加した。Git Bash 擬似環境の 検証には、データディレクトリの親(.local/share)が symlink の場合の拒否を 加えた。これまではデータディレクトリの物理パス比較を外しても全件が通って いた。CLI 削除の検証は計 20 件で、main の uninstall.sh では 18 件が失敗する - README.md / README.en.md / CHANGELOG.md: 上記に合わせて記述と件数を更新 --- CHANGELOG.md | 4 +-- README.en.md | 2 +- README.md | 2 +- tests/unit/test-uninstall.sh | 52 +++++++++++++++++++++++++++++++----- uninstall.sh | 11 ++++---- 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index deef802..7f11807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this ### Fixed - **`uninstall.sh` が存在しない `claude uninstall` サブコマンドを呼んでいた問題を修正(#175)**: 「Claude Code CLI もアンインストールしますか?」に y と答えると、ネイティブ版(`~/.local/bin/claude` がある場合)、インストール方法を判別できない場合、Git Bash で `%LOCALAPPDATA%\Programs\claude` が無い場合に `claude uninstall` を実行していた。Claude Code 2.1.291 の `claude --help` のコマンド一覧に `uninstall` はなく、Usage は `claude [options] [command] [prompt]` なので、この語は削除コマンドではなくプロンプトとして渡る形になる(実 CLI で `claude uninstall` を実行した結果は確認していない)。ネイティブ版の分岐は、この呼び出しが失敗すると `~/.local/bin/claude` だけを削除して「アンインストールしました」と表示しており、ダウンロード済みの各バージョンが入った `~/.local/share/claude` が残っていた - `claude uninstall` の呼び出しをすべてやめ、公式のアンインストール手順に合わせた。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude` を削除する。対象は既定の配置だと確認できた場合に限る(macOS / Linux / WSL では、ランチャーが `~/.local/share/claude/versions/` 内を指す symlink で、`~/.local/bin` と `~/.local/share/claude` がどちらも symlink を経由しない実ディレクトリであること)。削除の直前に同じ確認をやり直し、ランチャーの削除と再帰削除は、ホームディレクトリ由来の固定パスに対してだけ、確認済みの親ディレクトリの中から行う。npm 版は従来どおり `npm uninstall -g @anthropic-ai/claude-code`、Homebrew 版は `brew uninstall --cask` を使い、これまで確認対象に入っていなかった `claude-code@latest` cask も検出する - - カスタムランチャー(`~/.local/bin/claude` が通常ファイルや別の場所を指す symlink)、`~/.local/bin`・`~/.local/share/claude` やその親が symlink の配置、`XDG_DATA_HOME` などで既定以外の場所へ移した配置、インストール方法を判別できない場合は自動削除せず、公式ドキュメントの URL と方法別の削除コマンドを表示する。削除に成功したあとも `claude` コマンドが見つかる場合は、別のインストールが残っている可能性を警告する。確認プロンプトの待機中に `claude` コマンドが見つからなくなった場合は、インストールされていないと表示して残りの処理を続ける + - カスタムランチャー(`~/.local/bin/claude` が通常ファイルや別の場所を指す symlink)、`~/.local/bin`・`~/.local/share/claude` やその親が symlink の配置、`XDG_DATA_HOME` などで既定以外の場所へ移した配置は、このスクリプトからは削除しない。その場合も npm と Homebrew には CLI が入っているかを確認し、見つかればそれぞれのアンインストールコマンドを実行する(npm の prefix を `~/.local` にしていて npm 版のリンクが `~/.local/bin/claude` にある環境や、Homebrew cask と古い自作スクリプトが併存する環境が該当する)。どちらにも見つからない場合と、インストール方法を判別できない場合は、公式ドキュメントの URL と方法別の削除コマンドを表示する。削除に成功したあとも `claude` コマンドが見つかる場合は、別のインストールが残っている可能性を警告する。確認プロンプトの待機中に `claude` コマンドが見つからなくなった場合は、インストールされていないと表示して残りの処理を続ける - Git Bash では、公式手順に記載のない `%LOCALAPPDATA%\Programs\claude` の再帰削除をやめ、`%USERPROFILE%\.local\bin\claude.exe` と `%USERPROFILE%\.local\share\claude` を対象にした。旧配置にある CLI は自動削除されず、手動の手順が表示される。Git Bash の分岐は実機では未検証で、テストは `_IS_MSYS` を立てた擬似環境での確認にとどまる - 設定とセッション履歴(`~/.claude`、`~/.claude.json`)は従来どおり CLI の削除では触らず、削除後にその旨を表示する。確認プロンプトの数と順序、未入力(EOF)を「残す」として扱う点は変えていない - - **回帰テスト**: `tests/unit/test-uninstall.sh` に、使い捨ての HOME とスタブの `claude` / `npm` / `brew` で CLI 削除プロンプト以降の経路を確かめる検証を 18 件追加した(ネイティブ版の既定配置、カスタムランチャー、symlink のデータディレクトリ、symlink の親ディレクトリ、symlink の `~/.local/bin`、既定以外の場所への配置、判別不能、npm、Homebrew cask 2 種、npm・Homebrew・ネイティブ版それぞれの削除失敗が完了ではなく失敗として表示されること、n と EOF での辞退、プロンプト待機中に `claude` が削除された場合、削除関数が空・相対・HOME 外のパスと、検出後に symlink へ差し替えられた `~/.local/bin` を拒否すること、Git Bash 分岐の擬似環境)。修正前のコードでは 18 件中 16 件が失敗する(辞退の 2 件は従来から通る)。`tests/unit/test-codex-setup.sh` には、同梱スクリプトがコマンド位置で呼ぶ `claude <語>` / `_claude_cli <語>` の第 1 階層が、現在使っている `plugin` / `mcp` 以外でないことの静的検査を追加した。修正前のコードでは `uninstall.sh` の 3 箇所を検出する + - **回帰テスト**: `tests/unit/test-uninstall.sh` に、使い捨ての HOME とスタブの `claude` / `npm` / `brew` で CLI 削除プロンプト以降の経路を確かめる検証を 20 件追加した(ネイティブ版の既定配置、カスタムランチャー、symlink のデータディレクトリ、symlink の親ディレクトリ、symlink の `~/.local/bin`、既定以外の場所への配置、判別不能、npm、Homebrew cask 2 種、`~/.local/bin/claude` に既定配置以外のランチャーがある状態の npm 版と Homebrew cask、npm・Homebrew・ネイティブ版それぞれの削除失敗が完了ではなく失敗として表示されること、n と EOF での辞退、プロンプト待機中に `claude` が削除された場合、削除関数が空・相対・HOME 外のパスと、検出後に symlink へ差し替えられた `~/.local/bin` を拒否すること、Git Bash 分岐の擬似環境)。修正前のコードでは 20 件中 18 件が失敗する(辞退の 2 件は従来から通る)。`tests/unit/test-codex-setup.sh` には、同梱スクリプトがコマンド位置で呼ぶ `claude <語>` / `_claude_cli <語>` の第 1 階層が、現在使っている `plugin` / `mcp` 以外でないことの静的検査を追加した。修正前のコードでは `uninstall.sh` の 3 箇所を検出する - **既存インストールへの影響**: 以前に y を選んでランチャーだけが削除された環境には `~/.local/share/claude` が残っている場合がある。不要なら `rm -rf ~/.local/share/claude` で削除できる。今後ネイティブ版で y を選ぶと、これまで残っていた `~/.local/share/claude`(ダウンロード済みの全バージョン)も削除される ## [0.78.2] - 2026-10-06 diff --git a/README.en.md b/README.en.md index 37476cf..4bd5363 100644 --- a/README.en.md +++ b/README.en.md @@ -509,7 +509,7 @@ Only files deployed by the starter kit (tracked in `~/.claude/.starter-kit-manif Some things the kit installed are offered rather than removed automatically, because they may outlive the kit: the Claude Code CLI, the Codex plugin, `cc-safety-net`, and local data under `~/.claude/security/` when the kit has a durable record of a verified `security-guidance` install. Regardless of fresh/update mode or legacy manifest selections, a plugin already present in the pre-install list is not adopted into this record, and its local data is not offered for cleanup. Each item is a separate prompt that defaults to keeping it. Accepting the local-data cleanup removes only known plugin-owned leaves such as its Python environments, session state, and logs; unknown files and directories in the shared location are preserved. Data moved elsewhere through environment-variable overrides is outside the cleanup scope. -Accepting the Claude Code CLI prompt removes only the CLI itself, following the official uninstall steps. A native install loses `~/.local/bin/claude` and `~/.local/share/claude` (the downloaded versions); an npm install or a Homebrew cask (`claude-code` / `claude-code@latest`) is removed with its own uninstall command. Removing the CLI does not touch settings or session history (`~/.claude`, `~/.claude.json`). When the install method or layout cannot be confirmed — a custom launcher, a symlinked `~/.local/bin` or data directory, or a location moved with `XDG_DATA_HOME` — nothing is removed automatically and the manual steps are shown instead. +Accepting the Claude Code CLI prompt removes only the CLI itself, following the official uninstall steps. A native install loses `~/.local/bin/claude` and `~/.local/share/claude` (the downloaded versions); an npm install or a Homebrew cask (`claude-code` / `claude-code@latest`) is removed with its own uninstall command. Removing the CLI does not touch settings or session history (`~/.claude`, `~/.claude.json`). A native install is removed only when it is confirmed to be in the default layout. A custom launcher, a symlinked `~/.local/bin` or data directory, or a location moved with `XDG_DATA_HOME` is never deleted by the script itself. An npm install or a Homebrew cask found in that situation is still removed with its own uninstall command; when neither is found, the manual steps are shown instead. ## Development diff --git a/README.md b/README.md index ad41ee8..965599c 100644 --- a/README.md +++ b/README.md @@ -1024,7 +1024,7 @@ cd claude-code-starter-kit キットが導入したもののうち、キットより長く使う可能性があるものは自動削除せず個別に確認します(既定はすべて「残す」)。対象は Claude Code CLI、Codex プラグイン、`cc-safety-net`、そしてキットによる検証済みの導入履歴が記録された `security-guidance` が `~/.claude/security/` に作るローカルデータです。fresh / update の別や旧 manifest の選択内容にかかわらず、セットアップの導入前一覧にすでに存在したプラグインはこの履歴に採用せず、そのローカルデータには削除を提示しません。ローカルデータの削除を選んでも、Python 仮想環境・セッション状態・ログ等の既知の plugin-owned leaf だけを削除し、同じディレクトリにある未知のファイルやディレクトリは保持します。環境変数で別の場所へ移したデータは対象外です。 -Claude Code CLI の削除を選ぶと、CLI 本体だけを公式のアンインストール手順どおりに削除します。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude`(ダウンロード済みの各バージョン)を削除し、npm 版と Homebrew cask(`claude-code` / `claude-code@latest`)はそれぞれのアンインストールコマンドを実行します。CLI の削除では、設定とセッション履歴(`~/.claude`、`~/.claude.json`)には触れません。カスタムランチャー、symlink になっている `~/.local/bin` やデータディレクトリ、`XDG_DATA_HOME` で移した配置など、インストール方法や配置を確認できない場合は自動削除せず、手動の手順を表示します。 +Claude Code CLI の削除を選ぶと、CLI 本体だけを公式のアンインストール手順どおりに削除します。ネイティブ版は `~/.local/bin/claude` と `~/.local/share/claude`(ダウンロード済みの各バージョン)を削除し、npm 版と Homebrew cask(`claude-code` / `claude-code@latest`)はそれぞれのアンインストールコマンドを実行します。CLI の削除では、設定とセッション履歴(`~/.claude`、`~/.claude.json`)には触れません。ネイティブ版として削除するのは、既定の配置だと確認できた場合だけです。カスタムランチャー、symlink になっている `~/.local/bin` やデータディレクトリ、`XDG_DATA_HOME` で移した配置は、このスクリプトからは削除しません。その場合も npm 版か Homebrew cask が見つかればそのアンインストールコマンドを実行し、見つからなければ手動の手順を表示します。 --- diff --git a/tests/unit/test-uninstall.sh b/tests/unit/test-uninstall.sh index 2cea77d..07e6401 100644 --- a/tests/unit/test-uninstall.sh +++ b/tests/unit/test-uninstall.sh @@ -1757,6 +1757,45 @@ for _ut_cli_cask in claude-code claude-code@latest; do fi done +# A launcher at ~/.local/bin/claude outside the default native layout does not +# hide an npm or Homebrew install. With npm's prefix set to ~/.local the +# launcher is npm's own relative link into lib/node_modules, and a stale custom +# script can sit there beside a Homebrew cask: each still goes to its package +# manager. The stubs unlink nothing, so the launcher surviving shows that the +# script deletes nothing at that path itself, and the leftover warning names it. +_ut_cli_prepare npm-prefix-local +_ut_cli_npm_pkg="$_ut_cli_home/.local/lib/node_modules/@anthropic-ai/claude-code" +mkdir -p "$_ut_cli_npm_pkg" +cp "$_ut_cli_bin_claude/claude" "$_ut_cli_npm_pkg/cli.js" +ln -s "../lib/node_modules/@anthropic-ai/claude-code/cli.js" "$_ut_cli_home/.local/bin/claude" +_ut_cli_run 'y\ny\n' "$_ut_cli_bin" UNINSTALL_NPM_HAS_CLAUDE=1 +if _ut_cli_common_ok \ + && grep -qx 'npm uninstall -g @anthropic-ai/claude-code' "$_ut_cli_log" \ + && ! grep -q '^brew uninstall' "$_ut_cli_log" \ + && grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ + && ! grep -q 'not removed automatically' "$_ut_cli_out" \ + && [[ -L "$_ut_cli_home/.local/bin/claude" && -f "$_ut_cli_npm_pkg/cli.js" ]] \ + && grep -qF "still found: $_ut_cli_home/.local/bin/claude" "$_ut_cli_out"; then + pass "uninstall: npm CLI linked at ~/.local/bin/claude (prefix ~/.local) is handed to npm uninstall -g" +else + _ut_cli_fail "uninstall: npm CLI linked at ~/.local/bin/claude was not handed to npm uninstall -g" +fi + +_ut_cli_prepare brew-custom-launcher +cp "$_ut_cli_bin_claude/claude" "$_ut_cli_home/.local/bin/claude" +_ut_cli_run 'y\ny\n' "$_ut_cli_bin" UNINSTALL_BREW_CASK=claude-code +if _ut_cli_common_ok \ + && grep -qx 'brew uninstall --cask claude-code' "$_ut_cli_log" \ + && ! grep -q '^npm uninstall' "$_ut_cli_log" \ + && grep -q 'Claude Code CLI uninstalled' "$_ut_cli_out" \ + && ! grep -q 'not removed automatically' "$_ut_cli_out" \ + && [[ -f "$_ut_cli_home/.local/bin/claude" && ! -L "$_ut_cli_home/.local/bin/claude" ]] \ + && grep -qF "still found: $_ut_cli_home/.local/bin/claude" "$_ut_cli_out"; then + pass "uninstall: Homebrew cask beside a custom ~/.local/bin/claude is removed and the launcher is kept" +else + _ut_cli_fail "uninstall: Homebrew cask beside a custom ~/.local/bin/claude was not handed to brew, or the launcher was removed" +fi + # A removal that fails is reported as failed, with the way to finish by hand, # and never as done. _ut_cli_prepare npm-fails @@ -1928,10 +1967,11 @@ fi # Git Bash branch, simulated with _IS_MSYS=true and a pass-through cygpath (no # real Windows involved): the layout is looked up under USERPROFILE, the # launcher is the regular file claude.exe, and a symlink in its place is not a -# native install. This branch has no launcher target to compare, so a data or -# launcher directory moved elsewhere and linked back is told apart from the -# default layout by the physical-path checks alone: each must be refused and -# leave claude.exe and the moved files in place. +# native install. This branch has no launcher target to compare, so a data +# directory, its parent (.local/share), or the launcher directory moved +# elsewhere and linked back is told apart from the default layout by the +# physical-path checks alone: each must be refused and leave claude.exe and +# the moved files in place. _ut_cli_win="$_ut_cli_root/remove-guard/winhome" _ut_cli_win_external="$_ut_cli_root/remove-guard/win-external" mkdir -p "$_ut_cli_win/.local/bin" "$_ut_cli_win/.local/share/claude/versions" \ @@ -1950,7 +1990,7 @@ _ut_cli_guard_out="$(env -i HOME="$_ut_cli_home" USERPROFILE="$_ut_cli_win" \ _claude_cli_detect_native || printf "symlink-rc=%s" "$?" rm -f "$win/.local/bin/claude.exe" mv "$win/.local/bin/real.exe" "$win/.local/bin/claude.exe" - for moved in data:share/claude bin:bin; do + for moved in data:share/claude bin:bin share:share; do label="${moved%%:*}" moved="$win/.local/${moved#*:}" mv "$moved" "$2/$label" @@ -1969,7 +2009,7 @@ _ut_cli_guard_out="$(env -i HOME="$_ut_cli_home" USERPROFILE="$_ut_cli_win" \ && printf " removed" ' _ "$_ut_cli_root/remove-guard/functions.sh" "$_ut_cli_win_external" 2>&1 || true)" if [[ "$_ut_cli_guard_out" \ - == "symlink-rc=2 data-symlink-rc=2 bin-symlink-rc=2 kept removed" ]] \ + == "symlink-rc=2 data-symlink-rc=2 bin-symlink-rc=2 share-symlink-rc=2 kept removed" ]] \ && _ut_cli_gone "$_ut_cli_win/.local/bin/claude.exe" \ && _ut_cli_gone "$_ut_cli_win/.local/share/claude" \ && [[ -d "$_ut_cli_win/.local/bin" && -d "$_ut_cli_win/.local/share" ]]; then diff --git a/uninstall.sh b/uninstall.sh index c201c30..dc1ebc1 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1816,7 +1816,7 @@ _claude_cli_detect_native() { # for a native install in the documented default layout under the home # directory. Return 1 when no native launcher exists, and 2 when one exists # in any other shape (custom launcher, relocated or symlinked launcher or - # data directory); that shape is never removed automatically. + # data directory); this script never deletes that shape itself. local base="${HOME:-}" bin launcher data target target_dir _CLAUDE_CLI_NATIVE_LAUNCHER="" _CLAUDE_CLI_NATIVE_DATA="" @@ -1918,11 +1918,10 @@ if command -v claude &>/dev/null; then warn "$STR_CLI_UNINSTALL_FAILED" _claude_cli_manual_steps fi - elif [[ "$_cli_native_rc" -ne 1 ]]; then - # A launcher exists, but not in the default native layout. - # shellcheck disable=SC2059 - warn "$(printf "$STR_CLI_UNINSTALL_MANUAL" "$_cli_found")" - _claude_cli_manual_steps + # No native install in the default layout. A launcher in any other shape + # (npm's own link when its prefix is ~/.local, a custom script) is left + # where it is; npm and Homebrew are still asked whether they own the CLI + # before falling back to the manual steps. elif npm list -g @anthropic-ai/claude-code &>/dev/null; then info "$STR_CLI_UNINSTALL_NPM" if npm uninstall -g @anthropic-ai/claude-code 2>/dev/null; then From d183db9b6a575eeb38033eec39e37452df237bdc Mon Sep 17 00:00:00 2001 From: okash1n <48118431+okash1n@users.noreply.github.com> Date: Wed, 7 Oct 2026 06:40:19 +0900 Subject: [PATCH 4/4] =?UTF-8?q?docs:=20CHANGELOG=20=E3=81=AE=E3=83=90?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E8=A6=8B=E5=87=BA=E3=81=97?= =?UTF-8?q?=E3=82=92=E3=83=AA=E3=83=AA=E3=83=BC=E3=82=B9=E9=A0=86=E3=81=A8?= =?UTF-8?q?=E6=97=A5=E4=BB=98=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f11807..c38b619 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/). -## [0.78.4] - 2026-10-06 +## [0.78.3] - 2026-10-07 ### Fixed - **`uninstall.sh` が存在しない `claude uninstall` サブコマンドを呼んでいた問題を修正(#175)**: 「Claude Code CLI もアンインストールしますか?」に y と答えると、ネイティブ版(`~/.local/bin/claude` がある場合)、インストール方法を判別できない場合、Git Bash で `%LOCALAPPDATA%\Programs\claude` が無い場合に `claude uninstall` を実行していた。Claude Code 2.1.291 の `claude --help` のコマンド一覧に `uninstall` はなく、Usage は `claude [options] [command] [prompt]` なので、この語は削除コマンドではなくプロンプトとして渡る形になる(実 CLI で `claude uninstall` を実行した結果は確認していない)。ネイティブ版の分岐は、この呼び出しが失敗すると `~/.local/bin/claude` だけを削除して「アンインストールしました」と表示しており、ダウンロード済みの各バージョンが入った `~/.local/share/claude` が残っていた