Claude Code Update Auto:自動更新の設定と管理ガイド

Claude Codeを常に最新の状態に保ちたいけど、毎回手動で更新するのは面倒…そんな方のために、自動更新の設定方法と管理のベストプラクティスを詳しく解説します。

40 min read

Claude Codeを常に最新の状態に保ちたいけど、毎回手動で更新するのは面倒…そんな方のために、自動更新の設定方法と管理のベストプラクティスを詳しく解説します。

Claude Codeの自動更新機能

組み込みの自動更新

Claude Codeには自動更新チェック機能が組み込まれています:

# 起動時に更新チェックが行われる
claude

# 更新がある場合のメッセージ例
# Update available: 1.0.50 → 1.0.55
# Run 'npm install -g @anthropic-ai/claude-code@latest' to update

自動更新の有効化/無効化

# 自動更新チェックの設定確認
claude config get autoUpdate

# 自動更新チェックを有効化
claude config set autoUpdate true

# 自動更新チェックを無効化
claude config set autoUpdate false

自動更新スクリプトの作成

シンプルな自動更新スクリプト

auto-update-claude.sh:

#!/bin/bash
# Claude Code自動更新スクリプト

LOG_FILE="$HOME/.claude/update.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')

# 現在のバージョン取得
CURRENT=$(claude --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)

# 最新バージョン取得
LATEST=$(npm view @anthropic-ai/claude-code version 2>/dev/null)

# ログに記録
echo "[$TIMESTAMP] Current: $CURRENT, Latest: $LATEST" >> "$LOG_FILE"

