Connect Codex¶
Codex connects to Hivemind through one MCP server entry in its configuration. The same endpoint serves short, mid and long memory; never add a separate graph server. The complete client guide with troubleshooting is CODEX_INTEGRATION.md.
Written for Codex CLI 0.162.1.
Prerequisite: a Codex CLI with MCP server support (codex --version) and an
instance that passed the readiness checkpoint.
1. Give Codex its identity¶
Each agent gets its own identity; never share one between assistants. Two options, chosen by the operator of the instance.
For your own agent, open Account → Agents in the Portal and select
Create agent with Read and write on the target space. Then select
Manage → Issue API token and choose 1, 7, 30, 90 or 365 days, or a
custom whole number from 1 to 365. The hm_… token is shown once; it acts
with the agent's current grants. An operator can instead issue a
credential for a standalone agent in Identity & Groups → Agents and
credentials → Issue credential, with an optional UTC expiry (one day by
default, seven days at most); see
Identity and access.
A token imported from 1.6 (lm_…) is used the same way.
In ~/.codex/config.toml, or in .codex/config.toml at the project root
for a trusted project:
[mcp_servers.hivemind]
bearer_token_env_var = "HIVEMIND_TOKEN"
enabled = true
url = "https://hivemind.example.org/mcp"
Export the token in the environment that starts Codex, without recording it in shell history:
printf 'Hivemind token: '
IFS= read -r -s HIVEMIND_TOKEN
printf '\n'
export HIVEMIND_TOKEN
codex
bearer_token_env_var makes Codex read the value at runtime. Never write
the token itself into config.toml, and never use the literal token as
the variable name.
When the operator has enabled the OAuth policy:
codex mcp add hivemind --url https://hivemind.example.org/mcp # detects OAuth, starts the sign-in
codex mcp login hivemind # sign in again later; --no-browser on a remote shell
Codex identifies itself with its published client metadata; Hivemind never
receives your OpenAI account. ChatGPT uses a different client identity:
see Connect ChatGPT. codex mcp logout removes only the local
credentials; ask the operator to revoke the connection server-side. With
codex exec and approval_policy = "never", allow each Hivemind tool
explicitly in the configuration. See
native OAuth for MCP clients.
2. Verify the connection¶
codex mcp list
In Codex, use /mcp and confirm hivemind is connected. Then ask Codex to
call system_whoami on hivemind. Expected: "status": "ok",
auth_type: auth17, a client_name that is the agent's UUID, not its display
name, and the tutorial space under allowed_spaces, which lists the spaces
the agent can read. Compare client_name with the Agent ID shown in the
agent's details in the Portal. The permissions list is empty: that legacy
field does not describe 1.7 grants, so it proves neither read and write nor
the absence of manage. Check the rights in the Portal instead: the agent's
Space access under Account → Agents, or, for an operator, the
credential's Effective rights under
Identity & Groups → Agents and credentials. Ask Codex to call
space_rules, mid_read_all and short_read on that space next.
If memory bank writes such as mid_consolidate fail with
auth17_commit_unqualified, the instance's storage failed Core's startup
write witness; the operator fixes it as described in
Install in production.
3. Install the project instructions¶
Codex loads AGENTS.md at the project root. Put this block there and replace
the space name. It is the same contract as for Claude Code, so both agents
behave the same way on the shared space:
# Project memory — Hivemind MCP
Hivemind is the canonical shared memory across agents and sessions: MCP server
`hivemind`, space `<space-id>`. One space owns short, mid and long
memory. Local history or product memory is non-authoritative and never
bypasses this startup gate. Repository files remain the final authority.
## Start of every task
Before changing anything, call all three and read the results:
1. `space_rules(space_id="<space-id>")`
2. `mid_read_all(space_id="<space-id>")`
3. `short_read(space_id="<space-id>")`
If any call fails, times out or returns non-OK, stop before mutation.
## During work
Write concise atomic notes only for durable facts:
`short_note(space_id="<space-id>", category="<category>", content="...")`
Categories: observation, decision, progress, issue, todo, insight, question.
Agent identity comes from the credential; never pass or invent one. Record
every human decision and every blocking question as a note in the same turn.
Use `long_query` for historical context, then re-read the canonical source.
Never run `long_push` or change long bindings as routine work.
## End of a meaningful work block
Write one summary note, confirm with the user, then call
`mid_consolidate(space_id="<space-id>")` at most once and return
without polling. `bank_consolidation_status` is for an explicit status check.
Never edit memory bank files directly. Never put tokens or endpoints here.
Interactive Codex asks before each write tool as usual. The block is guidance to the model, not an access control: only the agent's grants limit what it can read or write. The vendor-neutral contract and its rationale are in the agent memory setup guide.
Next¶
With both agents connected, run the tutorial. For the other assistants, see Connect an assistant.