Connect Claude to Resources
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
Section titled “Prerequisites”-
macOS or Linux
-
Claude Code installed
-
The Keycard CLI installed:
Terminal window brew install keycardai/tap/keycard -
The Keycard plugin for Claude Code: in the root of your project, run
keycard plugin install claude. -
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).
Set up the project directory
Section titled “Set up the project directory”Create (or open) a directory that holds two files: a keycard.toml and a
.mcp.json.
my-project/├── keycard.toml└── .mcp.jsonkeycard.toml
Section titled “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: 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.
.mcp.json
Section titled “.mcp.json”.mcp.json declares the project’s MCP servers. Claude Code reads it from the
project root. 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": { "type": "http", "url": "https://mcp.datadoghq.com/", "headers": { "DD-API-KEY": "${DD_API_KEY}", "DD-APPLICATION-KEY": "${DD_APP_KEY}" } }, "linear": { "type": "http", "url": "https://mcp.linear.app/mcp", "headers": { "Authorization": "Bearer ${LINEAR_API_KEY}" } } }}Start a Keycard session
Section titled “Start a Keycard session”Launch Claude Code inside a Keycard session:
keycard run claudeConsents you gave at sign-in last until you sign out. The first time
keycard run claude fetches a credential for a Resource, it may open your
browser once more so you can let the Keycard CLI access that Resource.
Claude Code then detects the MCP servers from .mcp.json and asks you to confirm
connecting to them. Approve, and the MCP servers start with the credentials Keycard
already fetched.
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
Section titled “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-consoleservice.
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
pupCLI to list the monitors forsvc-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
Section titled “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; 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 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.
What’s next
Section titled “What’s next”Credentials are only half the story. To decide which tools the agent may call with them, put its MCP servers behind a Gateway and write the rules there: Allow or deny specific tools shows the Cedar for allowing one tool and refusing the next, per person or group. Connect coding agents walks through the Gateway setup with Linear.
Keycard records the tool calls your agent makes during the session. See Audit Log & Sessions to trace what the agent did in the Keycard Console.