2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Codeで特定のコマンドを禁止する方法

Last updated at Posted at 2025-07-20

どうも〜、泉(@izumin_0401)です。

Claude Codeで特定のコマンドを禁止する方法について、わかりやすく解説しやす。

Claude Codeで特定コマンドを禁止する具体的な方法

早速ですが、Claude Codeで特定コマンドを禁止する方法を解説します。

1. 設定ファイル「.claude/settings.local.json」を作成する

プロジェクトルートに.claudeフォルダを作成し、settings.local.jsonファイルを配置します。

ファイル作成後は、禁止したいコマンドをJSON形式で記述するだけです。

設定ファイルの基本構造は以下の通りです。

{
  "permissions": {
    "allow": [],
    "deny": []
  }
}

2. 危険なコマンドを禁止リストに追加する

ファイル削除、権限変更、秘密鍵アクセスなどの危険操作を禁止設定に追加します。

具体的な禁止コマンド例を設定すれば、誤操作によるシステム破損を防げます。

推奨する禁止コマンドパターンは以下の通りです。

{
  "permissions": {
    "allow": [],
    "deny": [
      "Bash(rm -rf:*)",
      "Bash(rm -r:*)",
      "Bash(sudo rm:*)",
      "Bash(rmdir:*)",
      "Bash(rm --recursive:*)",
      "Bash(rm --force:*)",
      "Bash(rm -f:*)",
      "Bash(rm -R:*)",
      "Bash(find * -delete:*)",
      "Bash(find * -exec rm:*)",
      "Bash(xargs rm:*)",
      "Bash(sudo:*)",
      "Bash(git config *)",
      "Bash(git push:*)",
      "Bash(git commit:*)",
      "Bash(git reset:*)",
      "Bash(git rebase:*)",
      "Bash(brew install *)",
      "Bash(chmod 777 *)",
      "Read(.env*)",
      "Read(id_rsa*)",
      "Read(*.key)",
      "Read(*.pem)",
      "Write(.env*)",
      "Write(id_rsa*)",
      "Write(*.key)",
      "Write(*.pem)"
    ]
  }
}

これで安全にClaude Codeを使えます。

rm -rfとか実行されたらツラすぎますからね...

まとめ

Claude Codeで特定のコマンドを禁止する方法について解説しました。

役に立ったら「いいね」ボタンをポチッとお願いします🙏

最後に

Twitterも見てね。

Vlogも見てね。

仮想通貨のサイトも見てね。

https://crypto-currency-textbook.com/

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?