# Set up Codex with the CLI

On a machine that uses only Codex, set up Harnessforce with the CLI alone. harnessforce login writes both the Claude Code user settings and the Codex config.toml.

```sh
/plugin marketplace add lambda-script/harnessforce-agent
/plugin install harnessforce@harnessforce-agent
/harnessforce:setup
```

```sh
npm install -g @harnessforce/cli
```

On a machine that uses Codex and not Claude Code, skip the plugin and `/harnessforce:setup` and do the same setup with the Harnessforce CLI. The telemetry settings, the import of past sessions, and the status check are the same as with Claude Code. The command that installs the CLI appears at the top of this page.

## Before you begin

* **Node.js:** `node --version` is 18 or later.
* **Workspace:** You can sign in to a Harnessforce workspace in your browser.

## Steps

1. **Check that `node --version` is 18 or later.**
2. **Install the CLI with the command at the top of this page.**
3. **Decide whether to send content data, then run `harnessforce login`.** By default the machine sends the categories the workspace stores. To keep content on the machine, run `harnessforce config set send-content off` first, then run `harnessforce login`. Before sending, it shows who in the workspace can read the content and how long it is kept. Sign in in your browser and choose a workspace, and an ingest key is issued.
4. **Import past sessions with `harnessforce import`.**
5. **Restart Codex and trust the `SessionStart`, `PostToolUse`, and `Stop` hooks with `/hooks`.** Until you trust them, Codex sessions are not registered with Harnessforce.
6. **Check the remaining steps with `harnessforce status`.**

## What harnessforce login writes

`harnessforce login` writes both the Claude Code user settings and the Codex `config.toml`, even on a machine that uses only Codex. If you install Claude Code later, it sends to the same workspace without running `harnessforce login` again.

The Codex `config.toml` is the one under `CODEX_HOME` when it is an absolute path, and `~/.codex/config.toml` otherwise. `harnessforce login` creates the file if it doesn't exist and writes only these entries:

| Entry                                                  | What it sets                                                                                                                                                                                                                     |
| ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `[otel].exporter`                                      | Sends Codex telemetry over OTLP/HTTP to Harnessforce with your ingest key                                                                                                                                                        |
| `[otel].log_user_prompt`, `[otel].log_agent_responses` | Whether Codex sends prompt text and model and tool content. `true` only when the machine's content setting is `on` (the default; `harnessforce config set send-content off` turns it off) and the workspace stores that category |
| `[[hooks.SessionStart]]`                               | Registers each session's repository, branch, and commit                                                                                                                                                                          |
| `[[hooks.PostToolUse]]`, `[[hooks.Stop]]`              | Record where the session worked                                                                                                                                                                                                  |
| `[mcp_servers]` `harnessforce`                         | The Harnessforce MCP server                                                                                                                                                                                                      |

It leaves your other keys, hooks, and MCP servers as they are. Running `harnessforce login` again replaces only the values it wrote before.

The hooks run the launcher in the CLI's fixed location by its full path, so they keep working after you switch Node.js versions (see [Configure Claude Code](/en/docs/claude-code#nodeVersions)). When `harnessforce login` changes a hook command, for example from `harnessforce` to the launcher's path, trust the hooks again with `/hooks`.

`harnessforce login` doesn't set how often Codex sends telemetry, because `config.toml` has no setting for it. Only Codex started with `harnessforce run` sends every 60 seconds, with the same delay and possible loss as [Claude Code](/en/docs/claude-code#exportInterval). Start Codex with `harnessforce run -- codex`. Codex started directly sends every second while it has events to send, and its hook shows a warning when each session starts. Your event count doesn't change, but the extra requests count toward the workspace's [requests per second](/en/docs/ingest#limits).

The ingest key is written to the Codex `config.toml` in plain text, because Codex cannot read the authentication header for its OpenTelemetry destination from an external command or an environment variable. The key can only send telemetry and register sessions. API tokens are never written to the file.

## Sign in to the MCP server

Sign in to the Harnessforce MCP server once from Codex with `codex mcp login harnessforce`.

## Read next

* [Install](/en/docs/install): the other two methods, for machines that use Claude Code.
* [Troubleshooting](/en/docs/troubleshooting): when no sessions arrive.
