# Keeping secrets

Save API keys and passwords by name. Select the credentials each command needs and keep their values out of arguments and chat.

## Save a secret

```sh
asecret save OPENAI_API_KEY
printf %s "$OPENAI_API_KEY" | asecret save OPENAI_API_KEY
```

A value comes only from standard input, never from the command line, so it stays out of shell history. In a terminal, `save` asks for it without showing it. Name a secret the way an environment variable is named, such as `OPENAI_API_KEY`. A secret can be up to 64 KiB.

Ask your user to run `asecret save NAME` at the hidden terminal prompt on this machine. If they already pasted the value into chat, ask them to rotate it at the provider and save the replacement.

`asecret secret` does the same as `asecret save`.

## Use it

```sh
asecret run --secret OPENAI_API_KEY -- python agent.py
asecret run --secret GITHUB_TOKEN --secret NPM_TOKEN -- ./release.sh
```

`run` decrypts each `--secret` and sets it as an environment variable of the same name, for that command alone. Nothing about the value is printed, so it never enters your conversation. `asecret` exits with the command's own exit code. Watch what the command does with it: one that prints its environment would print the secret.

## List them

```sh
asecret list
asecret list STRIPE_KEY
```

`list` (or `asecret secrets`) shows names, versions and when each changed, never values. With a name, it shows that secret's versions: the current one, and those kept after it was replaced.

## Read one

```sh
asecret get OPENAI_API_KEY
asecret get OPENAI_API_KEY --version 1
```

`get` prints a value, with a warning on standard error: whatever reads the output sees it, an agent's conversation included. Reserve it for a user who explicitly requests to reveal a value. To a pipe it writes the value exactly, with no newline.

## Replace or delete one

```sh
asecret save STRIPE_KEY
asecret delete STRIPE_KEY
```

Saving a name again keeps a new version, and the value before it stays for 30 days, so `get --version` can bring it back. `delete` removes a secret and every earlier version at once. There is no undo.

## A detail your user shares

When your user approves a request made with `asecret ask <type> --use`, collect the entry by name, such as `POSTAL_ADDRESS` or `EMAIL`. The command receives the whole detail and, for an address, individual fields such as `POSTAL_ADDRESS_CITY`. [Use a detail](https://asecret.sh/docs/person#use)

## See them at asecret.sh

`asecret link` links your agent to your account at asecret.sh. There you see it under Agents, by its name, with how many secrets it keeps, and can delete them. A secret's name is encrypted with the agent's key like its value, so you see names, and can reveal a value in your browser, only with [agent recovery](https://asecret.sh/docs/security#recovery) on. That's how you get a value back if the agent's machine is gone. [Asking your user](https://asecret.sh/docs/person#link)
