omp packages

@phantomcodes/cli1.7.0

Starts your coding agents (pi, Codex, Claude Code) and routes their requests to your own accounts with phantom-1: the Vercel AI Gateway, Z.ai and your ChatGPT plan.

GitHub Actions Published 2 hours ago SEE LICENSE IN LICENSE ~8.6K downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

Phantom CLI

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.

Docs · npm

Install and start

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:

curl -fsSL https://phantom.codes/install | sh
phantom

On Windows, Alpine and older Linux, use Node 24 or newer: npm i -g @phantomcodes/cli.

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:

Standard glm-5.4 on zai · Frontier gpt-6.1-sol on chatgpt · ! chatgpt needs sign-in

The first time, before there is any routing to show, phantom opens the settings first, then comes back to the list.

Command What it does
phantom pi, OpenCode, Settings and Report
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
phantom config the settings: Standard, Frontier and providers
phantom login, phantom logout sign in to Phantom and save your key, or remove it from this computer (see Sign in and add credit)
phantom report what routing did
phantom replay other routing settings tried on saved traces (see Traces)

Without a terminal (in a script or a pipe), phantom prints these as three lines and starts nothing.

Settings

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.

? Settings
❯ Standard    glm-5.4 · Z.ai
  Frontier    gpt-6.1-sol · ChatGPT
  Providers   ChatGPT ✓ · Z.ai ✓ · Vercel AI Gateway ✓
  Back
  • 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.
  • 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.

Each choice runs the same command a script would, so you can see the script form in phantom config --help:

phantom config --standard zai:glm-5.4 --standard-fallback gateway:deepseek/deepseek-v4.1-flash-1017 \
  --frontier chatgpt:gpt-6.1-sol --frontier-fallback gateway:anthropic/claude-sonnet-5.5
pbpaste | phantom config key set gateway --stdin
phantom config key use-keychain zai --service zai-api-key --keychain-account you
phantom config key rm zai
phantom config chatgpt login
phantom config models gateway
phantom config show

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.

Where the keys come from

Each key account (the Gateway, Z.ai) reads its key from one place:

  • 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.
  • 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.
  • 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.

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.

local.json

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:

{
  "accounts": {
    "gateway": { "kind": "gateway", "key": { "from": "saved" } },
    "zai": { "kind": "zai-coding-plan", "key": { "from": "keychain", "service": "zai-api-key", "account": "you" } },
    "chatgpt": { "kind": "chatgpt-plan" }
  },
  "tiers": {
    "standard": { "account": "zai", "model": "glm-5.4", "fallback": { "account": "gateway", "model": "deepseek/deepseek-v4.1-flash-1017" } },
    "frontier": { "account": "chatgpt", "model": "gpt-6.1-sol", "fallback": { "account": "gateway", "model": "anthropic/claude-sonnet-5.5" } }
  }
}
  • 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.
  • 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" }.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.

Start an agent

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:

phantom pi -- -p "list the files in this folder"
# phantom: pi routes on this computer: Standard glm-5.4 on zai, Frontier gpt-6.1-sol on chatgpt (local.json)
# phantom: pi made 7 requests: 5 Standard (zai), 2 Frontier (chatgpt), 1 fallback; log: ~/.config/phantom/local/requests.jsonl

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.

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.

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.

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).

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).

phantom opencode does the same for OpenCode:

phantom opencode                                   # OpenCode's own screen
phantom opencode -- run "list the files in this folder"
# phantom: opencode routes on this computer: Standard glm-5.4 on zai, Frontier gpt-6.1-sol on chatgpt (local.json)
# phantom: opencode made 3 requests: 2 Standard (zai), 1 Frontier (chatgpt); log: ~/.config/phantom-key/local/requests.jsonl

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.

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:

  • a model outside the run's provider is offered;
  • 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;
  • a config file changes the run's provider (an address, a model, a package);
  • OpenCode can't say where a session named with -s lives, or doesn't answer within 30 seconds.

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.

What the check doesn't cover:

  • OpenCode plugins run their own code inside OpenCode, and one can make its own network calls. phantom doesn't read or limit them.
  • 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.

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.

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.

Sign in and add credit

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.

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.

phantom's own flags go before the agent's arguments, with -- between them: phantom codex -- exec "review this repository".

See what routing did

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:

{"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}}}
  • 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.
  • 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.
  • 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.
  • 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>.
  • id matches the answer's x-phantom-local-request-id header, so an error your agent shows can be found in the file.
  • 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.
  • 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.
  • 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.
  • 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.
  • Past 10 MB the file becomes requests.1.jsonl, replacing the older one, and a new file starts.
  • "log": false in local.json turns the file off.

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.

Traces: full prompts and answers, off by default

phantom never stores message text unless you turn traces on:

phantom config --traces on    # start saving from the next phantom pi
phantom config --traces off   # stop saving from the next phantom pi; what is saved stays
rm -r ~/.config/phantom/local/traces   # delete what is saved

A phantom pi reads local.json when it starts, so one already running keeps its setting until it ends.

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.

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.

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.

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.

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.

Output and exit codes

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.

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.

Development and contributing

The CLI lives in cli/ in the Phantom repo, which uses pnpm. Install once at the repo root, then run the checks from cli/:

pnpm install
cd cli
pnpm typecheck
pnpm test
pnpm build
pnpm coverage

Report a security problem privately to support@phantom.codes, not in a public issue.

phantom is proprietary, under the Phantom Proprietary License. It lets you install and run phantom to use Phantom AI, the hosted API it calls.