For Docker, set the key in the container's environment.
Agent Relay reads pool secrets only at startup.
When you rotate a key, update the secret, then restart Agent Relay.
The environment key never leaves Agent Relay.
When Agent Relay dispatches a session, it hands the workspace the session's Anthropic-signed work order instead.
The work order:
- Authenticates the runner to Anthropic for that one session.
- Locks the runner to the Anthropic account the session was issued for.
- Reaches the workspace as an ephemeral workspace build secret that later builds don't reuse.
The workspace agent sets it as `SELF_HOSTED_RUNNER_ENVIRONMENT_SECRET`.
Coder delivers the secret only to the workspace agent, never to the provisioner, so it doesn't appear in build parameters or Terraform state and can't be read back through the API.
### Step 4: Add the module to your template
Add the [`coder/agent-relay-claude-code`](https://registry.coder.com/modules/coder/agent-relay-claude-code) module and the `agent_relay_status` metadata item:
> Do not set `SELF_HOSTED_RUNNER_ENVIRONMENT_SECRET` in the template yourself.
> To upgrade from an early access module version, refer to [Upgrade from early access](./setup.md#upgrade-from-early-access).
The template must also meet the [template requirements](./setup.md#step-3-prepare-a-workspace-template) that apply to every provider.
To keep the worker from starting before your startup scripts finish, order the module after them, as described in [Start the worker after workspace setup](./setup.md#start-the-worker-after-workspace-setup).
The module starts `claude self-hosted-runner --capacity 1 --exit-if-unused-min 10 --release-idle-session-min 60` in the background, so the workspace agent reaches `ready` immediately.
A runner that never receives its session exits after 10 minutes, and Agent Relay deletes its workspace.
A session with no user message for the pool's `idle_release_timeout`, 60 minutes by default, is released: the runner exits, Agent Relay deletes the workspace, and the developer's next message resumes the session on a new runner.
Set `idle_release_timeout` on the pool to change the window, as a duration in whole minutes up to `168h`, such as `30m`, or set it to `0` to turn idle release off.
Refer to [Fields for every pool](./configuration.md#fields-for-every-pool).
> [!WARNING]
> The module runs every session with `--permission-mode bypassPermissions`, because no terminal is attached to answer approval prompts.
> Apply [default-deny egress](https://code.claude.com/docs/en/self-hosted-environments-deploy#default-deny-egress) to relay workspaces, or the agent can reach any host the workspace can.
### Step 5: Add the pool to the Agent Relay configuration
Each pool needs a unique `name`, an `organization`, a `template`, and a `secret_env` that names the environment variable holding its environment key.
<div class="tabs">
### Kubernetes
Add the pool and its secret to `values.yaml`:
```yaml
pools:
claudeCode:
- name:example
secret_env:CLAUDE_ENVIRONMENT_SECRET
organization:coder
template:claude-code-relay
# Optional: fixed values for template parameters. Use the
# parameters your template defines.
template_parameters:
region:us-east-1
# Optional: the Coder user who owns Claude Tag channel sessions.
# claude_tag_channel_user: <user-uuid>
# Optional: release a session after this long without a user message.
Pass `CLAUDE_ENVIRONMENT_SECRET` to the container alongside `CODER_AGENT_RELAY_CODERD_SESSION_TOKEN`, as shown in [Install with Docker](./setup.md#docker).
Agent Relay doesn't start without the session token.
</div>
Agent Relay rejects a `template_parameters` entry that uses a name it sets on every build: `agent_relay_session_id`, `agent_relay_delivery_id`, `agent_relay_pool`, `agent_relay_client_platform`, `agent_relay_claude_code_release_idle_session_min`, `agent_relay_credential`, `agent_relay_claude_code_lock_to_account`, or `agent_relay_attempt`.
To serve Claude Tag channel sessions, refer to [Configure Slack for Agent Relay](./slack.md#claude-tag-channel-sessions).
When the pool is configured, return to [Install Agent Relay](./setup.md#step-5-install-agent-relay).
- When a build succeeds but the runner never starts, Agent Relay v0.16.0 or later lets Anthropic retry the session only on its first delivery, and only within `dispatch_deadline` of the build's creation.
Otherwise, it fails the session, so a broken template doesn't rebuild in a loop.
> Each late build adds a delete and a rebuild to the same provisioners.
## Network requirements
Agent Relay needs outbound HTTPS to:
- Your Coder deployment's access URL.
-`api.anthropic.com`.
Workspaces need outbound HTTPS to at least:
- Your Coder deployment's access URL, plus any external DERP or STUN servers your deployment uses.
-`api.anthropic.com`, for the runner control plane, session streaming, and model inference.
-`github.com`, over port 443 or 22.
-`claude.ai` and `downloads.claude.ai`, if `install_cli = true` or sessions install Anthropic marketplace plugins.
Refer to [Anthropic's network requirements](https://code.claude.com/docs/en/self-hosted-environments-deploy#network-requirements) for the authoritative list before you finalize your allowlist.
- Connections are outbound only.
Anthropic never connects into your network.
- Corporate egress proxies work through `HTTPS_PROXY` and `NO_PROXY`.
Session streaming uses server-sent events, so a proxy in the path must not buffer responses.
| Coder [external authentication](../admin/external-auth.md) | Each session owner's own token for Git over HTTPS, with no credential in the image | The owner must link the provider. Claude Tag channel sessions run as a service account. |
| Credentials in the template or image | Your own Git identity and push credentials for any supported host | You own credential scope and rotation |
| Runner-managed Git config (`--configure-git`) | Claude's Git identity, Anthropic-signed commits, and a `Co-authored-by:` trailer for the session creator | No push credentials, so combine it with another approach. Requires Git 2.34 or later. |
| Anthropic Git proxy (`--use-anthropic-git-proxy`) | No Git credentials in the workspace. Anthropic serves Git with the session creator's GitHub token. | `github.com` only, session repositories only, and branch pushes only. Requires Git 2.32 or later. |
Agent Relay builds the workspace as the developer's matched Coder user, so the token belongs to that developer.
If the provider isn't marked `optional`, Coder refuses to create a workspace for a developer who hasn't linked the provider, and Agent Relay can't serve their session.
Claude Tag channel sessions run as a service account, so give them credentials from the template instead, as described in [Configure Slack for Agent Relay](./slack.md#set-up-claude-tag-channel-sessions).
Pass runner options through the module's `additional_args` input, with one list element per argument: