|
| 1 | +<a id="cli-and-modes-reference"></a> |
| 2 | + |
| 3 | +# Command Line |
| 4 | + |
| 5 | +This page documents Pi's built-in command-line commands and options. Run `pi --help` or append `--help` to a command for the exact interface in your installed version. The top-level help also includes options registered by loaded extensions. |
| 6 | + |
| 7 | +```sh |
| 8 | +pi [options] [--] [@files...] [messages...] |
| 9 | +pi install <source> [options] |
| 10 | +pi remove <source> [options] |
| 11 | +pi uninstall <source> [options] |
| 12 | +pi update [target] [options] |
| 13 | +pi list |
| 14 | +pi config [options] |
| 15 | +pi auth <check|print-api-key|print-bearer-token> [options] |
| 16 | +``` |
| 17 | + |
| 18 | +<a id="modes"></a> |
| 19 | + |
| 20 | +## Invocation and output |
| 21 | + |
| 22 | +```sh |
| 23 | +pi |
| 24 | +pi --print "Summarize this repository" |
| 25 | +git diff | pi --print "Review this change" |
| 26 | +pi --mode json "Inspect this repository" > events.jsonl |
| 27 | +``` |
| 28 | + |
| 29 | +With terminal stdin and stdout, Pi opens the terminal UI unless `--print`, `--mode json`, or `--mode rpc` selects another interface. When either stream is redirected and neither JSON nor RPC mode is selected, Pi uses print mode. See [CLI Integration](cli-integration.md) for choosing between interactive, print, JSON, RPC, and SDK integration. |
| 30 | + |
| 31 | +| Input | Behavior | |
| 32 | +|---|---| |
| 33 | +| `message` | Provide an initial prompt | |
| 34 | +| `@path` | Include a text file or image in the first prompt | |
| 35 | +| Piped stdin | Prepend its contents to the first prompt | |
| 36 | +| `--` | Stop option parsing so a prompt can begin with `-` | |
| 37 | + |
| 38 | +Pi resolves `@path` from the current working directory. The working directory also controls project configuration, resource discovery, and session grouping. |
| 39 | + |
| 40 | +`--print` controls whether Pi runs once and exits. `--mode` selects the output interface. `--mode text` does not force one-shot execution when stdin and stdout are terminals; use `--print` for that behavior. |
| 41 | + |
| 42 | +| Option | Behavior | |
| 43 | +|---|---| |
| 44 | +| `-p`, `--print` | Run the supplied prompts, write the final assistant text to stdout, then exit | |
| 45 | +| `--mode text` | Select text output; still open the terminal UI when stdin and stdout are terminals | |
| 46 | +| `--mode json` | Run the supplied prompts, write JSONL events to stdout, then exit | |
| 47 | +| `--mode rpc` | Read JSONL commands from stdin and write responses and events to stdout until shutdown | |
| 48 | +| `--export <input> [output]` | Export a session file to HTML and exit; derive the destination when `output` is omitted | |
| 49 | + |
| 50 | +RPC mode rejects `@file` arguments. JSON and RPC modes reserve stdout for protocol records. See [JSON Event Stream](json.md) and [RPC Protocol](rpc.md). |
| 51 | + |
| 52 | +<a id="model-options"></a> |
| 53 | + |
| 54 | +## Models |
| 55 | + |
| 56 | +```sh |
| 57 | +pi --model sonnet:high |
| 58 | +``` |
| 59 | + |
| 60 | +See [Choose a Model](models.md) for model selection and [Provider Authentication](providers.md) for credentials. |
| 61 | + |
| 62 | +- `--provider <name>`<br> |
| 63 | + Restricts `--model` lookup to one provider. |
| 64 | +- `--model <pattern>`<br> |
| 65 | + Selects by exact ID or fuzzy ID/name match. It accepts `provider/id` and an optional `:<thinking>` suffix. |
| 66 | +- `--api-key <key>`<br> |
| 67 | + Uses a non-persistent API-key override. It requires a model selected through `--model` or `--models`. |
| 68 | +- `--thinking <level>`<br> |
| 69 | + Sets `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`. It overrides a `--model` suffix and is clamped to the model's capabilities. |
| 70 | +- `--models <patterns>`<br> |
| 71 | + Sets a comma-separated scope for startup and cycling. It accepts exact IDs, fuzzy matches, case-insensitive globs, and optional `:<thinking>` suffixes. |
| 72 | +- `--list-models [search]`<br> |
| 73 | + Lists available models, optionally filtered by a fuzzy search, then exits. |
| 74 | + |
| 75 | +<a id="session-options"></a> |
| 76 | + |
| 77 | +## Sessions |
| 78 | + |
| 79 | +```sh |
| 80 | +pi --continue |
| 81 | +``` |
| 82 | + |
| 83 | +See [Sessions and Context](sessions.md) for resuming, forking, naming, and storing sessions. |
| 84 | + |
| 85 | +- `-c`, `--continue`<br> |
| 86 | + Continues the most recent session for the current project. |
| 87 | +- `-r`, `--resume`<br> |
| 88 | + Opens the session selector. |
| 89 | +- `--session <path|id>`<br> |
| 90 | + Opens by file path, exact ID, or partial ID. Pi searches the current project first and offers to fork a cross-project match. |
| 91 | +- `--session-id <id>`<br> |
| 92 | + Opens the exact project session ID or creates it if absent. IDs accept letters, numbers, `.`, `_`, and `-`. |
| 93 | +- `--fork <path|id>`<br> |
| 94 | + Forks an existing session into a new session for the current project. |
| 95 | +- `--session-dir <dir>`<br> |
| 96 | + Overrides storage and lookup. It takes precedence over `PI_CODING_AGENT_SESSION_DIR` and the `sessionDir` setting. |
| 97 | +- `--no-session`<br> |
| 98 | + Uses an in-memory session that is not persisted. |
| 99 | +- `-n`, `--name <name>`<br> |
| 100 | + Sets the session display name. |
| 101 | + |
| 102 | +Constraints: |
| 103 | + |
| 104 | +- Session IDs must start and end with a letter or number. |
| 105 | +- `--fork` cannot be combined with `--session`, `--continue`, `--resume`, or `--no-session`. |
| 106 | +- `--session-id` cannot be combined with `--session`, `--continue`, or `--resume`. Combine it with `--fork` to choose the new ID. |
| 107 | + |
| 108 | +<a id="tool-options"></a> |
| 109 | + |
| 110 | +## Tools |
| 111 | + |
| 112 | +```sh |
| 113 | +pi --tools read,grep,find,ls --print "Review this project" |
| 114 | +``` |
| 115 | + |
| 116 | +See [Settings](settings.md#tools) for configuring the default tool selection. |
| 117 | + |
| 118 | +- `-t`, `--tools <list>`<br> |
| 119 | + Replaces the default selection with a comma-separated allowlist of built-in, extension, or custom tools. |
| 120 | +- `-xt`, `--exclude-tools <list>`<br> |
| 121 | + Disables comma-separated tool names after all other selection options. |
| 122 | +- `-nbt`, `--no-builtin-tools`<br> |
| 123 | + Disables default built-in tools while retaining extension and custom tools. |
| 124 | +- `-nt`, `--no-tools`<br> |
| 125 | + Starts with all built-in, extension, and custom tools disabled. |
| 126 | + |
| 127 | +Default enabled tools are `read`, `bash`, `edit`, and `write`, unless `defaultTools` changes them. |
| 128 | + |
| 129 | +| Built-in | Purpose | |
| 130 | +|---|---| |
| 131 | +| `read` | Read text files and supported images | |
| 132 | +| `bash` | Run shell commands | |
| 133 | +| `powershell` | Run PowerShell commands on Windows | |
| 134 | +| `edit` | Apply exact text replacements to an existing file | |
| 135 | +| `write` | Create or overwrite a file | |
| 136 | +| `grep` | Search file contents | |
| 137 | +| `find` | Find paths using glob patterns | |
| 138 | +| `ls` | List directory contents | |
| 139 | + |
| 140 | +<a id="resource-options"></a> |
| 141 | + |
| 142 | +## Resources |
| 143 | + |
| 144 | +```sh |
| 145 | +pi --extension ./review.ts |
| 146 | +``` |
| 147 | + |
| 148 | +See [Configuration](configuration.md) for conventional directories and project trust, [Settings](settings.md#resources) for configured paths, and [Pi Packages](packages.md) for package sources. |
| 149 | + |
| 150 | +- `-e`, `--extension <path>`<br> |
| 151 | + Loads an extension file or directory and is repeatable. |
| 152 | +- `-ne`, `--no-extensions`<br> |
| 153 | + Disables discovered and configured extensions. Explicit `-e` paths still load. |
| 154 | +- `--skill <path>`<br> |
| 155 | + Loads a skill file or directory and is repeatable. |
| 156 | +- `-ns`, `--no-skills`<br> |
| 157 | + Disables discovered and configured skills. Explicit `--skill` paths still load. |
| 158 | +- `--prompt-template <path>`<br> |
| 159 | + Loads a prompt-template file or directory and is repeatable. |
| 160 | +- `-np`, `--no-prompt-templates`<br> |
| 161 | + Disables discovered and configured templates. Explicit `--prompt-template` paths still load. |
| 162 | +- `--theme <path>`<br> |
| 163 | + Loads a theme file or directory and is repeatable. |
| 164 | +- `--use-theme <name[/name]>`<br> |
| 165 | + Selects the initial interactive theme for this run. |
| 166 | +- `--no-themes`<br> |
| 167 | + Disables discovered and configured themes. Explicit `--theme` paths still load. |
| 168 | +- `-nc`, `--no-context-files`<br> |
| 169 | + Disables `AGENTS.md` and `CLAUDE.md` discovery. |
| 170 | + |
| 171 | +Resource paths apply only to the current process. Relative paths resolve from the current working directory. |
| 172 | + |
| 173 | +<a id="prompt-and-display-options"></a> |
| 174 | + |
| 175 | +## Prompts and process |
| 176 | + |
| 177 | +```sh |
| 178 | +pi --append-system-prompt ./instructions.md |
| 179 | +``` |
| 180 | + |
| 181 | +See [Configuration](configuration.md) for saved configuration, [Security](security.md#understand-project-trust) for project trust, and [Environment Variables](environment-variables.md) for process controls. |
| 182 | + |
| 183 | +- `--system-prompt <text|path>`<br> |
| 184 | + Replaces the default system prompt with text or the contents of an existing file. |
| 185 | +- `--append-system-prompt <text|path>`<br> |
| 186 | + Appends text or an existing file to the system prompt and is repeatable. |
| 187 | +- `--tui-mode <mode>`<br> |
| 188 | + Uses `regular` or `fullscreen` terminal mode. |
| 189 | +- `--verbose`<br> |
| 190 | + Shows verbose interactive startup information, overriding `quietStartup`. |
| 191 | +- `-a`, `--approve`<br> |
| 192 | + Trusts project-local configuration and resources for this process. |
| 193 | +- `-na`, `--no-approve`<br> |
| 194 | + Ignores trust-gated project-local configuration and resources for this process. |
| 195 | +- `--offline`<br> |
| 196 | + Disables automatic network activity, including model catalog refreshes. Equivalent to `PI_OFFLINE=1`. |
| 197 | +- `-h`, `--help`<br> |
| 198 | + Shows help, including flags registered by loaded extensions, then exits. |
| 199 | +- `-v`, `--version`<br> |
| 200 | + Shows the Pi version, then exits. |
| 201 | + |
| 202 | +Extensions may register additional long-form options. Unknown short options are rejected. |
| 203 | + |
| 204 | +## Package commands |
| 205 | + |
| 206 | +```sh |
| 207 | +pi install npm:@scope/package |
| 208 | +``` |
| 209 | + |
| 210 | +See [Pi Packages](packages.md) for source formats, filtering, installation, and project scope. |
| 211 | + |
| 212 | +### Common tasks |
| 213 | + |
| 214 | +| Task | Command | |
| 215 | +|---|---| |
| 216 | +| Install a package | `pi install <source>` | |
| 217 | +| List configured packages | `pi list` | |
| 218 | +| Remove a package and its settings entry | `pi remove <source>` | |
| 219 | +| Configure which package resources load | `pi config` | |
| 220 | + |
| 221 | +Add `--local` or `-l` to `install`, `remove`, `uninstall`, or `config` to use project settings instead of global settings. |
| 222 | + |
| 223 | +### Update Pi or packages |
| 224 | + |
| 225 | +Running `pi update` without a target updates Pi itself. |
| 226 | + |
| 227 | +| Task | Command | |
| 228 | +|---|---| |
| 229 | +| Update Pi | `pi update` | |
| 230 | +| Update all installed packages | `pi update --extensions` | |
| 231 | +| Update one installed package | `pi update <source>` | |
| 232 | +| Refresh model catalogs | `pi update --models` | |
| 233 | +| Update Pi and all installed packages | `pi update --all` | |
| 234 | + |
| 235 | +Add `--force` to reinstall Pi when the selected update includes Pi. |
| 236 | + |
| 237 | +### Aliases and command options |
| 238 | + |
| 239 | +- `pi uninstall <source>` is an alias for `pi remove <source>`. |
| 240 | +- `pi update --self`, `pi update self`, and `pi update pi` are aliases for `pi update`. |
| 241 | +- `pi update --extension <source>` is an alias for `pi update <source>`. |
| 242 | +- `-a`, `--approve` trusts project-local files for one command. `-na`, `--no-approve` ignores trust-gated project-local files. |
| 243 | +- Append `-h` or `--help` to a command for its exact usage and option constraints. |
| 244 | + |
| 245 | +## Credential commands |
| 246 | + |
| 247 | +```sh |
| 248 | +pi auth check --provider openai --json |
| 249 | +``` |
| 250 | + |
| 251 | +Authentication commands require `--provider <provider>` or `--model <model>`. See [Provider Authentication](providers.md) for supported methods. |
| 252 | + |
| 253 | +| Command | Description | |
| 254 | +|---|---| |
| 255 | +| `pi auth check` | Print `ready`, `not_ready`, or `invalid`; exit with status `0`, `1`, or `2`, respectively | |
| 256 | +| `pi auth print-api-key` | Print the resolved API key | |
| 257 | +| `pi auth print-bearer-token` | Print a resolved OAuth bearer token | |
| 258 | + |
| 259 | +| Option | Applies to | Description | |
| 260 | +|---|---|---| |
| 261 | +| `--provider <provider>` | All | Resolve credentials for a provider | |
| 262 | +| `--model <model>` | All | Resolve credentials from a model; may be combined with `--provider` | |
| 263 | +| `--json` | `auth check` | Write the structured result as JSON | |
| 264 | +| `--credentials` | `auth check` | Emit the resolved credential when ready | |
| 265 | +| `--no-refresh` | `auth check` | Do not refresh expired OAuth credentials; refresh is the default | |
| 266 | +| `--min-expiry <duration>` | `print-bearer-token` | Require remaining token lifetime using `ms`, `s`, `m`, or `h`, such as `30m` | |
| 267 | + |
| 268 | +Credential-printing commands write secrets to stdout. |
0 commit comments