CLI reference

Every latchkey command and option. latchkey help prints a summary. Nothing here prints a value except latchkey get.

Conventions

Running commands

latchkey run

Synopsis
latchkey run [options] -- COMMAND [ARGS...]

Starts COMMAND with every latchkey://ID in its environment replaced by the item’s value.

OptionMeaning
--env-file FILELoad KEY=VALUE lines from FILE first. Repeatable.
--env PROJECT/ENVSet the environment’s variables from its record (see Environments). Without a record, or before env migrate has run, it also loads what the older lookup finds: each item in the environment as its name, plus the shared items in the same checkout as its files (as recorded on import), and says so. Repeatable.
--file NAME=IDSet NAME to the path of a temporary file holding the value, readable only by you and deleted when COMMAND exits. NAME=latchkey-file://ID in an env file does the same.
--no-maskingDon’t hide values in COMMAND’s output, and start it directly.
--proxyKeep OPENAI_API_KEY and ANTHROPIC_API_KEY out of COMMAND entirely (see below).
--proxy-models A,BWith --proxy: refuse requests that don’t name one of these models in their JSON body.
--proxy-requests NWith --proxy: refuse requests after N have been forwarded.
--aws-session, --aws-role ARN, --aws-for TIMEGive COMMAND short-lived AWS credentials instead of the long-lived key (see below).

Items that aren’t agent-safe or covered by a grant ask for approval first. Values of secret kinds that are 6 characters or longer are replaced with <concealed by latchkey> in COMMAND’s output, including values split across two chunks; multi-line values are hidden line by line. COMMAND’s exit status becomes latchkey run’s. If COMMAND is killed by a signal, the status is 128 plus the signal.

Examples
latchkey run --env-file .env.local -- npm run dev
latchkey run --env shop/development --env shop/vercel.preview -- npm test
latchkey run --file ASC_KEY_PATH=shop/production/ASC_P8 -- fastlane beta

Other credentials are delivered normally and are not protected by the proxy. Temporary files are distinct per full item ID.

latchkey check

Synopsis
latchkey check [--env-file FILE]... [--env PROJECT/ENV]... [--file NAME=ID]... [IDS] [--json]

What latchkey run with the same options would get without asking (agent-safe or covered by a grant), what would ask you, and what’s missing. Asks nothing and releases nothing. Exits 66 if an item is missing, otherwise 0.

Example
$ latchkey check --env-file .env.local
agent-safe        shop/development/PGHOST
granted           shop/development/DATABASE_URL  (grant k3v9q2, 1 hour, 12 minutes left)
asks              shop/development/STRIPE_KEY

latchkey mcp

Serves Latchkey’s tools to an agent over MCP, on standard input and output. See Latchkey’s MCP server.

Keys that never reach the command: --proxy

With --proxy, a variable that is exactly a reference to an OpenAI or Anthropic key gets a placeholder instead, and OPENAI_BASE_URL or ANTHROPIC_BASE_URL points at a port on this Mac that latchkey run listens on. Requests there that carry the placeholder go to api.openai.com or api.anthropic.com with the real key in its place; anything else is refused. The command can use the key but can’t read, print or send it anywhere else.

Terminal
latchkey run --proxy --env shop/development -- npm test

It works with programs that use the OpenAI or Anthropic SDKs (or read those base URL variables). The run is refused if a supported key is not a whole reference, its base URL is already set, or the key would also be delivered through another variable or key file; unset custom base URLs first. At least one supported key reference is required.

Only COMMAND and the processes it starts can use the proxy: a request from any other program, even one that knows the placeholder, gets a 403, and the proxy stops when COMMAND exits. A process that detaches from COMMAND (so launchd adopts it) is refused too.

--proxy-models and --proxy-requests narrow what COMMAND may do with the key. With --proxy-models, only requests with a JSON body naming a listed model are forwarded, so GET /v1/models, multipart uploads and compressed bodies are refused. When either is set, latchkey run prints latchkey: proxy limits enforced: ... on standard error. Both need --proxy. For the MCP tool, see Agents and MCP.

Terminal
latchkey run --proxy --proxy-models gpt-4o-mini,gpt-4o --proxy-requests 200 --env shop/development -- npm test

Short-lived AWS credentials

