# Use BotPassword from Codex

Source: https://botpassword.com/docs/guides/codex

Status: P4-9. `bpw agent install codex` sets Codex up in one step. This guide adds `bpw mcp` to OpenAI Codex as a stdio MCP server, so Codex can use your credentials through BotPassword's intents. No intent returns a value; a `run_with` grant you mark `--allow-disclosure` lets the command it starts read one. The Codex CLI, IDE extension and ChatGPT desktop app share one configuration.

## The short path

```bash
cargo build --release -p bpw -p botpasswordd     # until signed installers exist (M1-11)
mkdir -p ~/.local/bin && cp target/release/bpw target/release/botpasswordd ~/.local/bin/
export PATH="$HOME/.local/bin:$PATH"            # put this line in your shell profile too
bpw daemon install                               # macOS: start the daemon at every login
bpw init --server http://127.0.0.1:8787 --kit-out ~/botpassword-kit.txt   # once; see Get started
bpw agent install codex                    # register the server, add the instructions
bpw agent enroll codex                     # macOS: let grants name Codex
bpw agent run -- codex                          # start the harness inside a session
```

Copy the programs to a directory only you can write (`~/.local/bin` above), and run them from there, not from `target/release`. The login item and the harness start these files as you every time, so `bpw agent install` and `bpw daemon install` refuse a binary, or a directory above it, that group or other users can write, or that another user owns. The daemon runs before `bpw init` because `init` talks to it (elsewhere than macOS, start `botpasswordd` yourself instead of `bpw daemon install`); `init` comes before `agent run` because an agent needs an account. [Get started](/docs/guides/getting-started) explains it.