# 更新が必要な場合
if [ "$CURRENT" != "$LATEST" ] && [ -n "$LATEST" ]; then
    echo "[$TIMESTAMP] Updating Claude Code..." >> "$LOG_FILE"
    npm install -g @anthropic-ai/claude-code@latest >> "$LOG_FILE" 2>&1

    NEW_VERSION=$(claude --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
    echo "[$TIMESTAMP] Updated to: $NEW_VERSION" >> "$LOG_FILE"
else
    echo "[$TIMESTAMP] Already up to date" >> "$LOG_FILE"
fi

実行権限の付与

chmod +x auto-update-claude.sh

定期実行の設定

cron(macOS/Linux)

# cronエディタを開く
crontab -e

# 毎日午前3時に自動更新(例)
0 3 * * * /path/to/auto-update-claude.sh

# 毎週月曜日の午前9時に自動更新
0 9 * * 1 /path/to/auto-update-claude.sh

# 毎月1日に自動更新
0 0 1 * * /path/to/auto-update-claude.sh

launchd(macOS推奨)

~/Library/LaunchAgents/com.claude.code.autoupdate.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.claude.code.autoupdate</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>/Users/username/scripts/auto-update-claude.sh</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>9</integer>
        <key>Minute</key>
        <integer>0</integer>
        <key>Weekday</key>
        <integer>1</integer>
    </dict>
    <key>StandardOutPath</key>
    <string>/Users/username/.claude/launchd-out.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/username/.claude/launchd-err.log</string>
</dict>
</plist>
# 読み込み
launchctl load ~/Library/LaunchAgents/com.claude.code.autoupdate.plist

# 状態確認
launchctl list | grep claude

# 無効化
launchctl unload ~/Library/LaunchAgents/com.claude.code.autoupdate.plist

systemd(Linux)

/etc/systemd/system/claude-code-update.service:

[Unit]
Description=Claude Code Auto Update
After=network-online.target

[Service]
Type=oneshot
ExecStart=/path/to/auto-update-claude.sh
User=username

[Install]
WantedBy=multi-user.target

/etc/systemd/system/claude-code-update.timer:

[Unit]
Description=Weekly Claude Code Update

[Timer]
OnCalendar=Mon 09:00
Persistent=true

[Install]
WantedBy=timers.target
# 有効化
sudo systemctl enable claude-code-update.timer
sudo systemctl start claude-code-update.timer

# 状態確認
systemctl status claude-code-update.timer

高度な自動更新設定

条件付き自動更新

smart-update-claude.sh:

#!/bin/bash
# 条件付き自動更新スクリプト

# 設定
MIN_UPTIME_HOURS=2  # 起動後2時間経過してから更新
SKIP_MAJOR=true     # メジャーアップデートはスキップ

# 現在のバージョン
CURRENT=$(claude --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
LATEST=$(npm view @anthropic-ai/claude-code version 2>/dev/null)

# メジャーバージョン抽出
CURRENT_MAJOR=$(echo "$CURRENT" | cut -d. -f1)
LATEST_MAJOR=$(echo "$LATEST" | cut -d. -f1)

# メジャーアップデートチェック
if [ "$SKIP_MAJOR" = true ] && [ "$CURRENT_MAJOR" != "$LATEST_MAJOR" ]; then
    echo "Major update detected. Skipping automatic update."
    echo "Current: $CURRENT, Latest: $LATEST"
    echo "Run manually: npm install -g @anthropic-ai/claude-code@latest"
    exit 0
fi

# 更新実行
if [ "$CURRENT" != "$LATEST" ]; then
    npm install -g @anthropic-ai/claude-code@latest
    echo "Updated from $CURRENT to $LATEST"
fi

通知付き自動更新

update-with-notification.sh:

#!/bin/bash
# 通知付き自動更新(macOS)

CURRENT=$(claude --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
LATEST=$(npm view @anthropic-ai/claude-code version 2>/dev/null)

if [ "$CURRENT" != "$LATEST" ]; then
    npm install -g @anthropic-ai/claude-code@latest

    # macOS通知
    osascript -e "display notification \"Updated from $CURRENT to $LATEST\" with title \"Claude Code Updated\""

    # または terminal-notifier を使用
    # terminal-notifier -title "Claude Code" -message "Updated to $LATEST"
fi

GitHub Actionsでの自動更新チェック

更新通知ワークフロー

# .github/workflows/claude-update-check.yml
name: Claude Code Update Check

on:
  schedule:
    - cron: '0 9 * * 1'  # 毎週月曜9時
  workflow_dispatch:

jobs:
  check-update:
    runs-on: ubuntu-latest
    steps:
      - name: Check Claude Code version
        id: version
        run: |
          LATEST=$(npm view @anthropic-ai/claude-code version)
          echo "latest=$LATEST" >> $GITHUB_OUTPUT
          echo "Latest version: $LATEST"

      - name: Create issue if update available
        if: steps.version.outputs.latest != env.CURRENT_VERSION
        uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.create({
              owner: context.repo.owner,
              repo: context.repo.repo,
              title: 'Claude Code Update Available',
              body: 'New version: ${{ steps.version.outputs.latest }}'
            })

自動更新を無効にする場合

更新チェックの無効化

# 環境変数で無効化
export CLAUDE_DISABLE_UPDATE_CHECK=1

# ~/.bashrc または ~/.zshrc に追加
echo 'export CLAUDE_DISABLE_UPDATE_CHECK=1' >> ~/.zshrc

特定バージョンに固定

# バージョンを固定してインストール
npm install -g @anthropic-ai/claude-code@1.0.50

# package.jsonでチーム全体を固定
# "devDependencies": {
#   "@anthropic-ai/claude-code": "1.0.50"
# }

ベストプラクティス

1. 更新タイミングの選択

シナリオ

推奨頻度

理由

個人開発

毎週

新機能を早く試せる

チーム開発

隔週〜月1

安定性重視

本番環境

月1〜手動

十分なテストが必要

2. 更新前のバックアップ

# 自動更新スクリプトにバックアップを追加
cp -r ~/.claude ~/.claude.backup.$(date +%Y%m%d) 2>/dev/null

3. 更新ログの保持

# ログローテーション
find ~/.claude -name "update.log.*" -mtime +30 -delete

まとめ

Claude Codeの自動更新設定のポイント:

  • 組み込み機能:起動時の更新チェックを活用
  • 定期実行:cron/launchd/systemdで自動化
  • 条件付き:メジャーアップデートは手動確認を推奨
  • 通知設定:更新時に通知を受け取る
  • ログ管理:更新履歴を記録

自動更新を適切に設定することで、常に最新の機能とセキュリティ修正を享受できます。

Related Articles