# CLI reference

Every `afile` command in one place. Run `afile <command> --help` for a command's options.

```sh
npm i -g @afile/cli
```

It needs Node.js 24 or later, and installs two commands: `afile`, and `afile-mcp` for [MCP](/mcp).

## Commands [#commands]

| Command | What it does |
| --- | --- |
| `save <file \| ->` | Save a file, or standard input, encrypted |
| `items` | List this agent's items, newest first |
| `show <item>` | Read one item: its name, size, version and links |
| `get <item \| link>` | Decrypt an item or a shared link to a file or standard output |
| `update <item> [file \| -]` | Save a new version, or rename or retag an item |
| `delete <item>` | Delete an item and close every link to it |
| `search <words>` | Find items by name, tag or note |
| `secret <name>` | Save a secret from standard input |
| `secrets` | List secret names, never their values |
| `run --secret <name> -- <cmd>` | Run a command with secrets in its environment |
| `share <item>` | Get a link that lets someone download one item |
| `receive` | Get a link where someone can send files to this agent |
| `links` | List this agent's open links and how often each was used |
| `close <link>` | Close a link at once |
| `connect` | Connect this agent to aFile and create its key |
| `me` | Show this agent, its storage and whether a person is linked |
| `key` | Show this agent's key, or export it with `--export` |
| `logout` | Forget the token and key on this machine |
| `add` | Add the aFile skill to your agents |
| `remove` | Remove the aFile skill from your agents |
| `mcp` | Print MCP settings for Claude Code, Gemini CLI or OpenCode |
| `instructions` | Print text your person can paste into any chat |

The commands for [your person](/person), `link`, `unlink`, `ask`, `asks`, `check`, `cancel` and `recipients`, need a self-hosted aFile server.

## Options for every command [#options]

| Option | What it does |
| --- | --- |
| `--json` | Print the API's JSON, for scripts and agents |
| `-y`, `--yes` | Answer yes to every prompt |
| `--api <url>` | Use another aFile API (`https://api.afile.sh` unless you say otherwise) |
| `-h`, `--help` | Show help |
| `-v`, `--version` | Show the version |

## Environment [#env]

| Variable | What it does |
| --- | --- |
| `AFILE_TOKEN` | Use an existing token |
| `AFILE_CONFIG_DIR` | Keep a separate agent on the same machine |
| `AFILE_API_URL` | Use another aFile provider |

The token and key live in `~/.config/afile/credentials.json`, readable only by you. `afile logout` forgets them on this machine, and doesn't delete anything at aFile.

## Exit codes [#exit]

`0` means it worked, `1` means the request failed, and `2` means the command itself was wrong, such as an unknown command or a missing argument. With `run`, the exit code is the command's own.
