@phantomcodes/cli 1.6.3 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/README.md +139 -118
- package/bin/phantom.mjs +37 -2
- package/dist/agents/command.d.mts +8 -27
- package/dist/agents/command.mjs +323 -59
- package/dist/agents/login.d.mts +3 -0
- package/dist/agents/login.mjs +97 -0
- package/dist/agents/opencode-check.d.mts +15 -0
- package/dist/agents/opencode-check.mjs +193 -0
- package/dist/agents/phantom-key.d.mts +7 -0
- package/dist/agents/phantom-key.mjs +40 -0
- package/dist/agents/proxy.d.mts +26 -28
- package/dist/agents/proxy.mjs +225 -33
- package/dist/chatgpt/command.d.mts +2 -0
- package/dist/chatgpt/command.mjs +119 -0
- package/dist/chatgpt/session.d.mts +87 -0
- package/dist/chatgpt/session.mjs +253 -0
- package/dist/cli/accounts.d.mts +21 -0
- package/dist/cli/accounts.mjs +96 -0
- package/dist/cli/app.d.mts +4 -24
- package/dist/cli/app.mjs +224 -139
- package/dist/cli/commands.d.mts +1 -16
- package/dist/cli/commands.mjs +144 -239
- package/dist/cli/help.d.mts +0 -19
- package/dist/cli/help.mjs +30 -55
- package/dist/cli/run.mjs +35 -79
- package/dist/cli/start.d.mts +2 -31
- package/dist/cli/start.mjs +13 -116
- package/dist/core/brand.d.mts +0 -7
- package/dist/core/brand.mjs +0 -8
- package/dist/core/errors.d.mts +0 -16
- package/dist/core/errors.mjs +0 -16
- package/dist/core/helpers.d.mts +0 -46
- package/dist/core/helpers.mjs +1 -64
- package/dist/core/node-trust.d.mts +0 -5
- package/dist/core/node-trust.mjs +0 -6
- package/dist/core/pick.d.mts +7 -55
- package/dist/core/pick.mjs +49 -106
- package/dist/core/request.d.mts +0 -46
- package/dist/core/request.mjs +1 -60
- package/dist/core/secrets.d.mts +0 -4
- package/dist/core/secrets.mjs +0 -10
- package/dist/core/state.d.mts +3 -1
- package/dist/core/state.mjs +147 -4
- package/dist/core/style.d.mts +0 -27
- package/dist/core/style.mjs +0 -20
- package/dist/core/version.d.mts +1 -2
- package/dist/core/version.mjs +1 -2
- package/dist/local/accounts.d.mts +25 -0
- package/dist/local/accounts.mjs +40 -0
- package/dist/local/agent-headers.d.mts +7 -0
- package/dist/local/agent-headers.mjs +44 -0
- package/dist/local/chatgpt-plan.d.mts +147 -0
- package/dist/local/chatgpt-plan.mjs +384 -0
- package/dist/local/command.d.mts +24 -0
- package/dist/local/command.mjs +211 -0
- package/dist/local/config.d.mts +49 -0
- package/dist/local/config.mjs +168 -0
- package/dist/local/decide.d.mts +37 -0
- package/dist/local/decide.mjs +201 -0
- package/dist/local/failure-signs.d.mts +4 -0
- package/dist/local/failure-signs.mjs +99 -0
- package/dist/local/keys.d.mts +32 -0
- package/dist/local/keys.mjs +239 -0
- package/dist/local/models.d.mts +53 -0
- package/dist/local/models.mjs +117 -0
- package/dist/local/replay.d.mts +59 -0
- package/dist/local/replay.mjs +143 -0
- package/dist/local/report.d.mts +43 -0
- package/dist/local/report.mjs +153 -0
- package/dist/local/request-log.d.mts +53 -0
- package/dist/local/request-log.mjs +69 -0
- package/dist/local/retry-after.d.mts +3 -0
- package/dist/local/retry-after.mjs +28 -0
- package/dist/local/rust-router.d.mts +39 -0
- package/dist/local/rust-router.mjs +54 -0
- package/dist/local/server.d.mts +27 -0
- package/dist/local/server.mjs +449 -0
- package/dist/local/status-line.d.mts +17 -0
- package/dist/local/status-line.mjs +81 -0
- package/dist/local/tiers.d.mts +3 -0
- package/dist/local/tiers.mjs +137 -0
- package/dist/local/traces.d.mts +69 -0
- package/dist/local/traces.mjs +341 -0
- package/dist/phantom.d.mts +0 -37
- package/dist/phantom.mjs +0 -31
- package/package.json +15 -9
- package/skills/phantom-ai/SKILL.md +28 -97
- package/dist/cli/screens.d.mts +0 -177
- package/dist/cli/screens.mjs +0 -398
- package/dist/core/free.d.mts +0 -13
- package/dist/core/free.mjs +0 -14
- package/dist/core/motion.d.mts +0 -47
- package/dist/core/motion.mjs +0 -156
- package/dist/core/shapes.d.mts +0 -13
- package/dist/core/shapes.mjs +0 -1
- package/dist/keys/command.d.mts +0 -16
- package/dist/keys/command.mjs +0 -143
- package/dist/keys/saved.d.mts +0 -96
- package/dist/keys/saved.mjs +0 -169
- package/dist/models/choice.d.mts +0 -7
- package/dist/models/choice.mjs +0 -27
- package/dist/models/command.d.mts +0 -8
- package/dist/models/command.mjs +0 -66
- package/dist/models/list.d.mts +0 -39
- package/dist/models/list.mjs +0 -39
- package/dist/receipts/command.d.mts +0 -7
- package/dist/receipts/command.mjs +0 -41
- package/dist/receipts/receipts.d.mts +0 -76
- package/dist/receipts/receipts.mjs +0 -118
- package/dist/setup/agents.d.mts +0 -149
- package/dist/setup/agents.mjs +0 -886
- package/dist/setup/apply.d.mts +0 -85
- package/dist/setup/apply.mjs +0 -301
- package/dist/setup/command.d.mts +0 -12
- package/dist/setup/command.mjs +0 -307
- package/dist/setup/editors.d.mts +0 -108
- package/dist/setup/editors.mjs +0 -500
- package/dist/setup/legacy.d.mts +0 -13
- package/dist/setup/legacy.mjs +0 -36
- package/dist/setup/plan.d.mts +0 -104
- package/dist/setup/plan.mjs +0 -132
- package/dist/setup/screen.d.mts +0 -30
- package/dist/setup/screen.mjs +0 -260
- package/dist/setup/shared.d.mts +0 -141
- package/dist/setup/shared.mjs +0 -88
- package/dist/setup/was.d.mts +0 -42
- package/dist/setup/was.mjs +0 -91
- package/dist/spend/command.d.mts +0 -5
- package/dist/spend/command.mjs +0 -235
- package/dist/spend/lineup.d.mts +0 -61
- package/dist/spend/lineup.mjs +0 -39
- package/dist/spend/reason.d.mts +0 -5
- package/dist/spend/reason.mjs +0 -60
- package/dist/spend/report.d.mts +0 -105
- package/dist/spend/report.mjs +0 -68
- package/dist/spend/routing.d.mts +0 -74
- package/dist/spend/routing.mjs +0 -57
- package/dist/workspace/command.d.mts +0 -59
- package/dist/workspace/command.mjs +0 -871
package/LICENSE
CHANGED
|
@@ -19,8 +19,7 @@ applies to every copy of the Software that carries this file.
|
|
|
19
19
|
part of it unless Harbor Financial LLC gives you written permission. The only
|
|
20
20
|
permission this license grants is the one in section 3, and it covers the
|
|
21
21
|
CLI alone. Visiting phantom.codes and using the Phantom service are
|
|
22
|
-
governed by the terms of service
|
|
23
|
-
license.
|
|
22
|
+
governed by the terms of service, not by this license.
|
|
24
23
|
|
|
25
24
|
3. Limited permission for the Phantom CLI
|
|
26
25
|
|
package/README.md
CHANGED
|
@@ -1,190 +1,211 @@
|
|
|
1
1
|
# Phantom CLI
|
|
2
2
|
|
|
3
|
-
`phantom`
|
|
3
|
+
`phantom` starts your coding agents (pi, OpenCode, Codex and Claude Code) and routes their requests to accounts you already pay for. phantom-1 picks a tier for each request, Standard for most and Frontier for the hard ones, and sends it to the account and model you chose for that tier: the Vercel AI Gateway, Z.ai's GLM Coding Plan or your ChatGPT plan.
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
[Phantom](https://phantom.codes) · [npm](https://www.npmjs.com/package/@phantomcodes/cli)
|
|
6
6
|
|
|
7
|
-
## Install and
|
|
7
|
+
## Install and start
|
|
8
8
|
|
|
9
|
-
You need Node
|
|
9
|
+
You need the coding agent itself. The installer needs no Node. It puts `phantom` in `~/.local/bin`, adds that folder to your PATH, and checks the download against the checksum npm lists. It runs on macOS, and on Linux with glibc 2.34 or newer:
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
|
|
13
|
-
phantom
|
|
12
|
+
curl -fsSL https://phantom.codes/install | sh
|
|
13
|
+
phantom
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
On Windows, Alpine and older Linux, use Node 24 or newer: `npm i -g @phantomcodes/cli`.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
`phantom` shows three kinds of row: the agents that route on your own accounts (pi and OpenCode, each when it is installed), Settings and Report. Enter on an agent starts it; Report shows what routing did in the last day (`phantom report --since 1d`). Above the list, one line says where each tier goes and what still needs doing, for example:
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
```
|
|
21
|
+
Standard glm-5.4 on zai · Frontier gpt-6.1-sol on chatgpt · ! chatgpt needs sign-in
|
|
22
|
+
```
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
The first time, before there is any routing to show, `phantom` opens the settings first, then comes back to the list.
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
| Command | What it does |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `phantom` | pi, OpenCode, Settings and Report |
|
|
29
|
+
| `phantom pi`, `phantom opencode`, `phantom codex`, `phantom claude` | starts that agent without asking; Codex and Claude Code run through Phantom's server, so the list leaves them out |
|
|
30
|
+
| `phantom config` | the settings: Standard, Frontier and providers |
|
|
31
|
+
| `phantom login`, `phantom logout` | sign in to Phantom and save your key, or remove it from this computer (see [Sign in and add credit](#sign-in-and-add-credit)) |
|
|
32
|
+
| `phantom report` | what routing did |
|
|
33
|
+
| `phantom replay` | other routing settings tried on saved traces (see [Traces](#traces-full-prompts-and-answers-off-by-default)) |
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
Without a terminal (in a script or a pipe), `phantom` prints these as three lines and starts nothing.
|
|
27
36
|
|
|
28
|
-
|
|
29
|
-
- `--no-shell`, or unticking "Your shell" in the checklist, leaves your shell startup file alone. Setup then prints the lines to add yourself.
|
|
30
|
-
- `--limit 20` caps what the key can spend each month, and `--limit none` removes the cap. At a terminal, setup asks once when the key has no cap.
|
|
31
|
-
- `phantom setup --restore` puts back each file setup changed, from the copies it kept. A file you edited after setup keeps your edits: restore takes out only Phantom's own lines and keys, and leaves the copy beside the file. Restore also removes the `settings.json.bak` copy that setup makes for Claude Code and Gemini, unless a `.bak` was already there before setup or you changed it since. It exits 1 only when a file could not be undone.
|
|
32
|
-
- `phantom setup --provider off` takes Phantom out of an agent and keeps the rest of its settings. In JSON settings files (Claude Code, Qwen Code, Gemini CLI and others), setup records each value it replaces and puts it back.
|
|
37
|
+
## Settings
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
`phantom config` is one screen. At the top is a table of your providers' accounts: each one's kind, whether its key is found (or ChatGPT is signed in), where the key comes from, which tiers use it, and how many requests it answered in the last day. Under it are four rows. Choose one with the arrow keys and Enter; Esc goes back.
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
```
|
|
42
|
+
? Settings
|
|
43
|
+
❯ Standard glm-5.4 · Z.ai
|
|
44
|
+
Frontier gpt-6.1-sol · ChatGPT
|
|
45
|
+
Providers ChatGPT ✓ · Z.ai ✓ · Vercel AI Gateway ✓
|
|
46
|
+
Back
|
|
47
|
+
```
|
|
37
48
|
|
|
38
|
-
|
|
49
|
+
- **Standard** and **Frontier** each open one list of every model your connected providers offer, each beside its provider, with the marker on the tier's current model. Type to narrow it, or type `account:model`. Enter sets that model and comes straight back; the tier's fallback and the other tier stay as they were. The last row, **Fallback**, opens the same list with No fallback first. A provider is connected when its key is found, or when you are signed in to ChatGPT.
|
|
50
|
+
- **Providers** lists ChatGPT, Z.ai and the Vercel AI Gateway, connected or not. Each opens what you can do with it: sign in or out of ChatGPT in the browser, or for a key provider save a key (hidden typing), use an item already in the macOS Keychain, or remove the key.
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
Help me set up phantom for AI inference through Phantom AI.
|
|
52
|
+
Each choice runs the same command a script would, so you can see the script form in `phantom config --help`:
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
is on the key my agent uses. Ask before adding funds or starting paid inference.
|
|
53
|
-
Keep keys and recovery credentials out of chat. Finish with the command to launch
|
|
54
|
-
my agent, and explain how to undo any saved setup.
|
|
54
|
+
```bash
|
|
55
|
+
phantom config --standard zai:glm-5.4 --standard-fallback gateway:deepseek/deepseek-v4.1-flash-1017 \
|
|
56
|
+
--frontier chatgpt:gpt-6.1-sol --frontier-fallback gateway:anthropic/claude-sonnet-5.5
|
|
57
|
+
pbpaste | phantom config key set gateway --stdin
|
|
58
|
+
phantom config key use-keychain zai --service zai-api-key --keychain-account you
|
|
59
|
+
phantom config key rm zai
|
|
60
|
+
phantom config chatgpt login
|
|
61
|
+
phantom config models gateway
|
|
62
|
+
phantom config show
|
|
55
63
|
```
|
|
56
64
|
|
|
57
|
-
|
|
65
|
+
A tier flag names the account first, then the model. A model the account's own list doesn't have is refused; when the list can't be read (or, for Z.ai, comes from its docs), phantom warns and writes it anyway. `phantom config show` prints the tiers, where each key comes from and whether it is found, and the ChatGPT sign-in, never a key.
|
|
58
66
|
|
|
59
|
-
|
|
60
|
-
phantom login
|
|
61
|
-
phantom fund --amount 10 --card
|
|
62
|
-
phantom workspace status
|
|
63
|
-
phantom codex
|
|
64
|
-
```
|
|
67
|
+
### Where the keys come from
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
Each key account (the Gateway, Z.ai) reads its key from one place:
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
- **Saved in phantom.** `phantom config key set <account>` asks for the key with hidden typing, or reads it from stdin with `--stdin`. On a Mac it goes in the login Keychain, and `local/keys/<account>` beside `local.json` holds only a pointer to it. Elsewhere that file holds the key, readable by you only. A key on the command line is refused, because shell history keeps it.
|
|
72
|
+
- **A Keychain item you already have** (macOS). `phantom config key use-keychain zai --service <service> --keychain-account <account>` points the account at it without copying it. It is read with `security find-generic-password -s <service> -a <account> -w`, and it has to be readable when you run the command.
|
|
73
|
+
- **An environment variable.** Name it in `local.json` (`"key": { "from": "env", "name": "ZAI_API_KEY" }`). A tier flag that adds the account (`--standard zai:glm-5.4`) names the kind's usual variable, `ZAI_API_KEY` or `AI_GATEWAY_API_KEY`.
|
|
69
74
|
|
|
70
|
-
|
|
75
|
+
`phantom config key rm <account>` forgets an account's key: a saved key is removed, and a Keychain item you made stays where it is. An agent won't start while a tier's account has no key, and phantom says which command fixes it.
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
phantom codex --key coding -- exec "explain this repository"
|
|
74
|
-
```
|
|
77
|
+
### local.json
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
The settings live in `local.json`, beside your saved keys (`~/.config/phantom/`, or `PHANTOM_STATE_DIR`). Older versions used `~/.config/phantom-key/`: the first phantom command after an update moves that folder to `~/.config/phantom/` and leaves a link at the old name, so saved keys, the ChatGPT sign-in and the request log carry over. When moving isn't plainly safe (either name is a link you made, or `~/.config/phantom/` already holds other files), phantom keeps using `~/.config/phantom-key/` and says once why and how to finish. local.json holds names, never a key:
|
|
77
80
|
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"accounts": {
|
|
84
|
+
"gateway": { "kind": "gateway", "key": { "from": "saved" } },
|
|
85
|
+
"zai": { "kind": "zai-coding-plan", "key": { "from": "keychain", "service": "zai-api-key", "account": "you" } },
|
|
86
|
+
"chatgpt": { "kind": "chatgpt-plan" }
|
|
87
|
+
},
|
|
88
|
+
"tiers": {
|
|
89
|
+
"standard": { "account": "zai", "model": "glm-5.4", "fallback": { "account": "gateway", "model": "deepseek/deepseek-v4.1-flash-1017" } },
|
|
90
|
+
"frontier": { "account": "chatgpt", "model": "gpt-6.1-sol", "fallback": { "account": "gateway", "model": "anthropic/claude-sonnet-5.5" } }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
81
93
|
```
|
|
82
94
|
|
|
83
|
-
|
|
95
|
+
- `kind` is `gateway` (Vercel AI Gateway), `zai-coding-plan` (Z.ai's GLM Coding Plan) or `chatgpt-plan` (your ChatGPT plan). Z.ai allows the plan only in the tools it supports, and phantom isn't one of them, so it says so at startup.
|
|
96
|
+
- `key` says where a key account's key comes from: `{ "from": "saved" }`, `{ "from": "env", "name": "..." }` or `{ "from": "keychain", "service": "...", "account": "..." }` (`account` is optional), and `null` until one is set. It holds a name, never a key. A file written before key sources existed says `"keyEnv": "ZAI_API_KEY"`; that still works, and the next change phantom writes turns it into `{ "from": "env", "name": "ZAI_API_KEY" }`.
|
|
97
|
+
- A `chatgpt-plan` account has no `key`: it uses the ChatGPT sign-in (`phantom config chatgpt login`), refreshed as it nears its end. phantom-1 translates each request to the plan's Responses API and the answer back, streamed or not.
|
|
98
|
+
- Each request goes to the tier phantom-1 picks. A file an older phantom wrote may still hold `"mode"`; phantom ignores it, and the next change it writes leaves it out.
|
|
99
|
+
- A tier's `fallback` gets one try when its account answers 429 or a 5xx. On the ChatGPT plan it also gets one when there is no usable sign-in, or when the plan refuses the request (`subscription_sharing_unsupported_capability`). A sign-in the plan refuses passes through, with a line on stderr that says whether signing in again will help. With no fallback and no sign-in, the answer is a 503 that says to run `phantom config chatgpt login`.
|
|
100
|
+
- When an answer carries `Retry-After`, phantom-1 waits that long (up to a minute, and the shortest wait any failed answer of the tier asked for) and tries the tier once more before passing the error on, because agents retry on their own schedule and ignore that header. A longer wait passes straight through, since sitting on the request that long looks like a hang. The wait that actually elapsed ends up in `waited=` on the request's stderr line.
|
|
101
|
+
- Each answer carries `x-phantom-local-tier`, `x-phantom-local-reason` and `x-phantom-local-request-id`, and each request prints one line to stderr with the tiers, account, model, status, tokens and total time, with no message text and no key.
|
|
84
102
|
|
|
85
|
-
##
|
|
103
|
+
## Start an agent
|
|
86
104
|
|
|
87
|
-
|
|
105
|
+
`phantom pi` starts pi with phantom-1 running inside the same process, on a free port on 127.0.0.1, and points pi at it with the model `phantom-1`:
|
|
88
106
|
|
|
89
107
|
```bash
|
|
90
|
-
phantom
|
|
91
|
-
phantom
|
|
92
|
-
phantom
|
|
93
|
-
phantom keys set --id coding --limit 10
|
|
108
|
+
phantom pi -- -p "list the files in this folder"
|
|
109
|
+
# phantom: pi routes on this computer: Standard glm-5.4 on zai, Frontier gpt-6.1-sol on chatgpt (local.json)
|
|
110
|
+
# phantom: pi made 7 requests: 5 Standard (zai), 2 Frontier (chatgpt), 1 fallback; log: ~/.config/phantom/local/requests.jsonl
|
|
94
111
|
```
|
|
95
112
|
|
|
96
|
-
`
|
|
113
|
+
Each request goes straight from your computer to the account its tier names. pi holds no account key: the router reads them, and pi's environment leaves out the variables `local.json` reads keys from. pi gets only a token for this run, and the router refuses requests without it. If a tier's key is missing or `local.json` is broken, phantom stops before pi starts, and says which key is missing and the command that sets it.
|
|
97
114
|
|
|
98
|
-
|
|
99
|
-
- `--budget`: the most it can spend each month, or each `--period` days.
|
|
100
|
-
- `--rate`: the most it can spend in one minute, in dollars.
|
|
115
|
+
A task with an image (a screenshot you attach, or an image a tool read) goes to a tier whose model reads images, for every step until your next message. Some don't, and drop the image without an error: glm-5.4 on Z.ai's GLM Coding Plan does, glm-5.3-flash doesn't. phantom knows a Gateway model from the Gateway's `vision` tag and a Z.ai model from its own list; a ChatGPT plan model counts as able. A model that can't read images (when neither tier's can, or a fallback that can't) is told the image was left out, so its answer starts by saying it couldn't look at the image because your models don't have vision, then goes on from your text.
|
|
101
116
|
|
|
102
|
-
|
|
117
|
+
While pi runs, its footer shows who answered the last request and why, such as `phantom: Frontier, gpt-6.1-sol on chatgpt, the same failure twice`. When something goes wrong, pi shows a warning once: a tier used its fallback (and why), an account answered with an error or couldn't be reached, the ChatGPT sign-in isn't usable or was refused, the router didn't answer, or the request log or a trace couldn't be saved. The same warning shows again after 10 minutes if it's still happening. Switching pi to a model that isn't phantom's clears the footer line.
|
|
103
118
|
|
|
104
|
-
|
|
119
|
+
For the run, `phantom/phantom-1` joins the models you scoped in pi (your own `--models`, or `enabledModels` in pi's settings: the project's `.pi/settings.json` when pi trusts the project, else `settings.json` in pi's agent folder), so Ctrl+P and `/scoped-models` offer it next to them and you can switch back to it. phantom only reads pi's settings. With no scope, pi already offers every model, phantom-1 included. phantom leaves pi's scope as it is, without phantom-1, in three cases: the scope already has a `phantom/` model; the project has its own scope and pi hasn't been told whether to trust the project yet (answer pi's question once, and the next run adds phantom-1); or a pattern has a comma, such as `claude-{sonnet,opus}*`, which `--models` can't carry (phantom says so when pi starts).
|
|
105
120
|
|
|
106
|
-
|
|
121
|
+
Pressing Ctrl+S in `/scoped-models` during a `phantom pi` run saves the scope pi shows, `phantom/phantom-1` included, into `enabledModels` in pi's agent `settings.json`. pi has no way to save it without that. Plain `pi` then has a pattern that matches no model. Later `phantom pi` runs see the saved `phantom/` model and add no second one. To remove it, delete `"phantom/phantom-1"` from `enabledModels` in pi's `settings.json` (`~/.pi/agent/settings.json`, unless `--agent-dir` or `PI_CODING_AGENT_DIR` moves it).
|
|
107
122
|
|
|
108
|
-
|
|
123
|
+
`phantom opencode` does the same for [OpenCode](https://opencode.ai):
|
|
109
124
|
|
|
110
|
-
|
|
125
|
+
```bash
|
|
126
|
+
phantom opencode # OpenCode's own screen
|
|
127
|
+
phantom opencode -- run "list the files in this folder"
|
|
128
|
+
# phantom: opencode routes on this computer: Standard glm-5.4 on zai, Frontier gpt-6.1-sol on chatgpt (local.json)
|
|
129
|
+
# phantom: opencode made 3 requests: 2 Standard (zai), 1 Frontier (chatgpt); log: ~/.config/phantom-key/local/requests.jsonl
|
|
130
|
+
```
|
|
111
131
|
|
|
112
|
-
|
|
113
|
-
- `phantom-1:free` is chat on free models at $0, with no card.
|
|
114
|
-
- `phantom-1:private` is chat (with images) on providers that keep none of your data and don't train on your prompts. It replaced `phantom-1:zdr`, which now answers 400.
|
|
132
|
+
OpenCode gets a provider for this run only, in the `OPENCODE_CONFIG_CONTENT` variable, with the model `phantom-relay-3f9a/phantom-1`. The four letters after `phantom-relay-` are new for each run, so no setting in your own config can name that provider and change where it sends calls. OpenCode lays the run's config over your own `~/.config/opencode/opencode.jsonc`, which phantom never changes. Every other provider is turned off for the run, your own `phantom` provider included, so OpenCode's own jobs (session titles, summaries) go through phantom-1 too. OpenCode runs on a server of its own for the run (`--standalone`), because its shared background server wouldn't see this run's provider. Its subagents' requests stay on Standard, as Claude Code's helper agents do.
|
|
115
133
|
|
|
116
|
-
|
|
134
|
+
Before each run phantom asks OpenCode, with the run's settings, which models it could use (`opencode models`) and which config files it read (`opencode debug config`). It does this in the folder OpenCode starts in, in a folder you name in the arguments, and, for a session you name with `-s` or `--session`, in the folder that session was started in, since OpenCode continues a session with that folder's settings. phantom stops before starting OpenCode, names the files and says what to remove, when:
|
|
117
135
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
136
|
+
- a model outside the run's provider is offered;
|
|
137
|
+
- a config file turns another provider on with `enabled_providers` or an `allow` rule in `policies`, even one with no key yet, because `/connect` in OpenCode's screen could add a key during the run;
|
|
138
|
+
- a config file changes the run's provider (an address, a model, a package);
|
|
139
|
+
- OpenCode can't say where a session named with `-s` lives, or doesn't answer within 30 seconds.
|
|
121
140
|
|
|
122
|
-
|
|
141
|
+
An agent or `small_model` that names another provider's model doesn't stop the run: OpenCode doesn't offer that model, so the agent runs on phantom-1. `phantom opencode -- -c` continues the last session of the folder phantom already checked.
|
|
123
142
|
|
|
124
|
-
|
|
143
|
+
What the check doesn't cover:
|
|
125
144
|
|
|
126
|
-
|
|
145
|
+
- **OpenCode plugins** run their own code inside OpenCode, and one can make its own network calls. phantom doesn't read or limit them.
|
|
146
|
+
- **Changes during a run.** phantom checks once, before OpenCode starts. If you edit an OpenCode config file during the run and OpenCode picks it up (`opencode reload`, for example), the new settings aren't checked.
|
|
127
147
|
|
|
128
|
-
|
|
129
|
-
phantom lineup --table
|
|
130
|
-
phantom lineup set --frontier <model> --standard-fallback <model>
|
|
131
|
-
phantom lineup reset
|
|
132
|
-
```
|
|
148
|
+
A session saved during a run records the run's provider, which no longer exists after the run. If you later continue it with plain `opencode -c`, outside phantom, OpenCode continues it on your own default model. If that model is on a `phantom` provider that points at Phantom's server, the rest of that session is paid from your Phantom key, not routed on your accounts. Use `phantom opencode -- -c` to keep it routed here.
|
|
133
149
|
|
|
134
|
-
`phantom
|
|
150
|
+
`phantom codex` and `phantom claude` don't route on this computer yet. They go through Phantom's server, on your Phantom key (from `phantom login`, or `PHANTOM_API_KEY`), and print what the run cost when the agent exits. With a ChatGPT sign-in, Codex's `openai/` models run on your ChatGPT plan. `phantom pi --server` and `phantom opencode --server` send pi and OpenCode that way too. With no key, Codex and Claude Code start the sign-in at a terminal, and in a script they stop and say to run `phantom login`. With no routing, pi and OpenCode don't start, and phantom says in one line to run `phantom config`.
|
|
135
151
|
|
|
136
|
-
|
|
152
|
+
## Sign in and add credit
|
|
137
153
|
|
|
138
|
-
|
|
154
|
+
Routing on your own accounts needs no Phantom account. `phantom login` is for Phantom's server: `phantom codex`, `phantom claude` and `--server` runs, paid from credit.
|
|
139
155
|
|
|
140
|
-
|
|
141
|
-
PHANTOM_KEY_NAME=coding phantom route set --models <model-a>,<model-b>
|
|
142
|
-
PHANTOM_KEY_NAME=coding phantom route test --table
|
|
143
|
-
```
|
|
156
|
+
`phantom login` prints a link and a code, opens your browser, and waits. Check that the page shows the same code, sign in to your account, and approve. phantom saves the key on this computer (the macOS Keychain on a Mac) and never prints it. If the account has no credit, phantom says where to add it: https://phantom.codes/keys. `--no-browser` only prints the link, to open on another device. `phantom logout` removes the saved key from this computer; the key still works until you revoke it on `/keys`.
|
|
144
157
|
|
|
145
|
-
|
|
158
|
+
phantom's own flags go before the agent's arguments, with `--` between them: `phantom codex -- exec "review this repository"`.
|
|
146
159
|
|
|
147
|
-
## See what
|
|
160
|
+
## See what routing did
|
|
148
161
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
phantom
|
|
162
|
+
Each request also adds one line of JSON to `requests.jsonl` in the `local` folder beside `local.json`. The line holds no message text, key or header:
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{"v":2,"at":"2026-11-28T10:00:00.000Z","id":"r_3f9a0c1b","run":"run_51c0e2aa","phantom":"1.6.3","router_version":"c6a372d12946","sensitivity":"balanced","conversation":"c_8d2e41f0","messages":12,"stream":true,"picked":"standard","reason":"router:dimensions","account":"zai","model":"glm-5.4","fallback":false,"status":200,"outcome":"ok","ms":{"decide":4,"first_byte":310,"total":2840},"tokens":{"in":18210,"out":412},"signals":{"messages":12,"user_turns":1,"tool_calls":5,"tool_errors_last_turn":1,"images":0,"tokens_est":19020},"router":{"tier":"standard","source":"dimensions","confidence":0.87,"threshold":0.5,"signals":{"severity":0.3,"spinning":0,"exploring":0,"productionIntensity":0.5}}}
|
|
153
166
|
```
|
|
154
167
|
|
|
155
|
-
|
|
168
|
+
- `picked` is the tier phantom-1 chose, and the request went to it. Lines an older phantom wrote also hold `"sent"` or `"mode"`; `phantom report` reads them and ignores those fields.
|
|
169
|
+
- `v` is the line's shape (2). `run` is the same on every request one `phantom pi` made. `phantom` is the CLI's version, `router_version` the build of Phantom's router phantom-1 asked (`null` without one), and `sensitivity` its setting.
|
|
170
|
+
- `router` is what Phantom's router answered, or `null` when a rule decided first: its tier and `source` (`dimensions`, `fall_open`, `override` or `capable_hold`), on a `dimensions` turn its confidence in that tier and the threshold the sensitivity sets, the four `signals` it weighed, and on an override the hard reason (`override`). Its picks' `reason` is `router:<source>`. `signals` at the top level are counts read from the messages, never their text.
|
|
171
|
+
- Lines saved before Phantom's router replaced Switchyard say `switchyard_sha`, `switchyard` and `switchyard:<source>`. `phantom report` and `phantom replay` read them as `router_version`, `router` and `router:<source>`.
|
|
172
|
+
- `id` matches the answer's `x-phantom-local-request-id` header, so an error your agent shows can be found in the file.
|
|
173
|
+
- `conversation` groups one task's requests. It is a hash that means nothing outside the run that wrote it, and `null` when the request has no user message.
|
|
174
|
+
- `outcome` is `ok`, `upstream-error` (the account answered with an error status), `stream-failed` (the account's connection broke mid-answer), `client-closed` (your agent hung up first), `unreachable` (no account answered) or `not-signed-in` (a ChatGPT plan tier with no usable sign-in and no fallback). `status` is the account's status, or `null` when none answered.
|
|
175
|
+
- On a fallback's line, `because` says why the first account was skipped, such as `zai:429`, `chatgpt:not-signed-in` or `zai:unreachable:ENOTFOUND` (the network's reason, when it gave one). `code` is the ChatGPT plan's error code when its answer was an error, or the network's reason (`ENOTFOUND`, `ECONNRESET`, `ETIMEDOUT`) when no account answered.
|
|
176
|
+
- `ms.decide` is the time phantom-1 took to pick. `ms.first_byte` counts from the request's arrival to the account's first answer, and `ms.total` to the end of the answer. These three times are the whole trace: there is no OpenTelemetry and nothing is sent anywhere.
|
|
177
|
+
- Past 10 MB the file becomes `requests.1.jsonl`, replacing the older one, and a new file starts.
|
|
178
|
+
- `"log": false` in `local.json` turns the file off.
|
|
156
179
|
|
|
157
|
-
|
|
180
|
+
`phantom report` reads both files and prints the requests by tier, by account and model (tokens, median and 95th percentile total time, median first byte), the reasons, how many tasks (one per message you typed) ran on Frontier from the start, moved up to it partway or came back down, fallbacks and failures. `--since 1h`, `1d`, `7d` or a UTC date such as `2026-11-28` narrows it, and `--json` prints it as JSON.
|
|
158
181
|
|
|
159
|
-
|
|
160
|
-
| --- | --- |
|
|
161
|
-
| Sign in and out | `phantom login`, `phantom logout` |
|
|
162
|
-
| Set up your agents | `phantom setup`, `phantom setup --dry-run`, `phantom setup --restore` |
|
|
163
|
-
| Start an agent for one run | `phantom claude`, `phantom codex`, `phantom pi` |
|
|
164
|
-
| Add credit and check spending | `phantom fund`, `phantom balance`, `phantom spend`, `phantom workspace status` |
|
|
165
|
-
| Manage the workspace's keys | `phantom keys create`, `phantom keys set`, `phantom keys rotate`, `phantom keys revoke` |
|
|
166
|
-
| Manage the keys saved on this computer | `phantom keys saved`, `phantom keys save`, `phantom keys rm` |
|
|
167
|
-
| Pick phantom-1, phantom-1:free or phantom-1:private | `phantom models`, `phantom models use <id>` |
|
|
168
|
-
| Pick the model in each tier | `phantom lineup`, `phantom lineup set`, `phantom lineup reset` |
|
|
169
|
-
| Set rules for `auto` | `phantom route` |
|
|
170
|
-
| Use the providers that answer soonest | `phantom route set --sort fast` (`--sort default` for cheapest first) |
|
|
182
|
+
### Traces: full prompts and answers, off by default
|
|
171
183
|
|
|
172
|
-
|
|
184
|
+
phantom never stores message text unless you turn traces on:
|
|
173
185
|
|
|
174
|
-
|
|
186
|
+
```bash
|
|
187
|
+
phantom config --traces on # start saving from the next phantom pi
|
|
188
|
+
phantom config --traces off # stop saving from the next phantom pi; what is saved stays
|
|
189
|
+
rm -r ~/.config/phantom/local/traces # delete what is saved
|
|
190
|
+
```
|
|
175
191
|
|
|
176
|
-
|
|
192
|
+
A `phantom pi` reads `local.json` when it starts, so one already running keeps its setting until it ends.
|
|
177
193
|
|
|
178
|
-
|
|
194
|
+
With traces on, phantom-1 saves the whole of every request and answer: the request body pi sent (system prompt, every message with its tool output and images, tools and the other fields) and the answer pi received (its text, the model's reasoning when the account sends it, every tool call with its arguments, the finish reason and usage). That is your code and your conversations, so they stay on this computer only: one file per day and `phantom pi` run in `local/traces/` beside `local.json` (mode 600, folder 700), up to 2 GB, past which the oldest files are deleted. pi sends the whole chat with every request, so a request that only adds to an earlier one in the same file is saved as its new messages and a pointer to that earlier request; `phantom replay` puts each request back together. A day of long pi chats takes a few megabytes instead of a few hundred. No header, key or token goes in. Nothing is sent anywhere. `phantom pi` says when traces are on, and `phantom report` and `phantom config show` say whether they are and where.
|
|
179
195
|
|
|
180
|
-
<
|
|
181
|
-
<summary><strong>Advanced and older commands</strong></summary>
|
|
196
|
+
`phantom replay` runs the saved traces through phantom-1's tier decision again, with no model call: once with the settings they were recorded with, as a check that the replay matches what happened, then with what you pass (`--sensitivity balanced|conservative|strict`, `--max-move-up-tokens <n>`, `--since`). It prints the requests that would change tier, the share on Frontier before and after, and how many of the router's picks scored within 0.1 of its move-up threshold; `--json` adds the router's score for every request (from -1, sure of Standard, to +1, sure of Frontier). A run that started before `--since` is replayed from its start, so its holds are as they were live, and only its requests from then on are counted.
|
|
182
197
|
|
|
183
|
-
`phantom --
|
|
198
|
+
`phantom config --sensitivity balanced|conservative|strict` sets how soon Phantom's router moves a task up to Frontier and how long it keeps it there (`"sensitivity"` in `local.json`, `balanced` unless set), from the next `phantom pi`.
|
|
184
199
|
|
|
185
|
-
|
|
200
|
+
`phantom config --trial on|off` turns on a test of the router's move up (`"trial"` in `local.json`, off unless set). When the router moves a task up to Frontier, a coin decides the whole task: it runs on Frontier as the router picks, or stays on Standard. Failure words, hard errors and images still move a Standard task up. The status line says when the trial kept a task on Standard, and the request log and traces save each task's side, so the finished tasks on each side can be graded and compared. Turn traces on with it.
|
|
186
201
|
|
|
187
|
-
|
|
202
|
+
phantom-1 asks Phantom's router, the Rust add-on in `routers/phantom-1/router`, when no rule decides first. The npm package doesn't include it, so without it phantom-1 picks Frontier. Run phantom from a repo checkout (`pnpm install` builds the router), or set `PHANTOM_ROUTER_DIR` to a built `routers/phantom-1/router` folder.
|
|
203
|
+
|
|
204
|
+
## Output and exit codes
|
|
205
|
+
|
|
206
|
+
At a terminal, the screens are pickers (arrow keys, Enter, Esc to go back). Through a pipe, scripts and agents get JSON on stdout and errors on stderr. `--json` prints JSON at a terminal, and `--table` draws the screen in a pipe. phantom refuses a flag it doesn't know; `phantom <command> --help` lists each command's flags.
|
|
207
|
+
|
|
208
|
+
Exit codes: 0 for success (and for Esc), 1 for an error, 130 for Ctrl+C. An agent run returns the agent's exit code.
|
|
188
209
|
|
|
189
210
|
<details>
|
|
190
211
|
<summary><strong>Development and contributing</strong></summary>
|
package/bin/phantom.mjs
CHANGED
|
@@ -9,6 +9,41 @@
|
|
|
9
9
|
* even if it would. So `npm run build` compiles the source to dist/ and this
|
|
10
10
|
* file, which never needs compiling, is what npm points at.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import { spawn } from 'node:child_process';
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
|
+
import { constants } from 'node:os';
|
|
15
|
+
import path from 'node:path';
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
function platformPackageFile() {
|
|
18
|
+
const platformPackage = `@phantomcodes/cli-${process.platform}-${process.arch}`;
|
|
19
|
+
try {
|
|
20
|
+
const manifest = createRequire(import.meta.url).resolve(`${platformPackage}/package.json`);
|
|
21
|
+
return path.join(path.dirname(manifest), 'bin', 'phantom');
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function leaveToTheChild() {}
|
|
28
|
+
|
|
29
|
+
function runPlatformPackageFile(file) {
|
|
30
|
+
const child = spawn(file, process.argv.slice(2), { stdio: 'inherit' });
|
|
31
|
+
process.on('SIGINT', leaveToTheChild);
|
|
32
|
+
process.on('SIGHUP', leaveToTheChild);
|
|
33
|
+
process.on('SIGTERM', () => child.kill('SIGTERM'));
|
|
34
|
+
child.on('error', (err) => {
|
|
35
|
+
console.error(`phantom: could not start ${file}: ${err.message}`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
child.on('exit', (code, signal) => {
|
|
39
|
+
process.exit(signal ? 128 + constants.signals[signal] : (code ?? 1));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const file = platformPackageFile();
|
|
44
|
+
if (file) {
|
|
45
|
+
runPlatformPackageFile(file);
|
|
46
|
+
} else {
|
|
47
|
+
const { main } = await import('../dist/phantom.mjs');
|
|
48
|
+
await main();
|
|
49
|
+
}
|
|
@@ -1,36 +1,17 @@
|
|
|
1
1
|
import type { CommandInput } from '../core/helpers.mts';
|
|
2
2
|
import type { Env } from '../core/state.mts';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* AI through a local proxy ({@link startProxy}). The agent gets the proxy's
|
|
6
|
-
* address and the run's secret token as its key, in PHANTOM_AGENT_TOKEN; the
|
|
7
|
-
* proxy checks the token, drops it, adds the real key, and phantom prints what
|
|
8
|
-
* the run paid when the agent exits. The token never goes on a command line,
|
|
9
|
-
* where other programs could read it, or to Phantom AI.
|
|
10
|
-
*/
|
|
11
|
-
/** How phantom starts one agent against the proxy. */
|
|
12
|
-
export type AgentSpec = {
|
|
13
|
-
/** The program phantom runs. */
|
|
3
|
+
export declare function onPath(bin: string): boolean;
|
|
4
|
+
type AgentSpec = {
|
|
14
5
|
bin: string;
|
|
15
|
-
/** Phantom AI's path for this agent: `/claude-code`, `/codex` or `/coding-agent`. */
|
|
16
6
|
prefix: string;
|
|
17
|
-
|
|
18
|
-
launch(proxy: string, args: string[], env: Env, tmp: string, token: string): {
|
|
19
|
-
/** Everything the agent is started with: phantom's settings, then the user's arguments. */
|
|
7
|
+
launch(proxy: string, args: string[], env: Env, tmp: string, token: string, model?: string): {
|
|
20
8
|
args: string[];
|
|
21
|
-
/** The agent's environment. */
|
|
22
9
|
env: Env;
|
|
10
|
+
warning?: string;
|
|
23
11
|
};
|
|
24
12
|
};
|
|
25
|
-
|
|
26
|
-
export declare const AGENTS: Record<
|
|
27
|
-
|
|
28
|
-
* `phantom claude`, `phantom codex` and `phantom pi`: runs the agent through the proxy,
|
|
29
|
-
* passing every other argument through, and returns its exit code. The Phantom CLI's own
|
|
30
|
-
* flags come first and stop at the first other argument or at `--`; they are
|
|
31
|
-
* read here, not with `flags`, because everything after them belongs to the
|
|
32
|
-
* agent. Run by `run()`.
|
|
33
|
-
*/
|
|
13
|
+
export type Agent = 'claude' | 'codex' | 'pi' | 'opencode';
|
|
14
|
+
export declare const AGENTS: Record<Agent, AgentSpec>;
|
|
15
|
+
export declare const ROUTES_HERE: readonly Agent[];
|
|
34
16
|
export declare function agentCommand(input: CommandInput): Promise<number>;
|
|
35
|
-
|
|
36
|
-
export declare function notInstalled(bin: string): string;
|
|
17
|
+
export {};
|