3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows powershell に Claude Code を入れる。

Posted at

Windows で claude(Claude Code CLI)が「認識されません」になる問題を解消した手順まとめ【Qiita向け】

TL;DR

  • 原因は主に2つ:
    (1) Windows では Git Bash が必須bash.exe の場所を環境変数で教える必要がある)
    (2) ~\.local\bin が PATH に入っていないため claude.exe が見つからない
  • 解決は、公式ネイティブインストーラで再導入 → CLAUDE_CODE_GIT_BASH_PATH を設定 → ~\.local\bin を PATH へ追加 → PowerShell を再起動
  • 途中で npm ルートも試したが、PowerShell の ExecutionPolicy に阻まれた(npm.ps1 が実行不可)。今回は ネイティブインストールで解決

環境

  • Windows(PowerShell)
  • Node.js LTS は後から導入(結果として今回は未使用でもOK)
  • OneDrive 配下にプロジェクトがあるが、今回の原因とは無関係

症状

PS> claude --version
claude : 用語 'claude' は…認識されません

where claude もヒットしない。
irm https://claude.ai/install.ps1 | iex を実行しても、直後の同セッションでは claude が見つからないことがある。


原因の切り分けポイント

  1. Git Bash の必須要件
    Claude Code の Windows ネイティブ版は Git Bash を使う前提。
    CLAUDE_CODE_GIT_BASH_PATHbash.exe のフルパスが必要。

  2. PATH に ~\.local\bin がない
    ネイティブインストーラは通常、claude.exe
    C:\Users\<User>\.local\bin\claude.exe に配置。
    → このディレクトリを ユーザー PATH に追加し、コンソールを再起動しないと見つからない。

  3. (回避可)npm ルートの落とし穴
    npm install -g @anthropic-ai/claude-code を使う場合、PowerShell の ExecutionPolicy によって npm.ps1 が止まることがある(UnauthorizedAccess)。


実際に効いた手順(コピペ可)

1) Git Bash を用意して場所を教える

# Git for Windows(未導入なら)
winget install --id Git.Git -e --source winget

# bash.exe の代表的な場所を探索して環境変数に登録
$gitBash = @(
  "C:\Program Files\Git\bin\bash.exe",
  "C:\Program Files\Git\usr\bin\bash.exe",
  "C:\Program Files (x86)\Git\bin\bash.exe",
  "C:\Program Files (x86)\Git\usr\bin\bash.exe"
) | Where-Object { Test-Path $_ } | Select-Object -First 1

[Environment]::SetEnvironmentVariable('CLAUDE_CODE_GIT_BASH_PATH', $gitBash, 'User')
$env:CLAUDE_CODE_GIT_BASH_PATH = $gitBash  # 今のセッションにも反映

# 確認(例)
$env:CLAUDE_CODE_GIT_BASH_PATH
# => C:\Program Files\Git\bin\bash.exe

2) 公式ネイティブインストーラで導入(上書きOK)

irm https://claude.ai/install.ps1 | iex
# 例)出力
# Version: 1.0.89
# Location: C:\Users\<User>\.local\bin\claude.exe

3) ~\.local\bin を PATH に追加

$localBin = Join-Path $HOME ".local\bin"
New-Item -ItemType Directory -Force -Path $localBin | Out-Null

$uPath = [Environment]::GetEnvironmentVariable('Path','User')
if ($uPath -notmatch [regex]::Escape($localBin)) {
  [Environment]::SetEnvironmentVariable('Path', $uPath + ";" + $localBin, 'User')
}

# 今のセッションにも反映(※完全反映には再起動が確実)
$env:Path = [Environment]::GetEnvironmentVariable('Path','User') + ';' +
            [Environment]::GetEnvironmentVariable('Path','Machine')

4) いったん PowerShell を閉じて 開き直す → 動作確認

where claude
claude --version
claude doctor

実行ログの要点(今回の決め手)

  • インストーラは成功していた:
    Location: C:\Users\yt\.local\bin\claude.exe
  • しかし PATH に ~\.local\bin が無いので claude 未検出。
  • CLAUDE_CODE_GIT_BASH_PATHC:\Program Files\Git\bin\bash.exe に設定。
  • ~\.local\bin をユーザー PATH に追加。
  • PowerShell を再起動claude --version が通る。

npm ルートで入れたい人向け(参考)

PowerShell で npmUnauthorizedAccess になる場合はどれかで回避:

A) ExecutionPolicy を緩める(カレントユーザーのみ)

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

B) npm.cmd を明示的に呼ぶ

& "C:\Program Files\nodejs\npm.cmd" -v
& "C:\Program Files\nodejs\npm.cmd" install -g @anthropic-ai/claude-code

C) そもそも cmd.exe で実行する(PowerShell 経由でない)

cmd /c "npm -v && npm install -g @anthropic-ai/claude-code"

ただし Windows での必須条件(Git Bash の用意 & パス設定)は npm ルートでも同じ
npm で入れた後は、npm のグローバル実行パス(例: %AppData%\npm を PATH に通すのを忘れずに。


よくあるハマりどころ

  • コンソール再起動を忘れる
    ユーザー PATH の変更は 新しい PowerShell から反映されます。
  • Git Bash 未導入 or パス未設定
    CLAUDE_CODE_GIT_BASH_PATH を必ずチェック。
  • PowerShell 5.1 と 7 で微妙にコマンドが違う
    例:$PSStyle.OutputRendering は PS7 以降。5.1 では未定義なので無視してOK。
  • OneDrive 直下のプロジェクト
    今回は無関係でしたが、同期中のロックや長いパスに注意(\\?\ プレフィックスで回避可)。

動作テスト(任意)

cd "C:\Users\<User>\OneDrive\ドキュメント\kanji_assign_no_api\kanji_assign_no_api"
claude
# 初回はブラウザでログイン案内
# 起動したら /help を表示、プロジェクトの RUNBOOK.md を要約させる等で確認

まとめ

  • 勝ち筋は「ネイティブインストーラ + Git Bash パス設定 + ~\.local\bin を PATH + シェル再起動」。
  • npm ルートは ExecutionPolicy の回避が必要な場合があるため、まずはネイティブインストーラが簡単&確実。
  • どのルートでも、Git Bash の用意PATH 反映が鍵でした。

付録:確認コマンド集

# Claude の所在
where claude

# ネイティブ配置の中身
Get-ChildItem $HOME\.local\bin -Force

# Git Bash の設定
echo $env:CLAUDE_CODE_GIT_BASH_PATH
Test-Path $env:CLAUDE_CODE_GIT_BASH_PATH

# Node / npm
where node; node -v
where npm;  npm -v   # 実行不可なら npm.cmd の方を試す

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?