Guide · Coding agents
Give coding agents API keys without handing them over
An agent that runs your tests needs the keys your tests use. It doesn't need to see them, keep them, or have them pasted into a chat window.
In shortKeep latchkey:// references in your env files and tell the agent to run commands through latchkey run. Each read asks you with Touch ID, showing the agent, folder and command, unless a grant you made covers it. For OpenAI and Anthropic keys, --proxy lets the command call the API without ever holding the key.
The usual shortcuts
Pasting a key into the conversation puts it in a transcript. Leaving it in .env lets the agent read the file, and so print, log or commit it. Exporting it in your shell hands it to everything that shell starts, for as long as it runs.
Set it up
-
Put references in the env files
Import the files so they hold
latchkey://references rather than values. -
Tell the agent how to run things
Add this to
CLAUDE.md,AGENTS.mdor your agent's instructions:Agent instructions Secrets are in Latchkey. Env files hold latchkey:// references, not values. Run anything that needs secrets as `latchkey run --env-file .env.local -- <command>`. Never run `latchkey get`, never print the environment, and never read or write values in .env files. If latchkey exits with 77 (refused) or 66 (missing), stop and ask; don't retry. -
Approve when it asks
When the agent runs
latchkey run, the approval panel names the agent, the programs it runs through, the folder and the full command. Choose to allow once, allow from that folder for a while, or Deny, then touch the sensor: Touch ID listens right in the panel, from whatever app you're in. Several requests the agent makes in a row share one panel, so one touch answers them all, and each can be denied on its own. A refused run exits with 77 and prints the exactlatchkey grantcommand that would allow it. -
Grant before you step away
Terminal lk grant 'shop/development/*' --session --for 4h lk grant 'shop/development/*' --command "npm test" --for 2hA session grant ends when the agent quits; a command grant covers only that command. Every read under a grant is listed in Activity, and you can revoke it early.
Keys the agent can use but never read
lk run --proxy --env shop/development -- npm testWith --proxy, the command gets a placeholder and a local address, and the real OpenAI or Anthropic key is added only to requests bound for that provider. --proxy-models and --proxy-requests limit which models it may name and how many calls it may make.
After the session
lk touched --since 4h --by claude
lk rotate --touched --since 4h --by claude --openSee every key released to programs the agent started, then replace the ones you'd rather it no longer knew. Rotation ends the grants that covered them.
What this doesn't do
Approvals and grants decide what reaches a command. They can't control what the command does with a value once it has it. Keep grants narrow and short, and deny requests you don't recognize.