以下のチェックは12月6日に Linux 上の Claude Code 2.1.337 で実行しました。どの実行も claude -p による1ステップのタスクで、モデルは Haiku 5.5、使い捨ての git リポジトリを使い、テスト用マシン自身のルールが結果に混ざらないよう user 設定ソースを外しています。実行ごとのルールとフックは --settings で渡しました。対話モードは一切試していないので、後述するカウントダウン、Shift+Tab の切り替え、警告ダイアログはドキュメントに基づく記述です。ほかにそう明記したものも同様です。
Claude Code の —dangerously-skip-permissions は何を無効にするのか?
Claude requested permissions to edit .../repo/.git/hooks/post-merge which is a sensitive file.
Write ツールは実行ビットを立てないので、このフックはまだ発火しません。その後の chmod は試しておらず、後述する残るチェックのどれもそれをカバーしません。allow ルールはそれ以上に意味がありません。「Allow rules have no effect in bypassPermissions.」
Claude Code の bypassPermissions セッションを止められるものは何か?
読み込んだ deny ルール、ask ルール、PreToolUse フック、クリティカルパスへの rm チェックは、フラグを付けた状態でもすべて効きました。各実行では Claude にコマンドを1つだけ頼んでいます。
This command's glob pattern traverses directories that cannot be staticallyenumerated. This requires explicit approval and cannot be auto-allowed bypermission rules.
claude -p "$PROMPT" --dangerously-skip-permissions \ --output-format stream-json --verbose < /dev/null > run.jsonlrc=$?python3 - run.jsonl "$rc" <<'PY'import json, sysrc = int(sys.argv[2])msgs = [json.loads(l) for l in open(sys.argv[1]) if l.strip()]init = next((m for m in msgs if m.get("subtype") == "init"), None)result = next((m for m in msgs if m.get("type") == "result"), None)if not init or not result: sys.exit(f"exit {rc}: no init or result message")denied = result.get("permission_denials") or []print("exit:", rc, "| mode:", init.get("permissionMode"), "| subtype:", result.get("subtype"), "| refused calls:", len(denied))ok = (rc == 0 and init.get("permissionMode") == "bypassPermissions" and result.get("subtype") == "success" and not result.get("is_error") and not denied)sys.exit(0 if ok else 1)PY
Claude Code の bypass モードでクリティカルパスの rm プロンプトを無効にできるか?
できます。v2.1.311 以降、claude を起動する環境に CLAUDE_CODE_EVEN_MORE_DANGEROUSLY_SKIP_PERMISSIONS=1 を設定します。手元では設定しておらず、このセクションはドキュメントに基づきます。この変数は起動時の環境からのみ読まれ、設定ファイルの env ブロックに書いても無視されます。ドキュメントの警告ははっきりしています。「a command such as rm -rf ~ can run without asking you.」さらに Bash ツールと Monitor ツールでは、Claude Code が完全には解析できないフラグ付きのコマンドも通します。
Claude Code の —dangerously-skip-permissions はどこで実行すべきか?
コンテナ、VM、またはサンドボックスランタイムの中で、root 以外のユーザーとして実行します。モードの表では bypass は「Isolated containers and VMs only」とされており、サンドボックス環境のページは、組み込みの Bash サンドボックスだけでは足りない理由を次のように説明しています。
Always run --dangerously-skip-permissions sessions inside a container, a VM,or the sandbox runtime, so that file tools, MCP servers, and hooks are alsoinside the boundary.
コンテナが守るのはホストであって、マウントしたものや渡したものではありません。dev container のページによれば、bypass モードは悪意のあるプロジェクトが「exfiltrating anything accessible inside the container, including the Claude Code credentials stored in ~/.claude」することを防げず、Claude は「can still modify any file in the bind-mounted workspace, which appears directly on your host」とされています。これを上の結果と並べてみてください。コンテナ内で書かれた .git/hooks のファイルや空にされた .claude/settings.json は、ホストのチェックアウトにそのまま現れます。リポジトリは、その中で最初に claude -p を実行した時点でコードを実行させることもできます。hooks リファレンスによると、ヘッドレス実行では、一度も信頼していないフォルダでも設定ファイルのフックが実行されます。そのため、ドキュメントと手元のテストの両方に合う構成は短くまとまります。
1. Read the repository's .claude/, .mcp.json and .devcontainer/ before the first headless run in it, or start that run with --bare.2. Non-root user in the container or VM. Don't rely on the root refusal: per the docs it is lifted inside a recognized sandbox.3. No host secrets mounted: no ~/.ssh, no cloud credential files. Repository-scoped or short-lived tokens only.4. Egress allowlist (the reference dev container ships init-firewall.sh), or your own network controls.5. Deny rules where the session's user can't write or replace them, including the directory they sit in and any hook script they call: on Linux, managed settings in /etc/claude-code/managed-settings.json.6. Afterwards, review the tracked diff, then list .git/hooks, .git/config and the untracked or ignored files under .claude/ by hand: git diff and git status don't show what sits inside .git.
bypassPermissions の代わりに Claude Code の auto モードや dontAsk を使うべきか?
たいていの場合はそうです。auto モードは v2.1.283 以降、対話型ターミナルと VS Code のセッションで組み込みの初期モードになっており、ルールで決まらない操作をプロンプトではなく分類器に回します。ドキュメントは、auto モードにとって隔離は必須要件ではなく多層防御だとしています。dontAsk は CI に向いています。プロンプトになるはずのものはすべて拒否され、作業ディレクトリ内の読み取りと事前承認したツールは引き続き実行されます。ドキュメントの CI 向けの例は claude -p "run the test suite" --permission-mode dontAsk に --allowedTools "Bash(npm test)" "Read" を付けたものです。
bypass が合うのは、マシン自体が制御になっている場合です。つまり、価値のある中身がこれからどのみちレビューするリポジトリだけという、使い捨てのコンテナや VM です。その中では、フラグがあっても残るルールが、指定したコマンドを引き続き止めます。手元の実行では、deny ルール、git push に対するフック、rm チェックのどれも効きました。ただしルールは書かれたとおりのコマンドにしか一致せず、これはフックの記事で見つけた限界と同じです。しかもセッションはルールが書かれたファイルを書き換えられます。だから守るのはマシンで、ルールはその中での誘導役です。それ以外の場所では、ドキュメントの警告がそのまま当てはまります。「bypassPermissions offers no protection against prompt injection or unintended actions.」