> **Agents: read this file raw, not summarized.** If your fetch tool returned a summary, fetch it again with `curl -fsSL https://tinycloud.one/agents/abilities/secrets` and follow that text. Summaries drop the shell blocks you must run.

# Use your TinyCloud Secrets from your agent

Your agent uses API keys and other secrets you keep in TinyCloud Secrets (secrets.tinycloud.xyz) without the value ever appearing in the conversation. When a secret is missing, it sends you a link where you add it yourself. It never asks you for a value.

## For the owner

- **Paste into your agent:** `Fetch https://tinycloud.one/agents/abilities/secrets with curl and follow it. Turn this script into a voiceover with ElevenLabs. Get the key from TinyCloud.`
- Your agent follows [the shared setup](https://tinycloud.one/agents/abilities/agent), keeps your account DID only for this conversation, reads the Secrets skill, then continues the same request. If it doesn't know the DID of your Secrets account, give it the address shown in Secret Manager; do not send it an API key.
- **You approve:** a Secret Manager `/request` link if a name is missing and a separate OpenKey request when the agent needs read access. The current read grant includes network-wide decrypt authority, not only the named secret. Check the exact items; you may decline any item. Then tell your agent you're done; there's no code to send back, and never send a value.
- **Undo:** `auth logout` clears only the agent's local session. Its grant remains valid until expiry or owner revocation; a provider key already read may require rotation.

## For the agent

**Read this page raw first.** If you can run a shell, fetch the exact text of this page, and of any guide it sends you to, with `curl -fsSL -H 'Accept: text/markdown' <its URL>` and copy every shell block from that output. A web-fetch tool that summarizes pages drops or rewrites the blocks, and they only work exactly as written.

**Send links exactly as printed.** Send the owner every link exactly as the CLI printed it, copied from the output: never retype, shorten or rebuild it.

Keep the owner's request, read [setup/agent.md](https://tinycloud.one/agents/abilities/agent), select **Secrets** and follow its steps. Choose a role-and-purpose-specific `TC_SECRETS_PROFILE` rather than silently sharing `api-keys`. Read and follow https://tinycloud.one/agents/abilities/skills/secrets.md, then continue the original task in this conversation. Missing CLI or owner DID is `NEEDS_SETUP`, not a reason to request a value in chat or a broad grant.

## Exit codes and owner lines

Secrets signs in with an OpenKey link, so the shared table covers that sign-in's exits; `secrets wait` and the data reads have their own codes (see the exceptions below), and the skill's own table gives each code. Its owner lines are the shared ones, with `<what>` = "access to your secrets".

**Exit codes and owner lines.** This table applies to the CLI approval commands `onboard`, `auth grant`, `auth login` without `--paste`, and `auth request --grant`. Codes named by a guide itself, such as `SPACE_SETUP_PENDING`, follow that guide. Commands under **Exceptions** have their own codes.

**Approval links: codes on cards, one tap in chat.** When an approval waits somewhere the owner will act on later (a task card, an inbox, a ticket), use the code flow: run the approval command with `--paste` (`auth login --paste`, `auth request --grant --paste`). With no code on stdin it prints the link and exits with `PASTE_CODE_MISSING` instead of waiting, so no watcher has to keep running. Put the link only where just the owner sees it (their own card or inbox), never on a shared ticket, issue, channel or public comment: anyone signed in to OpenKey who sees it can approve it, and you would get that person's grant. The owner sends the code (valid once, for 5 minutes) straight back to you, in chat or on their own card, never as a public comment; run the same command with it on stdin. It tells you the approval is done and carries what you need. Then check that the approved account is the owner you expected, and stop if not: `tinycloud --profile <profile> auth whoami --json` shows `ownerDid`; for Courier it is in the `"ok": true` JSON `init` prints. Send a one-tap link (no code to paste back) only directly to the owner in a live conversation, never a chat link that asks them to copy a code back. `onboard` has no code flow: run it only in a live conversation.

| Exit | Means | Do |
| --- | --- | --- |
| 0 | Done. | Send the done line, then carry on. |
| 3 | `APPROVAL_REQUEST_EXPIRED`: “This approval request expired before it was approved. Start a new request.” | Before doing anything else, use `pending.expiresAt` from the earlier exit-8 JSON and compare it with now. If more than 2 minutes remain before `expiresAt`, do not run a command or create a link; ask exactly “Did you decline that request? If not, I'll send you a fresh link.” and wait. Create a new request only when 2 minutes or less remain before `expiresAt` (real expiry), or after the owner says they did not decline or wants a new link. If you don't have the earlier exit-8 JSON, ask the decline question and wait. Never read `approval-pending.json`; it contains private keys. |
| 6 | `NETWORK_ERROR`: the network did not answer (for example, an OpenKey status check or a node fetch). | Run the same command again once; make no new link. For a resumed approval, the saved request is kept. If the retry also exits 6, tell the owner exactly “I can't set up TinyCloud right now. Please ask me again later.”, then put the stderr error code on its own line and stop. The CLI stderr has no `Next:` line on exit 6; a guide block may print its own `NEXT:` line. |
| 8 | Still waiting only when stdout contains a non-empty `pending.approvalUrl` link. Exit 8 without it is not pending. | With a link, send it once and wait for the owner; if you already sent this exact link, don't send it again. Follow the shared relay block's `Next:` lines rule. Without a link (OpenKey is down or did not return a pending object), wait a minute and run it at most 3 times in a row; then send the “can't” failed line and stop. This is a bounded retry, never pending. |
| 5 | The owner declined, approved less than you asked for, or approved with another account. | Stop and send the “couldn't” failed line, then the error code on its own line. Ask again only if the owner wants to. The 1.6.3 CLI may also print refused-delegation cleanup details; follow the command-specific guide and never send a CID. |
| Anything else | An error; stderr has `{"error":{"code":…}}`. | Any code not mapped above is an error: stop and send the “couldn't” failed line, then the code on its own line. Do not treat it as pending or retry. |

**The three owner lines, word for word.** `<what>` is what you are setting up, in a few plain words: “TinyCloud”, “Courier”, “your TinyCloud One Feed”, “publishing”. Call what the owner approves a permission.

- **Done**, on exit 0: “`<What>` is set up.”
- **Failed** when OpenKey stays down: “I can't set up `<what>` right now. Please ask me again later.”
- **Failed** otherwise: “I couldn't set up `<what>` this time. Tell me if you'd like me to try again.”

**Declined approval, owner line:** “Did you decline that request? If not, I'll send you a fresh link.”

**Exceptions: commands with other codes.**

- `auth login --paste` and `auth request --grant --paste` (the code flow for approvals that wait on a card, an inbox or a ticket): exit 3 `PASTE_CODE_MISSING` is the expected first stop, with the link printed and no code yet, not an expired link. These flows ask the owner for the code OpenKey shows after they approve. It works once, for 5 minutes; a used or expired code ends as exit 1, “Delegation code not found or expired”.
- `auth login --device` (the older apps sign-in): 3 is `DEVICE_AUTH_EXPIRED` and 5 is `DEVICE_AUTH_DENIED`, as above. Each new run counts toward OpenKey's limit of 5 device sign-ins per 10 minutes; over it, exit 1 `DEVICE_AUTH_RATE_LIMITED`.
- Data commands (`kv`, `sql`, `share`, `secrets get`, `feed`): exit 3 is `AUTH_REQUIRED`, a missing or expired session, so sign in again as the guide says; there is no link to resend. Exit 5 is `PERMISSION_DENIED` or `KV_ALREADY_EXISTS`, not the owner declining. Branch on the code.
- `secrets wait`: exit 8 means a named secret was still missing when the wait ended.
- Courier (`tinycloud courier …`): Courier 0.8.2 exits only 0, 1, 2 or 8; exit 6 is not a Courier code. Codes are command-specific; follow the Courier guide. For `init --request`, exit 0 may still create and print an approval link; follow every stderr `Next:` line by the shared relay rule, regardless of the exit code. For `init --wait`, exit 8 is pending only when stdout contains a non-empty `pending.approvalUrl`.
- Link-based CLI `auth request --grant` (without `--paste`) runs with `--timeout 60s`.

Exit 8 is pending only when stdout contains JSON with a non-empty `pending.approvalUrl`. Send each new URL once, exactly as printed, on its own line. Keep `pending.expiresAt` and end your turn. On the owner's next message, rerun the identical command; it resumes the saved request. Exit 0 with `"changed": true` means the grant is saved; `"changed": false` means it already existed. `auth retry --last` doesn't find grant requests. Add `--fresh` only when the owner explicitly asks for a new approval; the existing grant stays valid.

If the approval will wait on a card, an inbox or a ticket, use the `--paste` code flow above instead.
- Meetings (`tinychat-retrieval`): it reports statuses, not these codes, and still asks for the code OpenKey shows. The meetings guide says how.
- Helper scripts (`agent-env.mjs`, the apps skill's `.sh` helpers) have their own exit codes, listed where they run. For example, `layout.sh` exits 3 when `jq` is missing.

## Undo

- **Local session:** if you approved the agent, `"$TC_BIN" --profile "$TC_SECRETS_PROFILE" auth logout` clears that profile's session on this computer. Set `TC_BIN` to the CLI executable selected for this conversation, and use the actual role-specific `TC_SECRETS_PROFILE`. This does **not** revoke the grant or erase a value already read; the grant lasts until expiry or owner revocation. `PROFILE_NOT_FOUND` means this profile never signed in.
- **The agent's key:** the skill creates a local profile, `${TC_SECRETS_PROFILE:-api-keys}`, holding a key that your approval is for. It never deletes profiles itself. Optional: remove it with `"$TC_BIN" profile delete "${TC_SECRETS_PROFILE:-api-keys}"`; this succeeds even if the profile was never created. If it reports `PROFILE_DELETE_DEFAULT`, that profile is the default:
  - if you have another (`"$TC_BIN" profile list`), make that the default with `"$TC_BIN" profile switch <other>` and delete again;
  - if it's your only profile, delete the whole profile store, `${TC_HOME:-$HOME}/.tinycloud`. Deleting just the profile's folder would leave it named as the default.
- **The skill and the CLI:** delete `~/.agents/skills/tc-secrets` or `${CLAUDE_CONFIG_DIR:-~/.claude}/skills/tc-secrets`, and `~/.local/share/tinycloud/cli` if nothing else uses it.
