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 -
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 an
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 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
Section titled “Start a Keycard session”Launch Claude Code inside a Keycard session:
keycard run claudeThe first time (roughly once per sign-in), you’ll be asked to grant two consents:
- Management API access: lets the CLI talk to the Keycard Management API.
- 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
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; the session also decides what the agent is allowed to do with them. Continue with Control Tool Calls to enforce a default-deny Cedar policy on every tool call, add in-the-loop approvals, and audit the session in the Keycard Console.