With --aws-session, latchkey run signs a request to AWS STS with your long-lived access key (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, both references) and gives COMMAND the temporary credentials STS returns, including AWS_SESSION_TOKEN. --aws-role ARN assumes that role instead. They last 15 minutes unless --aws-for says otherwise (at most 12 hours). The long-lived key never reaches COMMAND, and no AWS CLI is needed. MFA isn’t supported yet.

Terminal
latchkey run --aws-role arn:aws:iam::123456789012:role/dev --aws-for 1h --env shop/development -- terraform plan

latchkey get

Synopsis
latchkey get ID

Prints one value. Asks unless the item is agent-safe or covered by a grant. Keep agents away from it.

Items

CommandWhat it does
latchkey list [--project P] [--json]IDs grouped by project and environment, with kind, service, whether agents may read them, and the note. --json prints the same as JSON (see the item shape). Never values.
latchkey set ID [--kind KIND] [--agent-safe] [--note TEXT] [--service NAME]Add or change an item. The value comes from standard input, or a hidden prompt in a terminal. Kinds: token, password, key, value. Replacing a value keeps the old one as a version. Asks.
latchkey update IDS|PATTERN... [--agent-safe yes|no] [--kind KIND] [--service NAME] [--note TEXT] [--fill-sites HOSTS]Change settings on many items with one approval. Values are untouched. --service "" clears the service. --fill-sites vercel.com,app.netlify.com sets the only sites Latchkey for Safari may fill the items on (each covers its subdomains; up to 20); --fill-sites "" goes back to the default: the service’s own site and the deployment platforms.
latchkey rm IDS|PATTERN...Delete items with one approval; they go to Recently Deleted for 30 days. If any named item doesn’t exist, nothing is deleted.
latchkey mv IDS | --from-file FILE --to PROJECT/ENV | --shared [--file FILE]...Move items into a project’s environment, or back to shared, with one approval. Values, settings and history move with them. References are then updated in the files the items came from, each --file, and the --from-file file, which moves every shared item it refers to. If any target ID already exists, nothing moves.
latchkey duplicates [--json]Lists groups of items holding the same value, counted by kind at the top, and what to do about each, with the command to run. See below.
latchkey combine IDS --into NAME|ID [--file FILE]...Makes items holding one value into one shared item, with one approval. See below.
latchkey scan [DIR] [--json], scan --staged, scan --install-hook [--force]Finds env files that still hold plain values. See Scanning env files.
Examples
printf %s "$TOKEN" | latchkey set shop/production/STRIPE_KEY --kind token --service Stripe
latchkey update 'shop/development/*' --agent-safe no
latchkey list --project shop --json

latchkey duplicates

Synopsis
latchkey duplicates [--json]

Lists groups of items holding the same value, counted by kind at the top, and what to do about each, with the command to run:

Values are compared inside Latchkey and never shown; plain values and values shorter than 8 characters are left out. It asks for approval every time (grants and agent-safe settings don’t stand in), and agents can’t ask. --json gives items, advice, summary and into for each group.

latchkey combine

Synopsis
latchkey combine IDS --into NAME|ID [--file FILE]...

Makes items holding one value into one shared item NAME, or into one item ID of the environment they’re all in, with one approval. NAME is created from them (agent-safe only if every one was; the service if they agree; where they were used, combined), or must already hold the same value. The others go to Recently Deleted, environment records point at NAME, and references are updated in the files the items were imported from and in each --file. If the values differ, nothing changes. Agents can’t combine.

Example
latchkey duplicates
latchkey combine shop/development/OPENAI_API_KEY,blog/development/OPENAI_API_KEY --into OPENAI_API_KEY

latchkey scan

Synopsis
latchkey scan [DIR] [--json]
latchkey scan --staged
latchkey scan --install-hook [--force]

Finds env files under DIR (default: the current folder; .env, .env.* and *.env, not examples, templates or backups, not in node_modules, build or .git folders) that still hold plain values, and prints each as FILE:LINE NAME with the reason, never a value:

It exits 1 when anything is found, so it works in scripts. If Latchkey can’t compare (not approved, not running), the values that look secret are still reported, and it exits 1. --json gives place, key, reason (stored or looks-secret) and items for each finding.

--staged scans only the lines a commit would add, from the Git index, in env files that are staged.

