---
url: /examples/harness-api-key.md
---
# Give the harness an API key

Keep your Anthropic API key in the OS keychain and make Claude Code use it in every run, without the agent seeing it. You end with a default [target](/configure/targets.md#targets) whose credential is the key. A target names the harness a run uses and how it logs in.

Without a credential, Claude Code uses its own login, or the `ANTHROPIC_API_KEY` in your shell, which the agent and the tools it runs can read too. With a target credential, the harness gets a placeholder, and Pandra's proxy puts the key in its place only in requests to the provider's API.

## 1. Store the key

Register a [logical secret](/secrets.md), a name for where the key lives. Pandra asks for the key and hides what you type:

```sh
pandra config secret set anthropic-api-key --keychain
```

On Linux, the keychain needs GNOME Keyring or KWallet. To read the key from 1Password, a file, or a command instead, use another source flag, such as `--1password` or `--file`; [secret stores](/secrets/stores.md) lists them.

## 2. Make a target that logs in with it

Create the target `claude-api`, which logs in to Claude Code with an API key from the secret, and make it the default target, which every agent uses unless its own settings name another:

```sh
pandra config target set claude-api --harness claude-code \
    --login api-key --secret anthropic-api-key
pandra config target use claude-api
```

`pandra config target set` prints the variable that the harness reads the key from:

```text
wrote env.ANTHROPIC_API_KEY = { secret = "anthropic-api-key" } to targets.claude-api (anthropic api-key)
```

Codex and Pi take other login methods and variables: see the login sections of [Codex](/harnesses/codex.md#login) and [Pi](/harnesses/pi.md#login).

## 3. Check a run

In an agent project, `--dry-run` shows the plan of a run without starting it. Its `Credentials` section shows where the key comes from (shortened here):

```sh
pandra run . --dry-run
```

```text
Run plan for . (nothing was started)

...
Harness     claude-code                                 target claude-api
Backend     host
Target      claude-api                                  defaults
...

Credentials
  ANTHROPIC_API_KEY  secret anthropic-api-key (keychain), through Pandra's proxy
...
```

[Learn more about target credentials →](/configure/targets.md#target-credentials)
