> ## Documentation Index
> Fetch the complete documentation index at: https://docs.finalsay-hitl.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code and Codex

> Approve risky commands from your phone, and teach coding agents when to ask.

Coding agents run commands on your machine and push to shared places. FinalSay gives you two ways to stay in charge,
both built on the [CLI](https://docs.finalsay-hitl.com/integrations/cli.md), and both work the same in Claude Code and OpenAI Codex:

* **A hook** that stops Claude Code or Codex before risky shell commands and asks you, whether or not the agent thinks
  to.
* **A skill** (or `AGENTS.md` snippet) that teaches any coding agent when to ask and how to read the answer.

Both need the CLI installed and configured:

```sh theme={"theme":{"light":"github-light","dark":"vesper"}}
npm install -g finalsay
finalsay login   # or export FINALSAY_API_KEY and FINALSAY_AGENT_ID
```

Create a dedicated agent for your coding agent (for example "Claude Code" or "Codex") so its approvals have their own
people and defaults.

## The hook: approve risky commands from your phone

`finalsay-gate.sh` is a `PreToolUse` hook for both Claude Code and Codex. When the agent is about to run a shell command
that matches a pattern, it asks in FinalSay with **Allow** and **Block**, and waits up to 10 minutes.

* **Allow** → the command runs.
* **Block**, a written answer, or no answer → the command is blocked and the agent is told why, including your written
  instruction.

By default it gates `git push`, `rm -r…`, `terraform apply|destroy`, `kubectl apply|delete`, `npm publish`, and
`DROP TABLE` / `DROP DATABASE`. It needs `jq`.

> [tab] Claude Code
>
> **1. Add the script**
>
> Copy `examples/agent-hook/finalsay-gate.sh` from the `finalsay` package to `.claude/hooks/` in your project,
> and make it executable:
>
> ```sh theme={"theme":{"light":"github-light","dark":"vesper"}}
> mkdir -p .claude/hooks
> cp "$(npm root -g)/finalsay/examples/agent-hook/finalsay-gate.sh" .claude/hooks/
> chmod +x .claude/hooks/finalsay-gate.sh
> ```
>
> **2. Register the hook**
>
> Merge this into `.claude/settings.json`:
>
> ```json .claude/settings.json theme={"theme":{"light":"github-light","dark":"vesper"}}
> {
>   "hooks": {
>     "PreToolUse": [
>       {
>         "matcher": "Bash",
>         "hooks": [
>           {
>             "type": "command",
>             "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/finalsay-gate.sh",
>             "timeout": 660
>           }
>         ]
>       }
>     ]
>   }
> }
> ```
>
> Keep the hook `timeout` above the wait time (600 seconds by default).

> [tab] Codex
>
> **1. Add the script**
>
> Copy `examples/agent-hook/finalsay-gate.sh` from the `finalsay` package to `.codex/hooks/` in your repository,
> and make it executable:
>
> ```sh theme={"theme":{"light":"github-light","dark":"vesper"}}
> mkdir -p .codex/hooks
> cp "$(npm root -g)/finalsay/examples/agent-hook/finalsay-gate.sh" .codex/hooks/
> chmod +x .codex/hooks/finalsay-gate.sh
> ```
>
> **2. Register the hook**
>
> Save this as `.codex/hooks.json` (it's also in the package as `examples/agent-hook/codex/hooks.json`). The
> `codex` argument makes the approval say *Codex* instead of *Claude Code*.
>
> ```json .codex/hooks.json theme={"theme":{"light":"github-light","dark":"vesper"}}
> {
>   "hooks": {
>     "PreToolUse": [
>       {
>         "matcher": "^Bash$",
>         "hooks": [
>           {
>             "type": "command",
>             "command": "\"$(git rev-parse --show-toplevel)\"/.codex/hooks/finalsay-gate.sh codex",
>             "timeout": 660,
>             "statusMessage": "Waiting for approval in FinalSay"
>           }
>         ]
>       }
>     ]
>   }
> }
> ```
>
> Keep the hook `timeout` above the wait time (600 seconds by default). Prefer `config.toml`? The same hook as an
> inline `[[hooks.PreToolUse]]` table is in `examples/agent-hook/codex/config.toml`. Use one or the other.
>
> **3. Trust the hook**
>
> Codex only runs hooks you've reviewed. Start Codex in the repository, open `/hooks` and trust the FinalSay
> hook. Codex asks again whenever the hook changes.
>
> The hook runs outside Codex's sandbox, so it reaches FinalSay even when the agent's own shell has no network.
> Tested with Codex CLI 0.172.
>
> Codex only loads `.codex/` from projects you've trusted. To gate every project instead, put the script in
> `~/.codex/hooks/` and the hook in `~/.codex/hooks.json`, with an absolute path as the `command`. The same setup
> applies in the Codex CLI, the IDE extension and the desktop app, which share `~/.codex`. Codex cloud tasks aren't
> covered.

### Tune it (optional)

| Variable | Default | What it does |
| - | - | - |
| `FINALSAY_GATE_PATTERN` | the list above | Extended regex (case-insensitive) of commands to gate |
| `FINALSAY_GATE_MAX_WAIT` | `600` | Seconds to wait for an answer |
| `FINALSAY_GATE_FAIL_OPEN` | off | Set to `1` to let commands run when FinalSay itself can't be reached. By default they're blocked. |
| `FINALSAY_GATE_AGENT` | `claude-code` | `claude-code` or `codex`, if you'd rather not pass it as the argument |

The approval shows the full command and the directory, plus Claude's own description of why it wants to run it (Codex
doesn't send one). The push notification reads *Claude Code: \<command>* or *Codex: \<command>*.

> [!NOTE]
>
> A hook is a strong guardrail, not a sandbox. It sees the commands the agent runs through its shell tool, so keep
> your agent's own permission settings on as well.

## The skill: teach the agent when to ask

The `finalsay` package includes:

* **`skill/`**: an Agent Skill (`SKILL.md`, plus the icon and `agents/openai.yaml` Codex shows in its skill list). Copy
  the folder to your agent's skills folder:

  | Agent | Project | Everywhere |
  | - | - | - |
  | Claude Code | `.claude/skills/finalsay/` | `~/.claude/skills/finalsay/` |
  | Codex | `.agents/skills/finalsay/` | `~/.agents/skills/finalsay/` |

* **`AGENTS.md`**: the same guidance, condensed. Paste it into your `AGENTS.md` (Codex reads it as is) or `CLAUDE.md`.

They teach the agent to ask before irreversible, costly or outward-facing actions, to write a question and context a
person can answer quickly, and to act on each exit code:

| Exit | Meaning | The agent should |
| - | - | - |
| `0` | First option chosen | Proceed |
| `3` | Another option chosen | Do what that option means (`selected_option_value`) |
| `4` | The reviewer wrote an instruction | Follow `custom_instruction` |
| `5` | Expired with no answer | Not proceed; follow the fallback or tell you |
| `6` | Still pending | Run `finalsay wait <request_id>` later; not proceed meanwhile |
| `1` / `2` | Error | Not proceed; tell you |

This works for any agent that runs shell commands: Claude Code, Codex, Cursor, Aider and others.

> [!TIP]
>
> Agent shells often time out long commands. The skill tells the agent to run `finalsay ask --wait` in the background,
> or to ask without `--wait` and call `finalsay wait <request_id>` later.

> [!WARNING]
>
> **Codex's sandbox has no network by default**, so `finalsay ask` from the agent's own shell can't reach FinalSay.
> Either allow it in `~/.codex/config.toml`:
>
> ```toml ~/.codex/config.toml theme={"theme":{"light":"github-light","dark":"vesper"}}
> [sandbox_workspace_write]
> network_access = true
> ```
>
> or connect FinalSay over [MCP](https://docs.finalsay-hitl.com/integrations/mcp.md#connect) instead, which doesn't run in the sandbox. The skill tells
> the agent to use the MCP tools when its shell has no network.

## Prefer MCP?

Claude Code, Codex and other MCP clients can also call FinalSay as tools (`request_human_approval`,
`get_approval_result`). See [MCP](https://docs.finalsay-hitl.com/integrations/mcp.md#connect) for both. The hook is the stronger guarantee: it runs
whether or not the model decides to ask.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.