🛠️ Windows Shell Reliability
Windows環境でコマンドを確実に実行するため、ファイルや
📺 まず動画で見る(YouTube)
▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
Reliable command execution on Windows: paths, encoding, and common binary pitfalls.
🇯🇵 日本人クリエイター向け解説
Windows環境でコマンドを確実に実行するため、ファイルや
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o windows-shell-reliability.zip https://jpskill.com/download/3712.zip && unzip -o windows-shell-reliability.zip && rm windows-shell-reliability.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/3712.zip -OutFile "$d\windows-shell-reliability.zip"; Expand-Archive "$d\windows-shell-reliability.zip" -DestinationPath $d -Force; ri "$d\windows-shell-reliability.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
windows-shell-reliability.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
windows-shell-reliabilityフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Windows Shell Reliability を使って、最小構成のサンプルコードを示して
- › Windows Shell Reliability の主な使い方と注意点を教えて
- › Windows Shell Reliability を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Windows Shell の信頼性パターン
PowerShell と CMD を介して Windows でコマンドを実行するためのベストプラクティスです。
使用する場面
Windows システムで実行されるスクリプトや自動化を開発またはデバッグする際に、特にファイルパス、文字エンコーディング、または標準 CLI ツールが関係する場合に、このスキルを使用してください。
1. エンコーディングとリダイレクト
重要: PowerShell バージョン間のリダイレクトの違い
古い Windows PowerShell リリースでは、ネイティブコマンドの出力を、その後の処理を壊すような方法で書き換えることがあります。PowerShell 7.4 以降では、stdout をリダイレクトする際にバイトストリームを保持するため、UTF-8 変換の回避策は、古いシェルの動作や、すでに読み取り不能なログファイルを扱っている場合にのみ適用してください。
| 問題 | 症状 | 解決策 |
|---|---|---|
dotnet > log.txt |
古い Windows PowerShell で view_file が失敗する |
Get-Content log.txt | Set-Content -Encoding utf8 log_utf8.txt |
npm run > log.txt |
エラーを含む UTF-8 テキストログが必要 | npm run ... 2>&1 | Out-File -Encoding UTF8 log.txt |
ルール: PowerShell 7.4 以降ではネイティブのリダイレクトをそのまま使用し、古い Windows PowerShell のリダイレクトが読み取り不能なログを生成する場合にのみ、明示的な UTF-8 変換を使用してください。
2. パスとスペースの処理
重要: クォーティング
Windows のパスにはスペースが含まれることがよくあります。
| ❌ 間違い | ✅ 正しい |
|---|---|
dotnet build src/my project/file.fsproj |
dotnet build "src/my project/file.fsproj" |
& C:\Path With Spaces\bin.exe |
& "C:\Path With Spaces\bin.exe" |
ルール: スペースを含む可能性のある絶対パスと相対パスは常に引用符で囲んでください。
呼び出し演算子 (&)
PowerShell では、実行可能ファイルのパスが引用符で始まる場合、& 演算子を使用する必要があります。
パターン:
& "C:\Program Files\dotnet\dotnet.exe" build ...
3. 一般的なバイナリとコマンドレットの落とし穴
| アクション | ❌ CMD スタイル | ✅ PowerShell の選択肢 |
|---|---|---|
| 削除 | del /f /q file |
Remove-Item -Force file |
| コピー | copy a b |
Copy-Item a b |
| 移動 | move a b |
Move-Item a b |
| ディレクトリ作成 | mkdir folder |
New-Item -ItemType Directory -Path folder |
ヒント: PowerShell で ls、cat、cp のような CLI エイリアスを使用することは通常問題ありませんが、スクリプトで完全なコマンドレットを使用する方がより堅牢です。
4. Dotnet CLI の信頼性
ビルド速度と一貫性
| コンテキスト | コマンド | 理由 |
|---|---|---|
| 高速イテレーション | dotnet build --no-restore |
不要な nuget restore をスキップします。 |
| クリーンビルド | dotnet build --no-incremental |
古い成果物が残らないようにします。 |
| バックグラウンド | Start-Process dotnet -ArgumentList 'run' -RedirectStandardOutput output.txt -RedirectStandardError error.txt |
シェルをブロックせずにアプリを起動し、ログを保持します。 |
5. 環境変数
| シェル | 構文 |
|---|---|
| PowerShell | $env:VARIABLE_NAME |
| CMD | %VARIABLE_NAME% |
6. 長いパス
Windows には、デフォルトで 260 文字のパス制限があります。
修正: 長いパスエラーが発生した場合は、拡張パスプレフィックスを使用してください。
\\?\C:\Very\Long\Path\...
7. シェルエラーのトラブルシューティング
| エラー | 考えられる原因 | 修正 |
|---|---|---|
The term 'xxx' is not recognized |
パスが $env:PATH にない | 絶対パスを使用するか、PATH を修正してください。 |
Access to the path is denied |
ファイルが使用中またはアクセス許可の問題 | プロセスを停止するか、管理者として実行してください。 |
Encoding mismatch |
古いシェルのリダイレクトが出力を書き換えた | ファイルを UTF-8 として再エクスポートするか、2>&1 | Out-File -Encoding UTF8 でキャプチャしてください。 |
制限事項
- このスキルは、タスクが上記で説明した範囲と明確に一致する場合にのみ使用してください。
- 出力を、環境固有の検証、テスト、または専門家によるレビューの代わりとして扱わないでください。
- 必要な入力、アクセス許可、安全境界、または成功基準が不足している場合は、停止して説明を求めてください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Windows Shell Reliability Patterns
Best practices for running commands on Windows via PowerShell and CMD.
When to Use
Use this skill when developing or debugging scripts and automation that run on Windows systems, especially when involving file paths, character encoding, or standard CLI tools.
1. Encoding & Redirection
CRITICAL: Redirection Differences Across PowerShell Versions
Older Windows PowerShell releases can rewrite native-command output in ways that break later processing. PowerShell 7.4+ preserves the byte stream when redirecting stdout, so only apply the UTF-8 conversion workaround when you are dealing with older shell behavior or a log file that is already unreadable.
| Problem | Symptom | Solution |
|---|---|---|
dotnet > log.txt |
view_file fails in older Windows PowerShell |
Get-Content log.txt | Set-Content -Encoding utf8 log_utf8.txt |
npm run > log.txt |
Need a UTF-8 text log with errors included | npm run ... 2>&1 | Out-File -Encoding UTF8 log.txt |
Rule: Prefer native redirection as-is on PowerShell 7.4+, and use explicit UTF-8 conversion only when older Windows PowerShell redirection produces an unreadable log.
2. Handling Paths & Spaces
CRITICAL: Quoting
Windows paths often contain spaces.
| ❌ Wrong | ✅ Correct |
|---|---|
dotnet build src/my project/file.fsproj |
dotnet build "src/my project/file.fsproj" |
& C:\Path With Spaces\bin.exe |
& "C:\Path With Spaces\bin.exe" |
Rule: Always quote absolute and relative paths that may contain spaces.
The Call Operator (&)
In PowerShell, if an executable path starts with a quote, you MUST use the & operator.
Pattern:
& "C:\Program Files\dotnet\dotnet.exe" build ...
3. Common Binary & Cmdlet Pitfalls
| Action | ❌ CMD Style | ✅ PowerShell Choice |
|---|---|---|
| Delete | del /f /q file |
Remove-Item -Force file |
| Copy | copy a b |
Copy-Item a b |
| Move | move a b |
Move-Item a b |
| Make Dir | mkdir folder |
New-Item -ItemType Directory -Path folder |
Tip: Using CLI aliases like ls, cat, and cp in PowerShell is usually fine, but using full cmdlets in scripts is more robust.
4. Dotnet CLI Reliability
Build Speed & Consistency
| Context | Command | Why |
|---|---|---|
| Fast Iteration | dotnet build --no-restore |
Skips redundant nuget restore. |
| Clean Build | dotnet build --no-incremental |
Ensures no stale artifacts. |
| Background | Start-Process dotnet -ArgumentList 'run' -RedirectStandardOutput output.txt -RedirectStandardError error.txt |
Launches the app without blocking the shell and keeps logs. |
5. Environment Variables
| Shell | Syntax |
|---|---|
| PowerShell | $env:VARIABLE_NAME |
| CMD | %VARIABLE_NAME% |
6. Long Paths
Windows has a 260-character path limit by default.
Fix: If you hit long path errors, use the extended path prefix:
\\?\C:\Very\Long\Path\...
7. Troubleshooting Shell Errors
| Error | Likely Cause | Fix |
|---|---|---|
The term 'xxx' is not recognized |
Path not in $env:PATH | Use absolute path or fix PATH. |
Access to the path is denied |
File in use or permissions | Stop process or run as Admin. |
Encoding mismatch |
Older shell redirection rewrote the output | Re-export the file as UTF-8 or capture with 2>&1 | Out-File -Encoding UTF8. |
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.