--- title: "Connect Codex" type: reference tags: [signpost, docs, reference] proposed_by: tok_bc09b340db294c709763789154d8113d model: kmem-docs-publisher extracted_at: "2026-10-08T22:34:00.753Z" --- # Connect Codex Codex reads kmem from its configuration file, and it reads the token from the KMEM_TOKEN environment variable. kmem has tested this route with Codex. ![The Codex tab in Connect, with the configuration for Codex and the KMEM_TOKEN step.](/guide/160-codex.webp) ## Create a connection 1. In kmem, select **Connect**. The **MCP** tab opens. 2. Select Codex in the list of clients. 3. Check the **New connection** form. kmem fills in a name, for example "Codex · Maya · 8 Oct". You can change it, for example to "Codex nightly checks". 4. Select **Create connection**. [Create a connection](./110-connect-agents.md#create-a-connection) explains each field. Copy the token now. kmem shows it only one time. ## Merge the configuration Codex keeps its MCP servers in the file `~/.codex/config.toml`. 1. Under **Configuration for Codex**, select **Copy configuration**. 2. Open `~/.codex/config.toml` in a text editor. If the file does not exist, create it. 3. Add the kmem section at the end of the file. Keep your other servers. 4. Save the file. The configuration looks like this: ```toml kmem:codex [mcp_servers.acme-kmem] url = "https://acme.kmem.app/mcp" bearer_token_env_var = "KMEM_TOKEN" ``` Replace acme with your org's subdomain, in the server name and in the endpoint. The Connect screen fills it in for you. The server name is `-kmem`, for example `acme-kmem`. Each org has its own server name, so one computer can hold the kmem of more than one org. The configuration holds no token. The line `bearer_token_env_var` tells Codex to read the token from the variable `KMEM_TOKEN`. ## Set KMEM_TOKEN Set `KMEM_TOKEN` to the token of your connection, in the environment that starts Codex. 1. Open the profile file of your shell, for example `~/.zshrc` or `~/.bashrc`. 2. Add this line, with your token in place of YOUR_TOKEN: ```sh export KMEM_TOKEN="YOUR_TOKEN" ``` 3. Save the file. 4. Open a new terminal. The new terminal reads the profile file and gets the variable. If you start Codex from an app and not from a terminal, set the variable where that app gets its environment. Keep the profile file private. Do not commit it to a shared repository. ## Check the connection 1. Start Codex again. 2. Check that the MCP tools of Codex include acme-kmem. 3. Send the check prompt: ```text kmem:check-prompt Use kmem to list the docs I can access. If there are none, say so. ``` 4. In kmem, select **Check connection**. The three checks must show **Seen**. If Codex cannot reach kmem, check these points: - The terminal that starts Codex has a value in `KMEM_TOKEN`. Run `echo $KMEM_TOKEN` to see the value. - The token belongs to an active connection. - The `url` ends with `/mcp`. ## Add kmem with a command instead Codex can also add the server with a command. The command writes the same section to `~/.codex/config.toml`: ```sh codex mcp add acme-kmem --url https://acme.kmem.app/mcp --bearer-token-env-var KMEM_TOKEN ``` Replace acme with your org's subdomain, in the server name and in the endpoint. You still need to set `KMEM_TOKEN`. ## Next steps - [Connect OpenCode](./170-connect-opencode.md) - [Connect agents](./110-connect-agents.md) - [Troubleshooting](./250-troubleshooting.md)