> For the complete documentation index, see [llms.txt](https://docs.codna.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.codna.ai/reference/operations.md). Agents can also search and read this documentation through its [MCP server](https://docs.codna.ai/~gitbook/mcp).

# Local runtime

Operate Codna's local runtime. Health checks, the full diagnostic, loopback ports, and the environment variables that control on-disk state.

Codna runs a small local runtime on your machine. It starts on demand when a fix or review needs the agent, listens on loopback only, and is owned per checkout. You rarely manage it by hand; this page covers when you do.

## Health check

```bash
codna status
```

`codna status` never starts anything and never errors. It reports:

| Line            | Values                                                  |
| --------------- | ------------------------------------------------------- |
| `engine`        | `running` / `stopped` / `unknown`                       |
| `telys runtime` | `ready (<source>)` / `not installed — run codna login`  |
| `telys license` | the license source / `none` / `misconfigured`           |
| `engine key`    | `configured` / `missing (set CODNA_API_KEY)`            |
| `provider key`  | `configured` / `missing — run codna key set <provider>` |

`engine key` reports your Codna account key. Local CLI runs work without it; every MCP tool call (`codna mcp`) requires it — the one-time free `codna login` device authorization. `provider key` is the one `codna fix` and `codna review` need.

## Full diagnostic

```bash
codna doctor                 # inspect the runtime (JSON)
codna doctor --start-stack   # ensure the local runtime is running
codna doctor --stop-stack    # stop the local runtime
```

The key field in the JSON is `status`:

| `status`              | Meaning                                                             | Recovery                     |
| --------------------- | ------------------------------------------------------------------- | ---------------------------- |
| `not_running`         | Nothing is listening.                                               | `codna doctor --start-stack` |
| `healthy_owned`       | Healthy and owned by this checkout.                                 | none                         |
| `unhealthy_owned`     | Owned but failing health checks.                                    | restart                      |
| `stale_codna_sidecar` | A healthy runtime that cannot be reused here (see `stale_reasons`). | restart                      |
| `port_collision`      | Another process holds the port, or the listener is not Codna.       | free the port                |

When a restart or start is needed, the report includes the exact `codna_command` to run.

## Ports

| Port    | Role                                               |
| ------- | -------------------------------------------------- |
| `18600` | The local runtime (`http://127.0.0.1:18600`)       |
| `18601` | The local agent runtime (`http://127.0.0.1:18601`) |

Both listen on loopback only. Two `codna fix` runs with matching `CODNA_RUNTIME_ROOT` and `CODNA_PORT_BASE` share one runtime, so a second invocation reuses a warm one instead of paying a cold start. Set distinct values for each when you want full isolation, for example when concurrent runs use different provider credentials.

## Environment variables

| Variable                                 | Default    | Effect                                                                           |
| ---------------------------------------- | ---------- | -------------------------------------------------------------------------------- |
| `CODNA_RUNTIME_ROOT`                     | `~/.codna` | Root for runtime state, logs, saved reports and the key index.                   |
| `CODNA_PORT_BASE`                        | `18600`    | Base port; Codna uses this port and the next. Range `[1024, 65534]`.             |
| `CODNA_DISABLE_KEYCHAIN`                 | *(off)*    | `1`, `true`, `yes` or `on` disables OS-keychain access; keys come from env only. |
| `CODNA_AGENT_CORE_READY_TIMEOUT_SECONDS` | `120`      | Readiness timeout for the local runtime (clamped `5`–`300`).                     |

{% hint style="info" %}
There is no engine URL or server to configure. `CODNA_ENGINE_URL` exists only to point Codna at a remote engine, and then `CODNA_API_KEY` is required.
{% endhint %}

## State on disk

Under `CODNA_RUNTIME_ROOT` (default `~/.codna`):

* `runtime/local-stack.json`, `runtime/local-stack.lock` — runtime state and lock.
* `logs/` — rotating runtime logs.
* `keys/keychain-index.json` — the non-secret index of stored provider keys (values live in the OS keychain).
* `reports/` — local copies of `codna report` submissions that could not be sent.
* `review-budget/` — the recorded review turns the review window learns from.

Account sign-in state lives under `~/.telys/`; per-repository memory lives in each repo's `.codna-memory/`.

## See also

* [CLI Reference](https://docs.codna.ai/reference/cli.md) — `codna doctor` and `codna status`.
* [Configuration](https://docs.codna.ai/reference/configuration.md) — the complete environment and `codna.yaml` reference.
* [Troubleshooting](https://docs.codna.ai/reference/troubleshooting.md) — common failures and fixes.
