@weave_protocol/adapter-codex
v0.3.0
Published
Weave Protocol adapter for OpenAI Codex CLI - enforces WARD.md policies via Codex's PreToolUse hook
Maintainers
Readme
🛡️ @weave_protocol/adapter-codex
Enforce WARD.md in OpenAI Codex CLI with its
PreToolUsehook. Every shell command, file edit and MCP call is checked against your policy before it runs.
The same WARD.md you use with Claude Code, Antigravity, Microsoft Agent Framework and Gemini CLI.
🆕 What's new
0.3.0: session and spend limits. WARD.md's limits are now enforced per session, keyed on the Codex session_id:
- Behavioral Limits:
maxToolCalls,maxRuntimeSecondsandmaxExternalServices; spending_limits:caps: tool calls, and per-tool call counts and USD amounts over a run, hour, day, week or month.
The counts live in a small local ledger (~/.weave/ledger, or $WEAVE_LEDGER_DIR) because every hook call is a new process. Ward 0.3.6's payment guard also asks before any call that moves money: payment tools, and wallet or Stripe CLIs in shell commands.
Quick start
npm i -g @weave_protocol/adapter-codex
weave-ward-codex init # adds the hook to ~/.codex/hooks.jsonThen, in Codex, run /hooks and trust "Weave: checking WARD.md". Codex skips new or changed hooks until you trust them. Add a WARD.md to your project (npx @weave_protocol/ward init), or a user-wide one at ~/.codex/WARD.md.
The command is weave-ward-codex, not weave-codex. The weave-codex npm name belongs to W&B Weave's Codex integration, which is a different product.
What it checks
The hook uses Ward's shared evaluator (evaluateToolCall), so the rules match the other adapters exactly:
- Shell commands (
Bash, including unified exec): theshell_execcapability, plus every URL and every absolute or~path in the command. - File edits (
apply_patch): the files the patch touches, read from its*** Add File,*** Update File,*** Move toand*** Delete Filelines. Adds, updates and moves are writes; deletes are deletes. Text inside the patch is never treated as a target. - MCP tools (
mcp__<server>__<tool>): by name, plus their path and URL arguments. update_planuses thetask_planningcapability, the same one the Gemini CLI adapter uses for planning tools.
Codex's hosted tools, such as web search, don't go through PreToolUse. Neither do some specialized paths, as Codex's docs note. Treat the hook as a guardrail, and combine it with Codex's own sandbox and approval settings.
Decisions
| WARD decision | What Codex sees |
|---|---|
| allow | nothing: the call continues, and Codex's own approvals still apply |
| deny | permissionDecision: "deny" with the WARD reason, which the model sees |
| require_approval | a deny whose reason says approval is needed (Codex hooks don't support "ask") |
Failure modes:
- An invalid WARD.md always denies, so a typo can't silently switch enforcement off.
- No WARD.md anywhere means no enforcement.
- Malformed payloads and evaluator errors allow by default.
init --fail-closedmakes them deny.
WARD.md is looked up in this order:
$WEAVE_WARD_PATH<project>/WARD.md<project>/.codex/WARD.md<project>/.weave/WARD.md$CODEX_HOME/WARD.md(default~/.codex/WARD.md)
Commands
weave-ward-codex init [--matcher=REGEX] [--timeout=SECONDS] [--fail-closed]
weave-ward-codex disable
weave-ward-codex status
weave-ward-codex test Bash --input='{"command":"cat secrets/key"}' # dry run
weave-ward-codex hook pre-tool-use # what Codex runsinit writes to $CODEX_HOME/hooks.json (default ~/.codex/hooks.json). It backs the file up, edits it atomically, and finds its own entry by its status message, so your other hooks are untouched.
Dashboard
Set WEAVE_DASHBOARD_URL (and WEAVE_API_KEY) where you run the agent, and each decision is reported to a local Weave API dashboard (0.2.0+). Only the decision and the tool name are sent, never command or argument contents. Reporting never changes a decision and gives up after 250 ms.
Verified
Built against Codex's hooks documentation: the PreToolUse payload, deny output, apply_patch and MCP tool naming. 13 fixture tests.
Live-checked in Codex CLI 0.166.0, signed in with a ChatGPT account:
cat secrets/keywas blocked, and Codex reportedCommand blocked by PreToolUse hook: WARD: Denied by filesystem rule …;cat notes.txtwent through;- an
apply_patchaddingsecrets/new.txtwas blocked by its file target, and no file was created, even in theworkspace-writesandbox.
🕸️ Part of Weave Protocol
One WARD.md policy for every agent you run, locally or at scale, plus the tools around it.
| Package | What it does | |---|---| | Ward | The WARD.md policy standard and the tool-call evaluator every adapter shares | | Mund | Scans content for prompt injection, secrets, PII and exfiltration | | Hord | Encrypted vaults, PII tokenization, sandboxes, capability tokens, attestations | | Dōmere | Audit threads, compliance checkpoints, GDPR and CCPA records, anchoring | | Witan | Multi-agent consensus and spending caps | | Hundredmen | MCP proxy that enforces WARD.md on tool calls | | Tollere | Supply-chain checks: typosquats, CVEs, suspicious version diffs | | Browser | WARD.md and injection scanning for Playwright browser agents | | Adapters | WARD.md in Claude Code, Antigravity, MSAF, Gemini CLI, Codex, OpenCode and Cursor | | Adversary · AgentSecBench | Red-team engine and locked benchmark | | API · CLI · LangChain | REST API and dashboard, setup CLI, LangChain.js integration | | full | Every defensive package in one install | | Yoxallismus | Post-quantum hybrid cipher (experimental beta) |
License
Apache-2.0
