# How to Connect Kalen to Codex

> Add Kalen to the Codex CLI as a streamable HTTP MCP server, with your Kalen API key read from an environment variable, then check it works.

Canonical: https://kalen.si/guides/connect-codex

[Start](https://kalen.si/guides)

Updated November 23, 2026 · 3 min read

To connect Kalen to the Codex CLI, create an API key on the [Connect page](https://kalen.si/app/setup), put it in an environment variable with `export KALEN_API_KEY=<key>`, and run `codex mcp add kalen --url https://kalen.si/mcp --bearer-token-env-var KALEN_API_KEY`. Codex then calls Kalen over streamable HTTP and sends the key as a bearer token from that variable, so the key itself never sits in Codex’s config file. Put the export in your shell profile so every new terminal has it.

## Steps

1. Sign in to Kalen and open the [Connect page](https://kalen.si/app/setup).
2. Create an API key. It starts with `kln_live_` and is shown once: copy it now. You can keep up to 10 active keys and revoke any of them.
3. Add the key to your shell profile (`~/.zshrc` or `~/.bashrc`), with your key in place of `<key>`:

```
export KALEN_API_KEY=<key>
```

1. Open a new terminal, or run `source ~/.zshrc`, so the variable is set.
2. Add Kalen to Codex:

```
codex mcp add kalen --url https://kalen.si/mcp --bearer-token-env-var KALEN_API_KEY
```

1. Check that Codex lists it:

```
codex mcp list
```

1. Start Codex and send the prompt below.

## Check that it works

```
Use Kalen to check my account.
```

Codex should call the `account` tool and report your plan, credits, X connection and profile. The call shows up on your [Usage](https://kalen.si/app/usage) page.

## Example

An illustration, not a real account.

You: Use Kalen to check my account.

Codex calls `account`. Kalen answers with your plan and balance, whether X is connected (with a connect link to open in your browser if not) and whether your profile, voice and stories are set.

You: Turn the README of this project into an X thread with Kalen.

Codex reads the file, sends its text to Kalen’s `repurpose` tool, rebuilds it as a thread, checks it, scores it and shows you every tweet. It schedules nothing until you approve.

## Media from the terminal

There is no upload panel in a terminal. Kalen’s `upload_media` returns a `curl` line instead; run it once per file, then ask Codex to list your media for the ids. See [Media and video](https://kalen.si/guides/media-and-video).

## What it costs

The key and the connection are free. Scheduled posts and paid reads from X spend credits, and each asks first. See [Credits and plans](https://kalen.si/guides/credits-and-plans).

## Common errors

- **“Missing or invalid Kalen credentials” (HTTP 401).** Codex started without the variable, or the key was revoked. Run `echo $KALEN_API_KEY` in the same terminal; if it’s empty, set it and restart Codex. If the key was revoked, create a new one on the [Connect page](https://kalen.si/app/setup) and update the export.
- **Codex doesn’t list Kalen.** Run the `codex mcp add` command again, then `codex mcp list`.
- **A new tool is missing.** Codex reads the tool list when it starts. Restart it.
- **Never paste the key into a file you commit.** Keep it in your shell profile or a secrets manager.

## Next

Next: [Connect your X account](https://kalen.si/guides/connect-x).

**About this guide.** Written by the team that builds Kalen. Something didn't match what you see? Write to [support@kalen.si](mailto:support@kalen.si) and say which AI you use.

## Your X assistant, inside your AI.

 [Start your 7-day trial for $1](https://kalen.si/#pricing)
