# Codex CLI: read your AI citations from the shell, key kept out of config

> For the complete documentation index, see [llms.txt](https://attensira.com/llms.txt).
> Every page on this site is also served as Markdown: append `.md` to any URL, or send `Accept: text/markdown`.

> Add Attensira's MCP server to Codex CLI with one command that reads your API key from an environment variable, so the key never lands in config.toml.

- Canonical page: https://attensira.com/integrations/codex-cli
- Family: integrations
- Last updated: 2026-10-04
- Author: Karl-Gustav Kallasmaa (https://x.com/kallasmaa)
- Claims as data: https://attensira.com/claims.json?slug=codex-cli

**In short:** Export a workspace API key as ATTENSIRA_API_KEY, then run codex mcp add attensira --url https://mcp.attensira.com/mcp --bearer-token-env-var ATTENSIRA_API_KEY. Codex reads the key at runtime and sends it itself, so it never enters config.toml. Codex can then read your citations per engine and day, the prompts you lose and the crew's waiting work.

## What it showed on attensira.com (read 2026-10-04)

Asked in Codex CLI: "How often have answers cited attensira.com in the last four weeks, per engine?"

Call: `citation_timeline domain_or_url=attensira.com days=28`

1,442 citations, and nearly all of them since 24 September. The number of tracked prompts citing us rose the same day, so read the answers before reading anything into it.

| Row | Value | Note |
| --- | --- | --- |
| ChatGPT, 6 to 23 September | 0 to 8 a day | 1 or 2 prompts citing us |
| ChatGPT, 24 September to 3 October | 81 to 157 a day | 3 to 6 prompts citing us |
| Perplexity, from 24 September | 11 to 30 a day | none before |
| Total, 28 days | 1,442 | ChatGPT 1,235 · Perplexity 207 |

_A timeline is what changed, not why._

## What can Codex read from the shell?

- Read citations per engine and per day for your domain or one page, with the mean position, from the shell or a script.
- Check, in a CI step after a deploy, whether the pages you changed are being cited, then measure properly at the +7, +14 and +30 day re-reads.
- Read the prompts you lose and who wins them, and what the crew has waiting for approval.
- Run unattended. The key does not expire until you revoke it, which suits a scheduled or CI job.

## How do I connect Codex CLI?

1. **Mint a key and export it** Mint a workspace API key under Settings → Your assistant, read-only if Codex only reads. It is shown once, because only a hash is stored. Export it as ATTENSIRA_API_KEY in your shell profile.
2. **Add the server with the env-var flag** Run codex mcp add with the server URL and --bearer-token-env-var naming the variable. Codex reads the token at runtime and sends the Authorization header itself, so the key never enters ~/.codex/config.toml.
3. **Set the variable where Codex launches** The variable has to exist in the shell profile Codex starts from. A key exported only in the terminal you tested in is missing when Codex starts another way, which shows up as an authentication failure.
4. **Fall back to a literal only if you must** If your Codex build has no --bearer-token-env-var, write the key into config.toml under an http_headers table. Treat that file as a secret, keep it out of every repository, and restart Codex after editing.

## What are the limits from the shell?

- Codex connects with a static key, not OAuth. A key never expires until revoked, so revoke it under Settings → Your assistant when the job it was minted for ends.
- A citation timeline does not say why a line moved. More prompts tracked, a provider change or a page change can all make the same step.
- A read-only key cannot write. A write tool returns 403 insufficient_scope, and a key's scope cannot be widened; mint a read-and-write key and swap it in.

### What did Codex show on our own workspace?

Almost all of the window's citations came after 24 September, and on the same day the number of our tracked prompts that cited us rose too. That points first at what we were tracking, not at anything we shipped, and the answers are where to confirm it. A timeline tells you a line moved. It never tells you why.

### What should a deploy check report?

Coverage, not a verdict. Right after a deploy, read whether the changed pages are being fetched and cited at all. The verdict comes from Attensira's own re-reads of each shipped change at +7, +14 and +30 days, each comparing a week before the change with a week around the re-read, and a change inside the noise is reported as no change. A script that reports movement every day is reporting sampling. Name each key after the job it serves, so revoking one breaks nothing else.

## FAQ

### Does the key end up in ~/.codex/config.toml?

Not with --bearer-token-env-var. Codex reads the token from the named variable at runtime and sends it as the Authorization header itself; the config only names the variable.

### Codex says authentication failed but the key is right. Why?

Usually the variable is not set in the environment Codex starts from. Put the export in your shell profile rather than in one terminal session.

### Can Codex sign in with OAuth instead?

Attensira's documented path for Codex CLI is a static key. Clients that sign in, such as Claude Code, Cursor and VS Code, need no key at all.

### Should the key be read-only?

If Codex only reads, yes. Choose the scope when you mint it; it cannot be widened afterwards.

### I lost the key. Can Attensira show it again?

No. Only a hash is stored, so a lost key is replaced, not recovered. Revoke it and mint a new one.

## Sources

Each entry below is one claim on this page. `retrieved` is the date the exporter or a human last saw the source say this, and nothing more: it is not a publication date and not a promise of re-verification. `cite` is the anchor on the canonical page where this claim is rendered.

### codex-bearer-env-var

Attensira's connect documentation states that Codex reads the token from a named environment variable at runtime and sends it as the Authorization header itself, so the key never enters config.toml.

- source: https://docs.attensira.com/mcp/connect (docs.attensira.com)
- retrieved: 2026-10-04
- cite: https://attensira.com/integrations/codex-cli#claim-codex-bearer-env-var

> Codex reads the token from a named environment variable at runtime and sends it as the `Authorization` header itself, so the key never enters `~/.codex/config.toml`
### api-key-shown-once

Attensira's connect documentation states that a key is shown exactly once because only a hash is stored, and that Attensira cannot re-display it.

- source: https://docs.attensira.com/mcp/connect (docs.attensira.com)
- retrieved: 2026-10-04
- cite: https://attensira.com/integrations/codex-cli#claim-api-key-shown-once

> It is shown exactly once: only a hash is stored, so Attensira cannot re-display it.
### static-keys-never-expire

Attensira's MCP overview states that a static API key never expires until it is revoked.

- source: https://docs.attensira.com/mcp/overview (docs.attensira.com)
- retrieved: 2026-10-04
- cite: https://attensira.com/integrations/codex-cli#claim-static-keys-never-expire

> Never, until you revoke it
