1
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に.envを読ませない設定は settings.json の permissions.deny に書く

1
Last updated at Posted at 2026-10-15

結論

  • Claude Code に .env を読ませたくないなら、settings.json の permissions.deny に Read(./.env) と Read(./.env.*) を書きます。公式ドキュメントにこの例がそのまま載っています。
  • 設定ファイルは ~/.claude/settings.json(自分・全プロジェクト)、.claude/settings.json(プロジェクト共有)、.claude/settings.local.json(自分・このプロジェクトだけ)の3つと、組織の管理設定です。
  • permissions のようなリストは上書きではなく合算されます。どこか1か所に deny があれば、それも効きます。
  • 出典: https://code.claude.com/docs/en/settings (2026-10-15 時点)

1. 書き方(公式の例)

{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)"
    ]
  }
}

設定ファイルは厳密なJSONです。// コメントや末尾のカンマがあるとエラーになります(公式 "Edit a settings file")。保存後、Claude Code の中で /status を実行し、Setting sources の行に読み込まれたファイルが出ているか確かめます(公式 "Confirm what loaded")。

2. どのファイルに書くか

ファイル 効く範囲 向いている用途
~/.claude/settings.json 自分の全プロジェクト 個人として常に拒否したいもの
.claude/settings.json そのプロジェクト(コミットすればチームにも) チーム共通の拒否ルール
.claude/settings.local.json 自分のこのプロジェクトだけ 個人の上書き
管理設定 組織が配布した全員 会社のポリシー

.env の拒否はチーム全員に効かせたいことが多いので、.claude/settings.json に書いてコミットするのが分かりやすいと思います(これは筆者の運用上の提案です)。

3. denyは「合算」される

公式の "Lists merge instead of overriding" に、permissions.allow のようなリストは複数ファイルで上書きではなく組み合わされると書かれています。つまり、リポジトリ側に deny がなくても、ホーム側の ~/.claude/settings.json で拒否済みのことがあります。点検するときは両方見ましょう。

4. denyはフォルダを信頼する前から効く

公式によると、共有ファイル .claude/settings.json の permissions.allow は各自がフォルダを信頼するまで適用されませんが、deny と ask はすぐ適用されます("A committed key doesn't reach teammates")。拒否ルールをコミットしておけば、クローン直後から効くということです。

5. 確認のしかた

  1. /status で Setting sources に自分のファイルが出ているか確認する
  2. 弾かれたルールがないかは claude doctor で確認する(公式 "Confirm what loaded")

注意

更新情報やちょっとしたTipsは X(@supportapp3_lab)で発信しています。

1
0
1

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
1
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?