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

  1. See what was released

    lk touched lists the items released to commands in a time window, including through lk run. --by claude narrows it to programs running under claude, 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 claude

    Without --by you get every release in that time, to anything. If you worked under a single grant, --grant ID lists what that grant released. Add --json for scripts.

  2. Replace them with one command

    Give lk rotate the same filters and it works through the same list, one item at a time. Add --open to open the service's key page where Latchkey knows it, and --push to send the new values to the environments you linked.

    Terminal
    lk rotate --touched --since 4h --by claude --open --push

    First 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.

  3. 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
  4. 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

The CLI reference has the full option list, and the security page says where protection ends.

Related