---
title: Connect Claude to Resources | Keycard
description: Hydrate credentials from Keycard into Claude Code session.
---

Give a coding agent access to the services it needs without pasting secrets into config files. This guide covers the two ways Keycard distributes credentials: **static** secrets (using Datadog as the example) and **OIDC / OAuth** credentials (using Linear). Both flow into a Claude Code session through the same mechanism.

By the end you’ll have a project that:

- Hydrates environment variables from Keycard-managed Resources
- Runs Claude Code inside a Keycard session
- Boots MCP servers already authenticated with Keycard-issued credentials

## Prerequisites

- macOS or Linux

- [Claude Code](https://claude.com/claude-code) installed

- The Keycard CLI installed:

  Terminal window

  ```
  brew install keycardai/tap/keycard
  ```

- Access to a Keycard Org and a Zone that already has the Resources you want to use (this guide assumes Datadog and Linear Resources have been configured by an admin; see [Configure Resources](#configure-resources)).

Note

This guide picks up after account setup. If you haven’t authenticated yet, run `keycard init` first to sign in and generate your `policy.cedar`.

## Set up the project directory

Create (or open) a directory that holds two files: a `keycard.toml` and an `mcp.json`.

```
my-project/
├── keycard.toml
└── mcp.json
```

### keycard.toml

`keycard.toml` tells Keycard which **Org** and **Zone** to use, and maps local environment variables to the Keycard **Resources** that hydrate them.

- **Org**: your Keycard Organization.
- **[Keycard Zone](/concepts/zones/index.md)**: a boundary around a group of Resources and configuration for a particular use case. All the Resources in this guide live in one Zone.
- **Credentials**: a map between local environment variables and the Resources that get exchanged to fill them in.

```
[org]
id = "<org-id>"


[zone]
id = "<zone-id>"


# Datadog: distributed as static secrets from a Keycard Vault.
[[credentials.default]]
env_var  = "DD_API_KEY"
resource = "<datadog-api-key-resource>"


[[credentials.default]]
env_var  = "DD_APP_KEY"
resource = "<datadog-app-key-resource>"


[[credentials.default]]
env_var  = "DD_SITE"
resource = "<datadog-site-resource>"


# Linear: an OIDC credential minted from an external OAuth Provider.
[[credentials.default]]
env_var  = "LINEAR_API_KEY"
resource = "<linear-api-key-resource>"
```

Each `[[credentials.default]]` entry needs an `env_var` and a `resource`. The `default` set is the one `keycard run` hydrates.

Static vs. OIDC: why it doesn't change the config

The Datadog API key, app key, and site are stored as **static** values in a Keycard Vault (an admin pasted them in once). The Linear API key is **OIDC**: Keycard mints a fresh, scoped token from an external OAuth Application each time. From `keycard.toml`’s point of view they look identical: every value flows through the same credential mechanism, which keeps environment management uniform. (The app key and site are effectively static and could be provided some other way, but routing them through Keycard keeps everything in one place.)

### mcp.json

`mcp.json` declares the MCP servers Claude Code should connect to. Reference the hydrated environment variables using `${VAR}` interpolation. This is a Claude Code feature: it expands the variables from the environment when it boots, so the MCP servers come up already authenticated with the Keycard-issued credentials.

```
{
  "mcpServers": {
    "datadog": {
      "url": "https://mcp.datadoghq.com/",
      "headers": {
        "DD-API-KEY": "${DD_API_KEY}",
        "DD-APPLICATION-KEY": "${DD_APP_KEY}"
      }
    },
    "linear": {
      "url": "https://mcp.linear.app/",
      "headers": {
        "Authorization": "Bearer ${LINEAR_API_KEY}"
      }
    }
  }
}
```

## Start a Keycard session

Launch Claude Code inside a Keycard session:

Terminal window

```
keycard run claude
```

The first time (roughly once per sign-in), you’ll be asked to grant two consents:

1. **Management API access**: lets the CLI talk to the Keycard Management API.
2. **Token exchange**: lets the CLI exchange and provide the tokens for your configured Resources.

These consents are remembered, so you won’t be prompted on every run.

Claude Code then detects the MCP servers from `mcp.json` and asks you to confirm connecting to them. Approve, and Keycard hydrates the credentials and hands them to the MCP servers.

**Verify the connection.** Run `/mcp` inside Claude Code. If the Datadog and Linear servers show as connected, the exchanged credentials were valid; an invalid credential would fail the connection.

## Use the credentials

The hydrated credentials work anywhere in the session, both through MCP servers and through CLI tools that read the environment variables.

**Via MCP.** Ask the agent to work with Datadog monitors:

> List all the monitors for the `svc-console` service.

The Datadog MCP server is already authenticated with the Keycard-issued credentials, so the agent can query it and return results.

**Via CLI.** The same data can come from a CLI tool instead of MCP. Ask:

> Use the Datadog `pup` CLI to list the monitors for `svc-console`.

The `pup` CLI picks up `DD_API_KEY`, `DD_APP_KEY`, and `DD_SITE` from the hydrated environment, with no keys on disk and nothing exported in your shell profile.

## Configure Resources

The Resources used above were set up ahead of time in the Keycard Console. Pre-configured MCP and API servers can be installed straight from the [Catalog](/admin/catalog/index.md); the two in this guide were configured by hand:

- **Linear (OIDC).** An external OAuth Provider. An admin created a Linear OAuth Application, added its credentials to Keycard, and set the active scopes. Tokens Keycard mints for Linear carry exactly those scopes. See [brokered access](/concepts/resources/#brokered-access/index.md) for how this mechanism works.
- **Datadog (static Vault).** Not an external OAuth Provider but a Keycard Vault. An admin opened the Resource, clicked **Add credential**, and pasted the static values from Datadog. See [vaulted static credentials](/concepts/resources/#vaulted-static-credentials/index.md).

## What’s next

Credentials are only half the story; the session also decides what the agent is allowed to *do* with them. Continue with [Control Tool Calls](/guides/control-tool-calls/index.md) to enforce a default-deny Cedar policy on every tool call, add in-the-loop approvals, and audit the session in the Keycard Console.