--install-hook writes a Git pre-commit hook (honoring core.hooksPath, and worktrees) that runs latchkey scan --staged and refuses the commit on findings. A hook that isn’t Latchkey’s is left alone unless --force. If neither lk nor latchkey is on the PATH, the hook says so and lets the commit through. Skip it for one commit with git commit --no-verify.

Examples
latchkey scan ~/Projects/shop
latchkey scan --install-hook

Environments

Each environment has a record: its variables, each pointing at an item (shared items too) or holding a plain setting such as PORT=3000. Records sync with your items, so an environment works the same on every Mac, wherever its checkout is. Import, set and mv keep them current.

CommandWhat it does
latchkey env [list], latchkey env show PROJECT/ENV [--json]Records, and one record’s variables. Unconfirmed variables are marked.
latchkey env migrate [--dry-run]Makes or completes records from your items and, where they’re on this Mac, the files they came from. Only adds: a stored variable is never changed, and running it again is safe. Reports conflicts, missing items, missing files and plain values that may be secret. What it found through files is unconfirmed until env confirm. Only numbers up to six digits and true/false are recorded from files without asking you. Asks once.
latchkey env set PROJECT/ENV NAME=latchkey://ID|NAME=VALUE..., env unset, env confirmChange one record. NAME=latchkey://ID points a variable at an item (it must exist); NAME=VALUE is a plain setting. A plain setting that looks secret is refused: save it as an item and point the variable at it. env confirm with no names confirms everything unconfirmed. Asks once.
latchkey env rm PROJECT/ENVForgets an environment’s record, with one approval. Its items stay, and run --env goes back to finding them by ID until a record is made again.
latchkey project [DIR], project link [NAME] [DIR] [--remote R], project unlink NAME [DIR], project listWhich project a checkout is, from its Git remotes (never with credentials). project shows the matching project, its environments, and the export command to run. link remembers the checkout’s origin (or --remote R, or its only remote) as project NAME, by default the folder’s name, so clones on your other Macs are recognized; it asks. A remote belongs to one project; unlinking a project’s last remote forgets the project. A match only names the project: it never releases a value or widens a grant. A match through a remote other than origin, as a fork has, is flagged and never taken as the project.

Export

latchkey export

Synopsis
latchkey export PROJECT/ENV [--out FILE [--merge [--yes] | --replace]] [--values [--clipboard]]

Writes the environment’s env file from its record: latchkey:// references and plain settings, sorted by name, to standard output or FILE.

Examples
latchkey export shop/development --out .env.local --merge
latchkey export shop/development --values --clipboard

Importing

