> For the complete documentation index, see [llms.txt](https://docs.understand.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.understand.tech/documentation/english-version/ai-in-a-box/codex-claude-code-and-opencode-integration.md). Agents can also search and read this documentation through its [MCP server](https://docs.understand.tech/~gitbook/mcp).

# Codex, Claude Code and OpenCode Integration

## Using your AI coding tools with Understand AI

Connect **Claude Code**, **Codex** or **OpenCode** to your own Understand AI DGX box. Your code and prompts stay on your infrastructure, and nothing is sent to any external AI provider.

Everything is configured **per project**: you drop a few small files into the folder you are working in, and the tool uses your DGX box instead of its default cloud service.

This guide uses `https://understand.local`. If your DGX box answers on a different address, use that instead.

***

### Prerequisites

You need two things before configuring any tool: a **certificate file** and an **API key**.

#### 1. Export the certificate

Your DGX box secures traffic with its own internal certificate authority. Your computer does not know that authority yet, so the coding tools will refuse to connect until you give them the certificate.

On the DGX box, run:

```bash
docker exec ut-caddy cat /data/caddy/pki/authorities/local/root.crt > caddy-root-ca.crt
```

This creates `caddy-root-ca.crt` in the current directory. Copy that file to your own computer.

> **If connections suddenly stop working months later**, the DGX box may have regenerated its authority. Run this command again and replace the file.

#### 2. Create an API key

Open **<https://understand.local/developer>**, create an API key, and copy it. You will paste it into a configuration file below.

Treat it like a password. It identifies you, and your usage is counted against it, so do not share one key between people.

#### 3. Put both in your project

Create this layout in the project you want to work in. You only need the section for the tool you use:

```
your-project/
├── caddy-root-ca.crt          <- the certificate from step 1
├── .claude/
│   └── settings.local.json    <- Claude Code
├── .codex/
│   └── config.toml            <- Codex
└── opencode.json              <- OpenCode
```

Add `caddy-root-ca.crt` and the tool folders to your `.gitignore`, because they contain your personal API key.

***

### Claude Code

#### Install

Install the CLI by following the official instructions for your platform: [**https://code.claude.com/docs**](https://code.claude.com/docs)

For the editor integration, install **Claude Code for VS Code** (publisher: Anthropic, ID `anthropic.claude-code`) from the Extensions marketplace.

<figure><img src="https://2654650065-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXgNPw9jE3xyWIcnvYeCB%2Fuploads%2FVV1KTmGCbunMuDqlOHku%2Fimage.png?alt=media&amp;token=692f0b0b-5df8-4a41-b45d-69ed847f06da" alt=""><figcaption></figcaption></figure>

#### Configure

Create `.claude/settings.local.json`:

```json
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://understand.local/api/llm",
    "ANTHROPIC_AUTH_TOKEN": "PASTE-YOUR-API-KEY",

    "ANTHROPIC_DEFAULT_OPUS_MODEL": "uai-large",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "uai-large",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "uai-large",
    "CLAUDE_CODE_SUBAGENT_MODEL": "uai-large",

    "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "65536",
    "CLAUDE_CODE_DISABLE_1M_CONTEXT": "1",

    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
    "NODE_EXTRA_CA_CERTS": "caddy-root-ca.crt"
  }
}
```

All three model lines are required. Each covers a different internal role, and any one left out would try to reach an external service.

#### Start using it

**Terminal**, from the project folder:

```bash
claude
```

**VS Code**: open the project folder, then open the Claude Code panel. Accept the workspace-trust prompt, because the settings file is ignored in Restricted Mode.

<figure><img src="https://2654650065-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXgNPw9jE3xyWIcnvYeCB%2Fuploads%2Fvlq8Gjji3A0CaL7uIcQe%2Fimage.png?alt=media&amp;token=dd56a0cd-37ee-4c2d-8360-f93d7260ae66" alt=""><figcaption></figcaption></figure>

If you don't see the model, restart you vscode and it will appear

***

### Codex

#### Install

Install the CLI by following the official instructions for your platform: [**https://learn.chatgpt.com/docs/codex**](https://learn.chatgpt.com/docs/codex)

For the editor integration, install **Codex, OpenAI's coding agent** (publisher: OpenAI, ID `openai.chatgpt`). Note that the ID keeps the older name.

<figure><img src="https://2654650065-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXgNPw9jE3xyWIcnvYeCB%2Fuploads%2FgHJ5XPEy2yNBflGhRLf1%2Fimage.png?alt=media&amp;token=49291abf-f4e7-4cd9-ad69-28f94915a62b" alt=""><figcaption></figcaption></figure>

#### Configure

Create `.codex/config.toml`:

```toml
model = "uai-large"
model_provider = "understand"
model_context_window = 65536

[model_providers.understand]
name = "Understand AI"
base_url = "https://understand.local/api/llm/v1"
wire_api = "responses"

[model_providers.understand.http_headers]
"x-api-key" = "PASTE-YOUR-API-KEY"
```

Codex only reads provider settings from its *home* directory, so create a small launcher that points Codex at your project folder. Save it as `codex-local.sh` in the project root:

```bash
#!/usr/bin/env bash
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export CODEX_HOME="$DIR/.codex"
export CODEX_CA_CERTIFICATE="$DIR/caddy-root-ca.crt"
exec codex "$@"
```

Then make it runnable:

```bash
chmod +x codex-local.sh
```

> If your certificate file is named something other than `caddy-root-ca.crt`, change that name in the script to match. And check the folder is called `.codex` with the leading dot, not `codex`.

<details>

<summary>Windows (PowerShell), save as <code>codex-local.ps1</code></summary>

```powershell
$dir = $PSScriptRoot
$env:CODEX_HOME = "$dir\.codex"
$env:CODEX_CA_CERTIFICATE = "$dir\caddy-root-ca.crt"
codex @args
```

</details>

#### Start using it

**Terminal**, from the project folder:

```bash
./codex-local.sh
```

**VS Code**: open the integrated terminal and run the same command.

A startup warning saying that model information for `uai-large` was not found is normal and can be ignored.

#### Using the Codex panel instead of the terminal

The terminal method above is the simplest and needs nothing else. If you want the Codex side panel in VS Code, it takes three extra steps, because the extension cannot read provider settings from a project folder and does not see anything you type in the integrated terminal.

**1.** Make sure your personal `~/.codex/config.toml` (`%USERPROFILE%\.codex\config.toml` on Windows) defines the provider: the `model`, `model_provider`, `model_context_window` and `[model_providers.understand]` sections from the configuration above. If you have configured Codex for your DGX box before, this is already there.

**2.** Quit VS Code completely: Cmd+Q on macOS, not just closing the window.

**3.** Open a normal terminal, **outside VS Code** (Terminal, iTerm, or PowerShell), set the two variables there, and start VS Code from that same terminal:

```bash
export UT_API_KEY="PASTE-YOUR-API-KEY"
export CODEX_CA_CERTIFICATE="/full/path/to/your-project/caddy-root-ca.crt"
cd /full/path/to/your-project
code .
```

The certificate must be a **full path**, not just the file name.

If your personal config uses the `[http_headers]` block, only `CODEX_CA_CERTIFICATE` is needed. If it uses `env_key = "UT_API_KEY"`, both are.

VS Code hands its own environment to the panel, so the variables have to exist *before* it starts. Two things therefore do not work: setting them in VS Code's integrated terminal (that changes only that one terminal, and it closes with the app), and closing the window instead of quitting.

To avoid repeating this every time, put the two `export` lines in your shell profile (`~/.zshrc` or `~/.bashrc`) and always start VS Code with `code .` from a terminal.

<figure><img src="https://2654650065-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXgNPw9jE3xyWIcnvYeCB%2Fuploads%2FKnRPnYACSV1xSGjufuzO%2Fimage.png?alt=media&amp;token=1d12dc2c-8b30-4009-b3e0-b9f12318b797" alt=""><figcaption></figcaption></figure>

***

### OpenCode

#### Install

Install the CLI by following the official instructions for your platform: [**https://opencode.ai/docs**](https://opencode.ai/docs)

For the editor integration, install **opencode**.

<figure><img src="https://2654650065-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXgNPw9jE3xyWIcnvYeCB%2Fuploads%2FCqOmWOJrUsV6XmDzscvg%2Fimage.png?alt=media&amp;token=b31a310f-4b74-4ac2-a7db-f4be155bba81" alt=""><figcaption></figcaption></figure>

#### Configure

Create `opencode.json` in the project root:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "understand": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Understand AI",
      "options": {
        "baseURL": "https://understand.local/api/llm/v1",
        "apiKey": "PASTE-YOUR-API-KEY"
      },
      "models": {
        "uai-large": { "name": "Understand AI" }
      }
    }
  },
  "model": "understand/uai-large",
  "small_model": "understand/uai-large"
}
```

Both `model` and `small_model` are required. Without the second, OpenCode looks for a cheaper model that your DGX box does not provide.

Create a launcher for the certificate. Save it as `opencode-local.sh` in the project root:

```bash
#!/usr/bin/env bash
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export NODE_EXTRA_CA_CERTS="$DIR/caddy-root-ca.crt"
exec opencode "$@"
```

Then make it runnable:

```bash
chmod +x opencode-local.sh
```

<details>

<summary>Windows (PowerShell), save as <code>opencode-local.ps1</code></summary>

```powershell
$dir = $PSScriptRoot
$env:NODE_EXTRA_CA_CERTS = "$dir\caddy-root-ca.crt"
opencode @args
```

</details>

#### Start using it

**Terminal**, from the project folder:

```bash
./opencode-local.sh
```

Check the connection with `opencode models understand`. It should print `understand/uai-large`.

**VS Code**: the extension opens OpenCode in a terminal, so add the certificate to your workspace settings (`.vscode/settings.json`) and it will be picked up:

```json
{
  "terminal.integrated.env.osx": {
    "NODE_EXTRA_CA_CERTS": "${workspaceFolder}/caddy-root-ca.crt"
  },
  "terminal.integrated.env.linux": {
    "NODE_EXTRA_CA_CERTS": "${workspaceFolder}/caddy-root-ca.crt"
  },
  "terminal.integrated.env.windows": {
    "NODE_EXTRA_CA_CERTS": "${workspaceFolder}\\caddy-root-ca.crt"
  }
}
```

***

<figure><img src="https://2654650065-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXgNPw9jE3xyWIcnvYeCB%2Fuploads%2FAKhNh2bPKDH6eQ2eIhD2%2Fimage.png?alt=media&amp;token=0c4642b7-483b-49eb-8f72-020137610094" alt=""><figcaption></figcaption></figure>

### If something does not work

| What you see                                                | What it means                                               | What to do                                                                                |
| ----------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| `Missing API key` or `401`                                  | the key did not reach the DGX box                           | check for a typo, and that you edited the file in the project you are actually working in |
| `Invalid or expired API key`                                | the key was rejected                                        | create a new one at `/developer`                                                          |
| `Unknown model 'uai-large'`                                 | your DGX box offers different model names                   | ask your administrator which name to use                                                  |
| `SSL certificate verification failed`                       | the certificate is not being found                          | check the path, and that the file is the one exported in step 1                           |
| `unable to get local issuer certificate`                    | the certificate has changed                                 | export it again (prerequisite 1) and replace the file                                     |
| `permission denied: ./codex-local.sh`                       | the script is not marked runnable                           | `chmod +x codex-local.sh`                                                                 |
| Codex: `Ignored unsupported project-local config keys`      | Codex will not read provider settings from a project folder | use `./codex-local.sh` instead of `codex`                                                 |
| Codex: `Missing environment variable` in the **terminal**   | your config expects the key in the environment              | use the `[http_headers]` block shown above                                                |
| Codex: `Missing environment variable` in the **side panel** | the panel does not see variables set after VS Code started  | follow "Using the Codex panel", including the full quit and restart                       |
| `429` or "rate limit"                                       | too many requests in a short time                           | wait a moment, and if it persists ask for your own key                                    |
| Long sessions fail after a while                            | the conversation grew past the DGX box's limit              | start a new conversation                                                                  |

Still stuck? Send your administrator the exact error message and the name of the tool you were using.
