Guide · Rotation
Rotate the keys an AI agent touched
After a long agent session you can't say for sure which keys it ran with. Latchkey keeps a log of every release, so you can list those keys and replace them instead of guessing.
In shortRun lk touched --since 4h --by claude to list the items Latchkey released to programs under claude. Then run lk rotate --touched --since 4h --by claude --open --push to replace each one, end the grants that covered it and push the new value to linked environments.
Why you end up rotating everything
An agent runs commands for you, and those commands need keys. Once a command has a value, it is in that command's memory and environment. Masking hides exact copies in the output, but it can't stop a command that prints, sends or encodes the value in another form. So after a session you can't prove which keys stayed private.
The usual answer is to rotate every key in the project. That is slow, and people skip it. A better answer is to rotate only what the agent could have seen, and to have a list of that. Latchkey writes one entry to its access log for each release, with the program chain, folder and command. It never logs values. The list comes from that log.
For the setup that comes before the session, see Give coding agents API keys safely.
List the keys, then replace them
-
See what was released
lk touchedlists the items released to commands in a time window, including throughlk run.--by claudenarrows it to programs running underclaude, so keys you read yourself in the same hours don't show up. Use the same window you worked in.Terminal lk touched --since 4h --by claudeWithout
--byyou get every release in that time, to anything. If you worked under a single grant,--grant IDlists what that grant released. Add--jsonfor scripts. -
Replace them with one command
Give
lk rotatethe same filters and it works through the same list, one item at a time. Add--opento open the service's key page where Latchkey knows it, and--pushto send the new values to the environments you linked.Terminal lk rotate --touched --since 4h --by claude --open --pushFirst it ends any grant that covers these items. Then, for each item, it shows where to make the new key and asks for the new value; leave it empty to skip that item. You make the key in the service's dashboard and paste it in. The old value stays in the item's history. With
--push, the new value then goes to each linked environment, such as a Vercel project. A push asks every time, and production needs its own confirmation in the app. -
Rotate one key by name
You can also name items or use a pattern. This is useful when the list shows one key that matters more than the rest.
Terminal lk rotate shop/development/STRIPE_KEY --open --push -
Check Activity
Open Activity in the Latchkey app to see the same releases with more detail. An entry shows the action, the items, the decision, who asked through which programs, the folder and the command. You can filter by event and project.
Shorten the list next time
The smaller the grant, the shorter the list. A grant can end when the agent quits (--session), cover one command (--command) or last one use (--once). Keys behind --proxy never reach the command, so you can leave them out of the rotation, though they still appear in the list because lk run itself fetched them. The proxy guide covers that.
What this doesn't do
- It can't make the new key. Stripe, GitHub, OpenAI and most services only issue keys in their dashboards. Latchkey takes you to the page and saves what you paste.
touchedreads Latchkey's access log for values released to commands. It says nothing about what a command did with a value.- Values copied or written with
lk export --values, filled by Safari or shown from history are logged but not listed bytouched; check Activity for those. - Rotation replaces the stored value and ends grants. It does not recall a value that was already released, and it does not disable the old key at the service. Do that in the service.
- History keeps old values, with your approval to read them, for up to 30 days after deletion or until they are more than 10 versions old. Use Forget History when an old value shouldn't linger.
The CLI reference has the full option list, and the security page says where protection ends.