Kanji
・Cloud engineer / freelance ・Born in 1993 ・From Ehime / Living in Shibuya, Tokyo ・5 years AWS experience Profile details
Table of Contents
Even when I keep coding standards and prohibitions aligned across AGENTS.md and CLAUDE.md , each terminal coding agent stops—or slips past a constraint—at a completely different layer. In daily work switching between Claude Code, OpenAI Codex CLI, and OpenCode, the friction rarely comes from prompt wording. It comes from where each runtime enforces boundaries right before and right after a tool executes.
AGENTS.md
CLAUDE.md
One tool relies on OS-level sandboxing to deny file writes, another intercepts tool calls with a hook script returning exit code 2 , and another evaluates a permission map alongside TypeScript plugin hooks. Treating shared Markdown rules as sufficient without accounting for those runtime differences leaves blind spots around MCP subprocesses and headless CI runs.
2
Based on the three CLIs installed on my macOS workstation in December 2026 (Claude Code 2.1.304 , Codex CLI 0.171.0 , and OpenCode v2.1.4 ), this guide compares their OS sandbox boundaries, deterministic hooks, MCP transport handling, and non-interactive automation flags.
2.1.304
0.171.0
v2.1.4
~/.claude/settings.json
.claude/settings.json
.local.json
~/.codex/config.toml
.codex/config.toml
~/.config/opencode/opencode.json
./opencode.json
.well-known
/sandbox
codex sandbox
permission
ask
allow
deny
PreToolUse
PostToolUse
approval_policy
config.toml
tool.execute.before
.after
permission.ask
stdio
http
sse
.mcp.json
[mcp_servers.<name>]
"mcp"
opencode.json
claude -p
--bare
--background
codex exec
codex review
opencode run
--format json
--standalone
The sharpest architectural split among the three CLIs is how they isolate shell commands:
seccomp
read-only
workspace-write
danger-full-access
sandbox.enabled: true
settings.json
bubblewrap
socat
sandbox.failIfUnavailable
Read
Edit
Write
--allowedTools
--allow-dangerously-skip-permissions
"permission"
"ask"
"allow"
"deny"
I checked the installed versions on my Apple Silicon Mac and tested codex sandbox in both read-only and workspace-write modes. Here is the observed output:
claude --version && codex --version && opencode --version codex sandbox -c sandbox_mode="read-only" --log-denials -- /bin/sh -c 'touch /tmp/codex_ro_test'
2.1.304 (Claude Code) codex-cli 0.171.0 opencode v2.1.4 touch: /tmp/codex_ro_test: Operation not permitted === Sandbox denials === None found.
Under read-only , the write attempt failed immediately with exit code 1 and Operation not permitted . However, running touch /tmp/codex_ws_outside_test under sandbox_mode="workspace-write" exited with 0 and created the file. Because macOS workspace-write permits writes in temporary directories (including /tmp ) alongside the workspace root, assuming workspace-write blocks every path outside the repository is inaccurate (exact Landlock path behavior on Linux was not tested in this local macOS verification).
1
Operation not permitted
touch /tmp/codex_ws_outside_test
sandbox_mode="workspace-write"
0
/tmp
There is also a critical caveat documented for Codex CLI: stdio MCP server processes defined in config.toml are not sandboxed by the Codex harness . Because Codex cannot reliably infer all files or network sockets an arbitrary MCP server needs, it avoids forcing a default sandbox that could break valid server configurations. Treat MCP server permissions and credentials as an independent trust boundary.
Prose rules such as “never push directly to main ” or “do not read .env ” degrade as context grows. Deterministic hooks enforce those constraints in code regardless of model state.
main
.env
Claude Code provides lifecycle hook events including PreToolUse , PostToolUse , PermissionRequest , and SubagentStop , executed as shell commands or HTTP endpoints. Tool arguments arrive on stdin as JSON; exiting with code 2 and writing to stderr blocks the tool call and feeds the reason directly back to the model.
PermissionRequest
SubagentStop
stdin
stderr
{ "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh" } ] } ], "PostToolUse": [ { "matcher": "Edit|Write", "hooks": [ { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/run-formatter.sh" } ] } ] } }
Inside .claude/hooks/block-dangerous-git.sh , extract .tool_input.command with jq and reject protected branch pushes:
.claude/hooks/block-dangerous-git.sh
.tool_input.command
jq
#!/usr/bin/env bash set -euo pipefail CMD=$(jq -r '.tool_input.command // ""') if echo "$CMD" | grep -qE 'git[[:space:]]+push[[:space:]]+.*(origin[[:space:]]+(main|master)|--force)'; then echo "Blocked by PreToolUse hook: direct push to main/master or --force is prohibited." >&2 exit 2 fi exit 0
Using JSON output ( hookSpecificOutput.permissionDecision or updatedInput ) on exit 0 also enables programmatic auto-approval or argument sanitization.
hookSpecificOutput.permissionDecision
updatedInput
OpenCode implements hooks as TypeScript plugins placed in .opencode/plugins/ or ~/.config/opencode/plugins/ . You combine baseline rules in opencode.json with runtime checks via @opencode-ai/plugin , throwing an error inside tool.execute.before to abort unsafe actions.
.opencode/plugins/
~/.config/opencode/plugins/
@opencode-ai/plugin
{ "$schema": "https://opencode.ai/config.json", "permission": { "bash": { "*": "ask", "git status*": "allow", "pytest*": "allow" } }, "plugins": [ "./.opencode/plugins/git-guard.ts" ] }
import type { Plugin } from "@opencode-ai/plugin"; export const GitGuardPlugin: Plugin = async () => ({ "tool.execute.before": async (input, output) => { if (input.tool === "bash" && typeof output.args?.command === "string") { if (/git\s+push\s+.*(main|master|--force)/.test(output.args.command)) { throw new Error("Blocked by OpenCode plugin: direct push to protected branch."); } } }, "tool.execute.after": async (input) => { if (input.tool === "edit" || input.tool === "write") { // Trigger lightweight formatting or audit logging after file edits } }, });
Inspecting structured output.args in TypeScript avoids the shell-quoting bugs common in ad-hoc bash hooks.
output.args
Instead of firing per-tool external shell hooks, Codex CLI anchors enforcement in ~/.codex/config.toml (and project .codex/config.toml , loaded only when the project is trusted) using sandbox_mode , approval_policy , and named profiles ( -p / -P ).
sandbox_mode
-p
-P
#:schema https://developers.openai.com/codex/config-schema.json sandbox_mode = "workspace-write" approval_policy = "on-request" [sandbox_workspace_write] writable_roots = ["~/workspace/active-project"]
Streamable HTTP
All three agents support the Model Context Protocol (MCP), and choosing the right transport avoids unnecessary operational risk or complexity.
Each CLI provides dedicated MCP subcommands verified via --help :
--help
# Claude Code: register HTTP or stdio servers (.mcp.json servers require approval) claude mcp add --transport http sentry https://mcp.sentry.dev/mcp claude mcp add my-local-tool -e LOG_LEVEL=info -- npx -y @example/mcp-tool # OpenAI Codex CLI: manage servers via subcommands or config.toml codex mcp add my-local-tool -- npx -y @example/mcp-tool codex mcp login my-remote-tool # OpenCode: interactive wizard, OAuth login, or "mcp" block in opencode.json opencode mcp add opencode mcp auth my-remote-tool
Regardless of client, keep active MCP servers scoped to roughly 3--5 focused servers per task. Connecting dozens of servers injects every tool schema into the context window on every turn, increasing token overhead and degrading tool selection accuracy. Claude Code also marks unapproved repository .mcp.json entries as ⏸ Pending approval in claude mcp list , preventing freshly cloned repositories from silently executing external MCP processes.
⏸ Pending approval
claude mcp list
For CI pipelines and scripted workflows, each tool offers dedicated non-interactive flags:
# Claude Code: --bare skips user hooks, keychain reads, and CLAUDE.md auto-discovery claude -p --bare --settings ./ci-settings.json "Run pytest on tests/ and summarize failures" # OpenAI Codex CLI: non-interactive execution and built-in diff review codex exec --strict-config -c sandbox_mode="read-only" "Inspect git diff and list security risks" codex review # OpenCode: explicit provider/model routing, JSON output, and isolated server opencode run --standalone --model anthropic/claude-sonnet-5-5 --format json "Check schema compatibility"
Two CI flags stand out in practice: Claude Code’s --bare prevents personal workstation hooks from leaking into automated jobs, while Codex CLI’s --strict-config fails fast on unrecognized config.toml keys instead of silently ignoring deprecated settings.
--strict-config
exit 2
Rather than forcing one CLI across every task, splitting responsibilities works reliably in practice:
SKILL.md
Two areas remain unverified in production here and worth watching over coming releases: parity between macOS Seatbelt’s /tmp handling and Linux Landlock in containerized CI runners, and the long-term stability of Codex CLI’s experimental remote-control / cloud modes alongside OpenCode’s background service daemon in shared team pipelines.
remote-control
cloud
service
Real-time AI quant analysis of earnings reports, corporate filings, and momentum indicators for global equities and Japanese stocks.
Master conversation skills with realistic AI phone training and 5-axis feedback. Includes 16-lesson interactive academy and studio AI portraits.
Effortlessly snap receipts for instant AI itemization. Integrated with LINE for seamless group expense tracking and pain-free settlement.
Interactive AI personas (Fortune Teller, Butler, Bartender) host real-time games, challenges, and conversation starters for unforgettable gatherings.
Unbiased healthcare database featuring zero-additive filters and active ingredient cost performance metrics.