Synopsis
latchkey import FILE... [options]
OptionMeaning
--batch LISTAlso import the files listed in LIST, one path per line (# comments allowed).
--scan DIRAlso import every .env and .env.* under DIR, skipping examples, templates, backups, and dependency, build and .git folders.
--project P, --env EPlace items here instead of what the repository and file name imply.
--sharedImport as shared items named after their keys.
--share-identicalWith several files, make a name with the same value in every file one shared item.
--rewriteReplace each imported value in its file with its reference.
--replaceOverwrite items that already exist (old values are kept as versions).
--dry-runShow what would happen, with a count per class and each setting it would leave; send nothing.
--only KEY,...Import only these keys (one file only).
--kind KIND, --kind KEY=KINDKind for all keys, or one.
--class KEY=secret|setting|publicChange how a line is classed (see below). --kind KEY=KIND also decides the class.
--agent-safe KEY,... or allMark keys agent-safe.
--agent-safe-pattern PATTERN,...Import matching names as agent-safe plain values.
--skip PATTERN,...Leave matching names alone.
--no-default-skipImport VERCEL_OIDC_TOKEN, VERCEL_* and TURBO_* too.

Imports support quoted multiline values and refuse malformed syntax before saving anything. Rewriting replaces the complete assignment and stops if the file changed while approval was pending.

Classes

Each line is classed before anything is saved:

ClassExamplesWhat import does
SecretTokens, passwords, connection strings with credentials, key blocksSaved masked
SettingPORT, NODE_ENV, LOG_LEVEL, *_ENABLED, *_PORT, true/false valuesLeft in the file
PublicNEXT_PUBLIC_*, VITE_*, PUBLIC_*, EXPO_PUBLIC_*, REACT_APP_*, publishable and public keys, IDs and hosts, web addresses with no credentialsSaved as a plain value (not masked, not agent-safe unless you say so)
Referencelatchkey://...Left alone

A value that carries credentials (a key block, a URL with a user or password) is a secret whatever its name says, and anything unclear is a secret. Settings stay in the file, so --rewrite doesn’t touch them. In the app, the Class column of the import sheet does the same as --class. Classes aren’t remembered between imports yet.

Example
latchkey import .env.local --dry-run
latchkey import .env.local --rewrite --class FEATURE_FLAGS=setting

History

CommandWhat it does
latchkey history IDEarlier values: when, why (replaced, deleted, replaced by a restore) and by whom. Never values.
latchkey restore ID [--version N]Put back version N (1 is the most recent), or bring back a deleted item with its settings. The current value is kept as a version first. Asks.
latchkey deletedItems deleted in the last 30 days, with days left.
latchkey forget IDSDelete earlier values for good. Asks.

Grants

CommandWhat it does
latchkey grant IDS [--folder DIR] [--for TIME] [--session] [--command CMD]... [--once]Let commands run from DIR (default: here), the folders inside it and that repository’s worktrees read these items without asking. TIME is like 30m, 2h, 1d, or always for a grant that lasts until revoked; default 1 hour, no maximum. IDS can include patterns. Asks once.
latchkey grantsGrants in effect, with time left and any limits.
latchkey revoke ID or allEnd a grant, or all of them. Doesn’t ask.

Narrow a grant with --session (it ends when the agent you run it under quits, and covers only programs started under it), --command "npm test" (only latchkey run of that command, read from the signed tool’s own command line), or --once (one request). The approval panel offers the same: until claude quits and Only for ….

Rotating

CommandWhat it does
latchkey touched [--since 24h] [--by NAME] [--grant ID] [--json]Items Latchkey released in that time: to anything, to programs under NAME (such as claude), or under one grant. From the access log; never values.
latchkey rotate IDS|PATTERN... | --touched [...] [--open] [--push]Replace items one by one: ends grants that cover them, shows where to make each new key (--open opens it), asks for the new value (the old one stays in history), then pushes to linked environments with --push.
After an agent session
latchkey touched --since 4h --by claude
latchkey rotate --touched --since 4h --by claude --open --push

Latchkey can’t make the new key for you: Stripe, GitHub, OpenAI and most services issue keys only in their dashboards. It takes you to the page, saves what you paste, and puts it everywhere it’s linked.

Remote locations

CommandWhat it does
latchkey remote list [PROJECT/ENV]Links, with when each was last pushed.
latchkey remote link PROJECT/ENV SERVICE KEY=VALUE...Link an environment. SERVICE is vercel, github, railway, fly or ssh (host= and script=; see a service on a Linux server). Asks.
latchkey remote unlink LINKRemove a link. Doesn’t ask.
latchkey remote status PROJECT/ENVNames missing on each side, and values changed since the last push.
latchkey push PROJECT/ENV [--to LINK] [--only IDS] [--dry-run]Push values with each service’s own tool, values on standard input. Asks every time; production needs its own confirmation in the app. Nothing is deployed.
ServiceKeysTool
vercelenvironment= (development, preview or production), and project= or dir=; optional branch= for one preview branchvercel
githubrepo=owner/repo; optional environment= (leave out for repository secrets)gh
railwayenvironment=, service=, and project= or dir=railway
flyapp=flyctl

The log

CommandWhat it does
latchkey log [--limit 20]Recent access log entries: time, what, decision, items, who, folder and command. Never values; likely secrets in command lines are redacted.
latchkey log --verifyChecks the log’s chain: exits 0 if every entry is as Latchkey wrote it, 1 with the first line that isn’t.

Status

Synopsis
latchkey status

Where values are kept, how you approve, how many items and grants, and the socket path.

Environment variables

VariableMeaning
LATCHKEY_NO_LAUNCH=1Don’t start the app if it isn’t running; fail with exit 69 instead.
LATCHKEY_SOCKET=PATHConnect to a socket forwarded over SSH from the Mac running Latchkey (see from another Mac).

Exit codes

CodeMeaning
0Done
64Wrong usage
66No item with that ID
69The Latchkey app can’t be reached
73A file couldn’t be rewritten
77Refused: not agent-safe, not approved, no grant
127The command couldn’t start

On 66 and 77, Latchkey prints the item IDs and what to do, including the latchkey grant command that would allow the refused items.