Then give the agent something to use with `bpw grant add` ([below](#before-you-start)); it can use nothing until you do.

`bpw agent install codex` does two things, and says what it did:

- **Registers the server** by running Codex's own `codex mcp add botpassword -- <absolute path of bpw> mcp --agent codex`, which writes a `[mcp_servers.botpassword]` table to `config.toml` in `$CODEX_HOME` (default `~/.codex`) and keeps the rest of that file. `bpw` does not edit the TOML itself.
- **Adds the instructions** to `AGENTS.md` in the same directory, between two marker lines (`<!-- BEGIN botpassword ... -->` and `<!-- END botpassword -->`). Codex reads `AGENTS.override.md` first and ignores `AGENTS.md` when the override is not empty, so if you keep a non-empty override the block goes there. The text is the ADR 0058 section 3 snippet: use the `bpw` tools instead of asking you to paste a secret, and ask you before any action you did not request.

It makes no grant and no session, and writes no secret anywhere. Your existing text is kept, a copy is saved as `AGENTS.md.bak` before the first change, and a second run changes nothing and says so. `--dry-run` prints what would change and changes nothing; it does run the harness's read-only `--version` and `mcp get` commands to find out what is already there. The harness's command is found on your `PATH`, skipping relative entries and anything in the current directory, and the path it will run is printed. A symbolic link at any file it would write is refused, never followed. If `codex` is not on your `PATH`, nothing is changed and the error shows the `codex mcp add` line to run yourself.

`run_with` can take up to 100 seconds and Codex's default tool timeout is 60. If Codex gives up on a slow command, add `tool_timeout_sec = 120` under `[mcp_servers.botpassword]` in `config.toml`.

To remove it: `bpw agent uninstall codex`. It unregisters the server and removes exactly the marked block and the one blank line install put before it; the rest of the file stays as it was, and a file that held nothing else is deleted. Your `.bak` copy is left in place. `bpw daemon uninstall` stops the login agent (that locks the vault, because the daemon holds the keys in memory). Neither touches your vault, grants, sessions or data directory. The rest of this page is the longer explanation and the by-hand steps.

## What Codex gets

What Codex gets: one tool per intent (`status`, `list_credentials`, `run_with`, `http_request`, `store_secret` and the rest of the [catalog](/docs/intents)). No tool is built to return a secret value. `run_with` and `http_request` inject a credential you granted and return output with that value redacted (best effort: the raw, base64, hex and percent-encoded forms are caught, other transformations are not). The other intents are checked against policy and then return `not_implemented` in this build.

## Before you start

The steps are the same as for [Claude Code](/docs/guides/claude-code#before-you-start):
1. Build `bpw` and `botpasswordd`, and note the absolute path of `bpw`.
2. Start the daemon and set up a disposable vault with synthetic keys.
3. Grant a credential with `bpw grant add`. It always asks for your master password, and agents cannot make or change grants.

```bash
cargo build --release -p bpw -p botpasswordd
BPW="$(pwd)/target/release/bpw"
"$BPW" grant add <api-key-id> --intent http_request \
  --host api.example.com --path '/v1/*' --method GET --expires-in-hours 8
"$BPW" grant add <cli-key-id> --intent run_with --command curl --allow-disclosure --expires-in-hours 8
```

The two items are synthetic trial keys, added as in the [Claude Code guide](/docs/guides/claude-code#before-you-start). **Grant `http_request` alone for any credential whose host scope matters.** A `run_with` grant hands the value to a command the agent chooses. That command can send it to any host, ignoring `--host`, `--path` and `--method`, and can recover it through a transformation the redactor does not catch (`rev`, `cut`, wrapped base64). The daemon starts the command outside the harness and its sandbox, with your full user privileges and network. Grant `run_with` only for a value you would be willing to hand the agent outright. That is why a `run_with` grant must say so with `--allow-disclosure` (`bpw grant list` labels it "this agent can read this secret") and must list each executable it may start with `--command`: the daemon records each one's resolved path and SHA-256, starts only those, and refuses a shell or interpreter given code inline (`sh -c`, `python -c`, `node -e`) and launchers such as `env` and `xargs` (ADR 0015). A `--command` takes any arguments, so the agent has that program's full command-line power: an allowlisted tool that runs code the agent can write (a script file, a build tool) still discloses. Command runners, interpreters and shells are refused as `--command`. `git`, `gh`, `npm` and `cargo` can be granted with `--argv`, and so can an interpreter running one script (below). The other runners (`make`, `ssh`, `npx`, `pnpm`, `docker`, ...) cannot be granted at all. `bpw grant add` warns when one grant has both intents.

### Command runners: git, gh, npm and cargo

A command runner runs other commands named in its arguments (`git -c alias.x='!…'`, `npm exec`, `cargo --config …`), so a grant for the bare executable would let any subcommand get the value. Grant it with an argv pattern instead (ADR 0040):

```bash
"$BPW" grant add <gh-token-id> --intent run_with --allow-disclosure --expires-in-hours 8 \
  --argv 'git push origin *' --argv 'git fetch origin' --argv 'gh pr create --fill'
"$BPW" grant add <npm-token-id> --intent run_with --allow-disclosure --expires-in-hours 1 \
  --argv 'npm publish --access public'
```

The agent then injects the value under the runner's token name:
- git and gh: `GH_TOKEN` or `GITHUB_TOKEN`. git reads it only through `gh auth git-credential` (`gh auth setup-git`).
- npm: `NPM_TOKEN` or `NODE_AUTH_TOKEN`, as your `.npmrc` names it.
- cargo: `CARGO_REGISTRY_TOKEN`.

Any other name is `scope_denied` for a runner. Every `run_with` grant also refuses a best-effort list of names that change how a program runs or where it connects: the loader (`LD_*`, `DYLD_*`), shells and the base environment (`PATH`, `HOME`, `BASH_ENV`, `LC_*`), proxies and TLS roots (`*_PROXY`, `SSL_CERT_FILE`), interpreters and compilers (`NODE_*`, `PYTHON*`, `CC`), and the runners' own configuration (`GIT_*`, `GH_*`, `NPM_CONFIG_*`, `CARGO_*`, `RUSTUP_*`). ADR 0040 has the full list. It is not complete for other tools, so for a plain command or a script, choose the variable name with care. The daemon's log says which name was refused.

How patterns work:
- **The pattern** is the program, then the exact arguments, separated by single spaces. A final `*` matches further operands, never options.
- **Every runner is deny by default.** A pattern starts with one of the runner's listed subcommands, and nothing may come before it. That refuses `git -c …`, `git -C …`, `cargo +nightly …` and `cargo --config …`. Only subcommands that use the token are listed:
  - git: `push`, `fetch`, `ls-remote`, `pull` and `clone`;
  - cargo: `publish`, `owner` and `yank`;
  - most of gh's `pr`, `issue`, `release`, `run`, `workflow`, `search`, `secret` and `variable` subcommands;
  - npm's registry subcommands.

  ADR 0040 has the tables.
- **Options are an allowlist per subcommand, spelled exactly.** No abbreviations, aliases or clusters. `--access public` and `--access=public` are different patterns, and so are reordered options. An option that takes a value needs the value in the pattern: `pr create --title *` is refused.
- **Name the remote.** `*` never stands for a remote or a URL: `git push *` and `git fetch *` are refused; write `git push origin *`. Operands after the remote are screened when the agent asks.
- **A git ref is a branch or tag.** It is a one-part name (`main`, `v1.2.0`) or `refs/heads/…` or `refs/tags/…` (`refs/heads/feature/x`). It is never:
  - an object id or an abbreviation of one, 4 or more hex digits (spell a branch named `cafe` as `refs/heads/cafe`);
  - `git describe` output, a name ending in `-g` and 4 or more hex digits (`v1.0-1-g600b5d3`);
  - revision syntax (`main~1`, `FETCH_HEAD^0`, `stash@{0}`);
  - `HEAD`, `FETCH_HEAD` or another pseudo-ref;
  - a review ref on any forge (`pull/1/head`, `merge-requests/…`, `changes/…`).

  Name the branch the agent should push. A push may still force (`+main`) or delete (`:main`), so `push origin *` allows both; write `push origin main` to rule them out.
- **`push origin *` decides what a later `pull` brings in.** An exact `git pull origin main` merges whatever `main` holds on the remote. With `push origin *`, the agent can make that any commit a local branch names. Do not combine `push origin *`, `pull` from the same remote, and a rule that runs project code (`npm ci`, `npm install`, `cargo publish`, a script); name the push refspec instead.
- **Subcommands whose operands name code, files, destinations or lasting rights are exact only.** Write their operands out:
  - `git clone` and `git pull`;
  - `npm publish`, `install`, `view`, `owner`, `access`, `dist-tag`, `deprecate` and `unpublish`;
  - `gh pr merge`, `release create`, `upload`, `download` and `delete`, and `secret` and `variable` `set`/`delete`. `gh pr review` never takes `--approve`, since an approval can satisfy a required review;
  - `cargo owner` and `yank`.

  Even written out, an operand cannot be an absolute or `~` path, a `..` path, a URL other than https or ssh to a host, or an npm git, GitHub, file or URL spec.
- **Not grantable at all:**
  - git `config`, `remote`, `submodule`, `rebase` and every local subcommand;
  - gh `api`, `auth`, `alias`, `extension`, `pr checkout`, `repo clone` and `repo set-default`;
  - npm `exec`, `run` and `pack`;
  - cargo `build`, `run`, `install` and `test`;
  - any option that names another host or repository, or opens a browser or editor (`--hostname`, `--repo`, `--web`, `--editor`);
  - any option that reads a file (`--body-file`, `-F`).
- **rustup's cargo.** `~/.cargo/bin` is not on the daemon's run PATH, so grant it by absolute path: `--argv '/Users/you/.cargo/bin/cargo publish'`. The agent sends the same path. `cargo publish` builds the crate to verify it, which runs every dependency's build script with the token in its environment. If you build and test separately, grant `cargo publish --no-verify`.
- **Interpreters and shells** (`python3`, `node`, `bash`, `sh`, `ruby`, `deno`, `bun`, `pwsh`, `java`, ...) are granted only to run one script inside the project: `--argv 'python3 scripts/deploy.py *'`. The script comes first, by its path in the project, with no interpreter option before it. `java -jar build/app.jar` and `pwsh -File scripts/x.ps1` are the two exceptions. `*` after the script matches operands only, never a URL or a path outside the project. The script decides what those arguments do. A grant made earlier with `--command python3` (or another listed interpreter) no longer matches; remake it with `--argv`. The list goes by name and cannot name every interpreter, so treat any `--command` as able to run code.
- **`bpw grant list`** shows each rule with its runner and the label "runs project code".

What a runner rule promises: an agent that controls only the command line and the variable name cannot:
- run code with the value in its environment;
- send the value to a host the pattern does not name;
- write files outside the working tree;
- change configuration that a later run reads.

That is an agent with MCP access and no file access. An interpreter rule promises less: the agent cannot choose the code, but the script decides what its arguments do. A `--command` promises none of this.

The "runs project code" label marks everything else. Each runner still runs hooks, lifecycle scripts or build scripts, and reads configuration from files:
- git: `.git/config` and `.git/hooks`;
- npm: `.npmrc` and `package.json` scripts;
- cargo: `build.rs` and `.cargo/config.toml`;
- gh: `~/.config/gh`.

An agent that can edit the project can still make `git push` run its own code or send the token elsewhere. So a runner grant needs `--allow-disclosure` like any `run_with` grant, and is never sealed. Prefer `http_request` for API tokens. Use a runner rule only for a value you would hand the agent outright, with a short expiry and a `--project`.

## Add the server by hand

`bpw agent install codex` does this for you ([the short path](#the-short-path)). Do it by hand to see each step or to use a project's `.codex/config.toml`. `--agent codex` is a label that BotPassword shows in `status` and in the notes of anything Codex stores. Any program can claim any label, so BotPassword never grants anything because of it.

**Command line:**

```bash
codex mcp add botpassword -- "$BPW" mcp --agent codex
```

**Config file** (`~/.codex/config.toml`, or `.codex/config.toml` in a trusted project):

```toml
[mcp_servers.botpassword]
command = "/absolute/path/to/target/release/bpw"
args = ["mcp", "--agent", "codex"]
# run_with may take up to 100 s; Codex's default tool timeout is 60 s.
tool_timeout_sec = 120
```

**Never put a secret in this config**, including in an `[mcp_servers.botpassword.env]` table. No secret is needed: `bpw mcp` looks for the daemon in `$BPW_SOCKET_DIR`, then `$XDG_RUNTIME_DIR/botpassword`, then `~/.botpassword/run`, and Codex can read its own configuration. Codex passes MCP servers only a short list of environment variables, so on Linux, where the daemon usually uses `$XDG_RUNTIME_DIR`, set the directory explicitly. The path is not a secret:

```toml
[mcp_servers.botpassword.env]
BPW_SOCKET_DIR = "/run/user/1000/botpassword"   # your $XDG_RUNTIME_DIR/botpassword
```

## Check it

```bash
codex mcp list             # botpassword is listed
```

In the Codex TUI, `/mcp` shows the active servers and their tools.

## Start it in a session

Agents act only inside a session (ADR 0014). There are two ways to give Codex one.

**Start it normally, then approve it.** This needs Codex enrolled ([below](#enroll-codex)), and works on macOS and Linux. Start `codex` the way you always do. Its first BotPassword tool call answers `session_required`, and BotPassword lists it as a waiting agent: on the desktop app's Agents page, and with `bpw session pending`. The app does not pop up, take focus or make a sound. The count beside Agents shows only within 5 minutes of entering your master password in the app. Using the app does not extend those 5 minutes.

Each row shows the name, how it was recognized, the process ID, when it started, the program it runs, a path it was started under, and its folder. These help you notice a wrong row. None of them proves the row is your agent. Code running as you can start a real Codex, with its own configuration, in your project folder, and its row looks the same. When in doubt, dismiss them all and use `bpw agent run`.

To approve one, give the project folder, a length (1 hour by default, 12 hours at most) and your master password, in the app or with `bpw session approve ID [--project DIR] [--minutes N]`. That command shows the row and asks `Approve? [y/N]` first. `bpw session dismiss ID` hides it for 10 minutes.

The session covers everything that Codex process runs, until it exits or the session runs out. If the process is an app, such as an editor, it also covers that app's other extensions and terminals. The ledger can say less about who asked than for a session `bpw agent run` started. A waiting agent goes away after 10 minutes, when its process exits, or when you lock the vault. Windows does not have this yet.

**Or start it through `bpw`**, from the project directory:

```bash
cd ~/Developer/your-project
bpw agent run --minutes 120 -- codex
```

`bpw agent run` asks for your master password, opens a session for this directory, runs `codex` as its child and ends the session when it exits. `bpw mcp` started by Codex is inside it.

Without a session, every tool but `status` answers `session_required`, and `status` reports only whether the vault is unlocked. A grant bound to a project (`bpw grant add --project`) applies only to sessions opened in that directory or below it. `bpw session list` and `bpw session end ID` show and end sessions.

## Enroll Codex

Enrolling tells BotPassword how to recognize Codex, so a grant can be for Codex only. Until you enroll it, every session's client is `unenrolled`, and a grant for `unenrolled` serves any session that is not an enrolled client's.

```bash
bpw agent enroll codex                  # asks for your master password
bpw agent clients                       # the enrolled clients and their IDs
bpw grant add ITEM --client ID ...      # a grant only Codex's sessions can use
```

On macOS, `bpw agent enroll codex` recognizes the program by its code signature: the signing team `2DC432GLL2` and the identifier `codex`. The Homebrew cask installs that signed program. An install that runs Codex as a script under `node` is not that program, so it is not recognized this way. Enrolling `node` itself by signature is refused, because that would match every script `node` runs.

Elsewhere, or for a program without a usable signature, enroll it by path: `bpw agent enroll --name Codex --path /full/path/to/codex`. The file and every directory above it must be owned by you or root and not writable by others. BotPassword checks this when you enroll and again each time it matches. Such a client is labeled "recognized by path". Anyone who can replace that file can act as that client.

`bpw agent run` fixes the session's client when it starts Codex: right after starting it, `bpw` asks the daemon, which reads `bpw`'s one child process itself and recognizes it. `bpw` prints the client it was recognized as, or that the session is unenrolled. The client stays fixed for the whole session, even if the program later replaces itself with another one. If the daemon cannot fix it, for example because the vault is locked, `bpw` stops Codex and ends the session. `bpw session list` shows each session's client.

If `bpw status` says the list of enrolled clients cannot be read, no session is recognized as a client. Run `bpw agent clients --reset` with the master password, then enroll your clients again.

Grants are not moved when you enroll. A grant made for `unenrolled` keeps serving `unenrolled` sessions only. To let the enrolled Codex use a credential, revoke the old grant and add one with `--client`. When Codex asks with `request_access` and you approve, the grant is made for its client.

`bpw agent unenroll ID` removes a client. Its sessions end, and any command they started is stopped. Its grants stay but no session can use them; the command says how many are left, and `bpw grant revoke` removes them.

## What a refusal tells Codex

When BotPassword refuses a request, the result keeps its outcome code (for example `session_required`, `vault_locked` or `scope_denied`) and adds two sentences next to it. `message` says what happened. `next_step` says what to do now: for example, ask you to unlock BotPassword, or call `request_access` so that you can approve a grant. A `next_step` never tells Codex to ask you for a password or a secret in chat, or to get around the refusal.

The same applies at a terminal. `bpw agent <intent>` prints the outcome, then `message:` and `next step:`. Add `--json` to get one JSON object on stdout and nothing else there; it holds the same fields as the MCP result and never a secret value. `bpw status --json` works the same way.

A script can tell the results apart by the exit status of `bpw agent <intent>` (`bpw agent run` is different: it exits with the status of the command it ran):

| Status | Meaning |
|---|---|
| 0 | Done |
| 1 | Failed: BotPassword could not be reached, the arguments were wrong, or something broke inside `bpw`. With `--json` each of these is still one object: `failed` with a `message` when `bpw` turned the arguments down or broke, `daemon_unavailable` for an unreachable daemon, `daemon_incompatible` for a daemon that answers in a form this `bpw` cannot read (update `bpw` and the daemon to the same build) |
| 2 | The command line could not be parsed. With `--json` that is also one object, `usage_error` |
| 3 | Refused: BotPassword answered and said no, for example `vault_locked` or `scope_denied` |
| 4 | Not finished: a person must act. This is `approval_required` (an approval is waiting for you) or `partially_rotated`. Do not treat it as done |

The credential helpers (`git-credential-bpw`, `docker-credential-bpw`, `bpw aws-creds`, `bpw kube-creds`) keep the exit status their own tool defines.

## What to expect

| Ask Codex to | Tool | Typical outcome |
|---|---|---|
| "Check BotPassword" | `status` | `success`, with the session's client (its ID once enrolled, otherwise `unenrolled`) and `agent "codex", self-asserted` |
| "Which credentials can you use?" | `list_credentials` | Only granted items, with their allowed intents |
| "Run `env` with my trial CLI key as `API_KEY`" | `run_with` | `success`; the output shows `[bpw:redacted]` where the value was |
| "GET https://api.example.com/v1/user with my trial API key" | `http_request` | `success` with status, headers and redacted body; a host outside the grant gives `scope_denied`, and a granted name that resolves to a private or loopback address gives `host_restricted` |
| "Store this new key: ..." | `store_secret` | `success` and a new item ID |
| "Ask me for access to my trial API key for api.example.com" | `request_access` | `approval_required` with a request ID; approve it in the desktop app's Ledger or with `bpw access approve ID`, and the agent's next check reads `approved` with the grant |
| In a fresh session with no grants: "Ask me for the key you need to read api.example.com" | `request_access` with `looking_for` | `approval_required` with a request ID and no item; you choose the item in the Ledger (or `bpw access approve ID --item ITEM`) and approve, and its next `list_credentials` shows the item |
| Anything after `bpw lock` | any | `vault_locked` |

`run_with` runs the program directly, not through a shell, and only an executable the grant lists; a shell runs a script file (`["/bin/sh", "script.sh"]`), never `-c`. The child gets only `PATH`, `HOME`, `LANG` and the injected variables, never your shell's environment. Codex's own sandbox does not apply to the command: the daemon starts it, outside Codex, with your user's privileges and network.

### Approving what the agent asks for

When the agent calls `request_access`, nothing changes until you decide. See what is waiting and decide from a terminal:

```sh
"$BPW" access list                 # what the daemon knows, then the agent's own words
"$BPW" access approve <request-id> # asks for your master password, shows the request, then asks y/N; --ttl-seconds shortens it
"$BPW" access approve <request-id> --item <item-id> # for a request that describes what it wants: choose the item first
"$BPW" access deny <request-id>
"$BPW" access ledger               # every request, decision and grant, with no values
```

The desktop app shows the same requests on its Ledger page, with a count beside Ledger in the sidebar. The grant you approve is exactly what was asked, bound to the project the session was opened in, and replaces any grant the item already has. The agent's name and reason are its own words: read them, but decide from the item, the scope and the project. Approval on your phone is planned (P4-2b).

An agent with no grant cannot name an item: it has no way to learn an ID, and BotPassword does not say whether one exists. So it describes what it needs instead, with `looking_for` ("the API key for api.example.com, to read the deploy status"), and the request reaches you with no item. The Ledger shows the description, labelled as the agent's own words, and lists your items with those that match its words first. Choose one, and the sheet shows that item's facts and the grant like any other request; choosing grants nothing. Approve with your master password, or decline. Until you approve, the agent learns nothing about your items, not even whether one matched (ADR 0069).
