-
Notifications
You must be signed in to change notification settings - Fork 0
feat: migrate Claude Code installation from npm to native installer #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| #!/usr/bin/env bash | ||
| # ============================================================================ | ||
| # Claude Code Version Update Script | ||
| # @anthropic-ai/claude-code の最新バージョンをチェックして更新します | ||
| # Claude Code の最新バージョンに更新します(ネイティブインストーラー使用) | ||
| # ============================================================================ | ||
|
|
||
| set -euo pipefail | ||
|
|
@@ -18,75 +18,40 @@ log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; } | |
| log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } | ||
| log_error() { echo -e "${RED}[ERROR]${NC} $1"; } | ||
|
|
||
| # スクリプトのディレクトリを取得 | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" | ||
|
|
||
| GLOBAL_FILE="${PROJECT_ROOT}/npm/global.json" | ||
| PACKAGE="@anthropic-ai/claude-code" | ||
|
|
||
| log_info "Claude Code バージョン更新を開始します..." | ||
|
|
||
| # jqの存在確認 | ||
| if ! command -v jq &> /dev/null; then | ||
| log_error "jq が必要です。インストールしてください: brew install jq" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # npmの存在確認 | ||
| if ! command -v npm &> /dev/null; then | ||
| log_error "npm が必要です。" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # global.jsonの存在確認 | ||
| if [[ ! -f "$GLOBAL_FILE" ]]; then | ||
| log_error "global.json が見つかりません: ${GLOBAL_FILE}" | ||
| # claudeコマンドの存在確認 | ||
| if ! command -v claude &> /dev/null; then | ||
| log_error "Claude CLI が見つかりません。" | ||
| log_info "インストール方法: curl -fsSL https://claude.ai/install.sh | bash" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # 現在のバージョンを取得 | ||
| current_version=$(jq -r ".dependencies[\"${PACKAGE}\"].version" "$GLOBAL_FILE") | ||
| current_version=$(claude --version 2>/dev/null | head -1 || echo "unknown") | ||
| log_info "現在のバージョン: ${current_version}" | ||
|
|
||
| # 最新バージョンを取得 | ||
| log_info "最新バージョンを確認中..." | ||
| latest_version=$(npm view "$PACKAGE" version 2>/dev/null) | ||
|
|
||
| if [[ -z "$latest_version" ]]; then | ||
| log_error "最新バージョンの取得に失敗しました" | ||
| exit 1 | ||
| fi | ||
|
|
||
| log_info "最新バージョン: ${latest_version}" | ||
|
|
||
| # バージョン比較 | ||
| if [[ "$current_version" == "$latest_version" ]]; then | ||
| log_success "Claude Code は既に最新バージョンです (${current_version})" | ||
| exit 0 | ||
| fi | ||
| # 更新を実行 | ||
| log_info "Claude Code を更新中..." | ||
|
|
||
| log_warn "バージョンが異なります: ${current_version} → ${latest_version}" | ||
|
|
||
| # 更新するかどうかを確認(CI環境では自動的に更新) | ||
| if [[ "${CI:-false}" != "true" ]] && [[ "${AUTO_UPDATE:-false}" != "true" ]]; then | ||
| read -p "更新しますか? (y/N): " -n 1 -r | ||
| echo | ||
| if [[ ! $REPLY =~ ^[Yy]$ ]]; then | ||
| log_info "更新をキャンセルしました" | ||
| exit 0 | ||
| if claude update; then | ||
| new_version=$(claude --version 2>/dev/null | head -1 || echo "unknown") | ||
| if [[ "$current_version" == "$new_version" ]]; then | ||
| log_success "Claude Code は既に最新バージョンです (${current_version})" | ||
| else | ||
| log_success "Claude Code を ${current_version} → ${new_version} に更新しました" | ||
| fi | ||
| else | ||
| log_warn "claude update に失敗しました。再インストールを試みます..." | ||
| if curl -fsSL https://claude.ai/install.sh | bash; then | ||
| new_version=$(claude --version 2>/dev/null | head -1 || echo "unknown") | ||
| log_success "Claude Code を再インストールしました (${new_version})" | ||
| else | ||
| log_error "Claude Code の更新に失敗しました" | ||
| exit 1 | ||
| fi | ||
|
Comment on lines
+23
to
52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: Anthropic’s docs confirm Practical workaround (don’t rely on the exit code):
Example (bash): set -euo pipefail
before="$(claude --version | head -n1)"
out="$(claude update 2>&1 || true)"
after="$(claude --version | head -n1)"
if grep -qiE 'already up to date|no updates' <<<"$out"; then
exit 0
fi
# If it changed, also success
if [[ "$before" != "$after" ]]; then
exit 0
fi
# Otherwise treat as failure (unexpected state)
echo "$out" >&2
exit 1If you’re seeing “update available” prompts but Homebrew says everything is already up to date, that mismatch is a known/recurring packaging sync issue (brew lagging behind other release channels), so version-checking is especially important. [3] Sources
The script's reliance on Anthropic does not document the exit code contract for 🤖 Prompt for AI Agents |
||
| fi | ||
|
|
||
| # global.jsonを更新 | ||
| log_info "global.json を更新中..." | ||
| tmp_file=$(mktemp) | ||
| jq --arg version "$latest_version" \ | ||
| ".dependencies[\"${PACKAGE}\"].version = \$version" "$GLOBAL_FILE" > "$tmp_file" | ||
| mv "$tmp_file" "$GLOBAL_FILE" | ||
|
|
||
| log_success "Claude Code を ${current_version} → ${latest_version} に更新しました" | ||
|
|
||
| # リリースノートのURLを表示 | ||
| log_info "リリースノート: https://github.com/anthropics/claude-code/releases" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Claude Code native installer install.sh behavior root vs non-root HOME directory💡 Result:
Claude Code’s native installer script (the
curl …/install.sh | bashflow) installs into the invoking user’s home directory—it is **not a system-wide (/usr/local) installer.The script “adds a symlink to the installation at
~/.local/bin/claude”. That~resolves from$HOMEof the user running the script. So:~/.local/bin/claude. [1]sudo/ asroot: installs under root’s home, e.g./root/.local/bin/claude, and your normal user won’t see it in their~/.local/bin(unless you also adjust PATH). (This is the direct consequence of the installer targeting~/.local/bin.) [1]The installer may print setup notes about adding
~/.local/binto PATH; issues have been reported around the exact PATH snippet it prints, reinforcing that it’s managing a per-user~/.local/bininstall rather than a global one. [2]If you accidentally installed as root and want it under a specific user, rerun it as that user (or use something like
sudo -u <user> -H bash -c 'curl -fsSL https://claude.ai/install.sh | bash'soHOMEis the target user’s home).Sources:
[1] Claude Code troubleshooting docs (native installer symlink location
~/.local/bin/claude, and local migration notes)[2] GitHub issue reporting the installer’s PATH guidance for
~/.local/bin(shows installer’s per-user PATH expectations)Install Claude Code as
vscodeto avoid HOME/path mismatch.The installer runs as root, but the PATH is appended for
/home/vscode. The native installer installs to~/.local/bin(resolved from the invoking user's$HOME), so running it as root installs to/root/.local/bin. This binary is inaccessible to thevscodeuser. Additionally, the PATH variable in the original code ($HOME/.claude/local/bin) doesn't match the installer's actual output location ($HOME/.local/bin).Proposed fix
🤖 Prompt for AI Agents