Codex
Make OpenAI Codex ask a person before it acts, through the MCP server or a PreToolUse hook that approves shell commands.
Codex has its own approval modes for the machine it runs on. Connecting it here sends the question to an inbox instead: answer from anywhere, let a teammate answer, let rules answer the routine ones, and keep every answer on one record with your other agents.
1. Create a key
Sign in, open Agents and create a key for Codex. Copy it: it is shown once.
2. Add the server and the skills
Put the key in your shell profile, such as ~/.zshrc:
export VARIANTGATE_KEY=gl_YOUR_KEYAdd the server to ~/.codex/config.toml:
[mcp_servers.variantgate]
url = "https://api.variantgate.com/mcp"
bearer_token_env_var = "VARIANTGATE_KEY"Add the skills:
curl -fsSL https://variantgate.com/skills/asking-for-approval/SKILL.md --create-dirs -o ~/.agents/skills/asking-for-approval/SKILL.md
curl -fsSL https://variantgate.com/skills/adding-approvals-to-code/SKILL.md --create-dirs -o ~/.agents/skills/adding-approvals-to-code/SKILL.mdCodex reads the key from the environment variable, so it never sits in the configuration file. The server adds four tools, described on the MCP server page.
3. Put shell commands through approval
The MCP tools rely on the model choosing to ask. A hook does not: it runs before every matching tool call. Add it to ~/.codex/config.toml:
[[hooks.PreToolUse]]
matcher = "^Bash$"
[[hooks.PreToolUse.hooks]]
type = "command"
command = "variantgate hook codex"
timeout = 180Codex asks you to trust a new hook under /hooks before it runs it. The hook needs VARIANTGATE_API_URL and VARIANTGATE_KEY in the environment. Each call becomes a request with an action name rules can match:
- shell.run
- Bash: Run the command: …
- file.write
- Write: Write the file …
- file.edit
- Edit and MultiEdit: Edit the file …; NotebookEdit: Edit the notebook …
- web.fetch
- WebFetch: Fetch …
- mcp.<server>.<tool>
- A tool from an MCP server: Use <tool> from the <server> MCP server
- tool.<name>
- Any other tool: Use the <name> tool
- The hook waits up to two minutes for a person, then withdraws the request and denies the call. Set
VARIANTGATE_HOOK_WAITto change it, in seconds, and keep the hook’stimeoutlonger than that wait: Codex documents only a denial as blocking a call, not a hook that timed out. - If the service cannot be reached, the call is denied. Codex has no prompt of its own to fall back to for hooks, and letting the call through would not be cautious.
A rule for shell.run covers every command, since rules match the action. Keep shell commands with a person and write rules for the routine actions.
4. Try it
Ask Codex to run a harmless command. Approve the request in the inbox and the command runs; deny the next one and check that Codex stops and says so.