CLI
Install, authenticate, manage credentials, authorize resources, and run commands in secure sessions with Keycard.
The keycard CLI handles authentication, credential management, resource authorization, and secure agent sessions.
Install
Section titled “Install”brew install keycardai/tap/keycardVerify the installation:
keycard versionInstall plugin
Section titled “Install plugin”Install the Keycard plugin for Claude Code:
keycard plugin installThe plugin includes a set of Skills Claude uses to manage credentials and update keycard.toml.
Pull down the latest version of the plugin at any time:
keycard plugin updateSupported platforms
Section titled “Supported platforms”The Keycard CLI supports macOS and Linux on both amd64 and arm64 architectures.
Update
Section titled “Update”Update to the latest version with Homebrew:
brew upgrade keycardAuthentication
Section titled “Authentication”Sign into your Keycard account. The CLI opens an OIDC browser sign-in flow and stores the resulting tokens in your system keyring.
keycard auth signin --zone <zone-id> --org <org-id>| Flag | Description |
|---|---|
-z, --zone |
Zone ID. Falls back to ZONE or zone.id in keycard.toml |
-o, --org |
Organization ID |
--device |
Use the device authorization flow instead of a local browser. See Sign in from a headless or remote machine |
Sign in from a headless or remote machine
Section titled “Sign in from a headless or remote machine”The default sign-in opens a browser on the machine running the CLI and listens on a localhost port for the redirect back. That only works when the browser and the CLI share a machine. Over SSH, inside a container or devcontainer, on a cloud development VM, or on a build agent, there is no browser to open, and a redirect to localhost lands on the remote host where nothing can reach it.
The device authorization flow (RFC 8628) removes both requirements. The CLI prints a short code and a URL. You open the URL on any device with a browser, such as your laptop or phone, enter the code, and approve the sign-in. The CLI polls Keycard in the background and continues as soon as the code is approved. Nothing has to connect back to the remote machine, and no port is opened on it.
keycard auth signin --device --zone <zone-id> --org <org-id>The CLI prompts for two codes: the first signs you into your Keycard account, the second signs you into the Zone. Each prompt shows its own code and URL.
* Waiting for authorization…| Enter this code: ABCD-EFGH| Open: https://<keycard-issuer-url>/device| Or press Enter to open automaticallyIf a browser is available on the machine, press Enter to open the URL with the code prefilled. Otherwise, type the URL into a browser elsewhere and enter the code by hand. Each code expires after a few minutes; if it does, re-run the command to get a new one.
Set KEYCARD_DEVICE=1 in the environment to use the device flow by default, for example in a container image or a shell profile on a remote host. The tokens are stored in the same system keyring as a browser sign-in, so every other keycard command works the same way afterwards.
Check your current identity:
keycard auth whoami --zone <zone-id>Sign out and remove stored tokens. Accepts -z/--zone and -o/--org:
keycard auth signout --zone <zone-id>Resource authorization
Section titled “Resource authorization”Authorize access to one or more Resources. The command also initiates sign-in if you don’t have an active session.
keycard auth resource <uri>... --zone <zone-id>Use this when a tool reports that resource access requires authorization.
Running commands
Section titled “Running commands”Run a command inside a Keycard secure session to provision just-in-time credentials.
keycard run --zone <zone-id> -- <command>| Flag | Description |
|---|---|
-z, --zone |
Zone ID. Falls back to ZONE or zone.id in keycard.toml |
--itl-prompt |
In-the-loop prompter backend: osascript, browser, or native. Also settable via ITL_PROMPT |
Credentials are sourced from [[credentials.default]] entries in keycard.toml. See Configuration for details.
To run Claude Code inside a secure session, use the dedicated subcommand:
keycard run claude --zone <zone-id>Session environment variables
Section titled “Session environment variables”Inside a secure session, the following environment variables are set automatically:
KEYCARD_RUN=1: indicates the process is running inside a Keycard session.KEYCARD_RUN_SESSION_ID: the unique session identifier.
Credentials
Section titled “Credentials”Get an access credential for a Resource URI:
keycard credential read <uri> --zone <zone-id>The URI must be present in the default credential set. Configure it in keycard.toml first.
List all credential entries configured in keycard.toml that would be hydrated by keycard run:
keycard credential infoAdd a gateway credential entry, or sync credential configuration down from your Zone:
keycard credential addkeycard credential syncConfiguration
Section titled “Configuration”Config file
Section titled “Config file”The CLI loads configuration from keycard.toml in the current directory. Override the path with --config or CLI_CONFIG.
[zone]id = "<zone-id>"
[[credentials.default]]env_var = "GH_TOKEN"resource = "https://api.github.com"Global flags
Section titled “Global flags”| Flag | Description |
|---|---|
--config |
Configuration file path. Defaults to keycard.toml |
-h, --help |
Show help for a command |
The Zone ID is resolved from --zone, then the ZONE environment variable, then zone.id in keycard.toml. Commands that need a Zone fail with an explicit error if none of the three is set.
Commands
Section titled “Commands”| Command | Description |
|---|---|
keycard run |
Run a command in a Keycard secure session |
keycard run claude |
Run Claude Code in a Keycard secure session |
keycard auth signin |
Authenticate with your account |
keycard auth signout |
Remove local authentication tokens |
keycard auth whoami |
Identify the current account |
keycard auth resource |
Authorize access to Resources |
keycard credential read |
Read a credential for a URI |
keycard credential info |
Show configured credential identifiers |
keycard credential add |
Add a gateway credential entry |
keycard credential sync |
Sync credential configuration from your Zone |
keycard plugin install |
Install the Keycard plugin for Claude Code |
keycard plugin update |
Update the Keycard plugin for Claude Code |
keycard version |
Show version info. Accepts --json |
Agent commands
Section titled “Agent commands”| Command | Description |
|---|---|
keycard agent hook |
Process agent hooks |
keycard agent exec |
Run a command with credentials injected |
keycard agent api |
Make an authenticated Management API request |
Agent hooks
Section titled “Agent hooks”Process hook events from AI agents (Claude Code, Cursor, and others).
keycard agent hook <agent>Agent exec
Section titled “Agent exec”Run a command with credentials hydrated from [[credentials.default]] entries in keycard.toml. Unlike keycard run, this fails immediately if any credential requires interactive authentication. Safe for use in non-interactive agent subprocesses.
keycard agent exec --zone <zone-id> -- <command>Inside an agent exec subprocess, KEYCARD_AGENT_EXEC=1 is set automatically.
Agent API
Section titled “Agent API”Make an authenticated HTTP request to the Keycard Management API and print the response body to stdout.
| Flag | Description |
|---|---|
-X, --method |
HTTP method. Defaults to GET |
-d, --data |
JSON request body. Reads stdin if omitted |
-o, --org |
Organization ID |
-z, --zone |
Zone ID |
keycard agent api <endpoint>Use -X to override the HTTP method (default: GET):
keycard agent api <endpoint> -X POSTUse -d to pass a JSON request body (reads stdin if omitted):
keycard agent api <endpoint> -X POST -d '{"key":"value"}'Use -o / --org to specify an organization ID:
keycard agent api <endpoint> --org <org-id>