pi-commandcode-provider
pi custom provider for Command Code API (commandcode.ai)
Package details
Install pi-commandcode-provider from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-commandcode-provider- Package
pi-commandcode-provider- Version
0.8.0- Published
- Nov 5, 2026
- Downloads
- 8,422/mo · 1,865/wk
- Author
- patlux
- License
- MIT
- Types
- extension
- Size
- 270.2 KB
- Dependencies
- 0 dependencies · 2 peers
Pi manifest JSON
{
"extensions": [
"./index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-commandcode-provider
A custom provider for pi that connects to the Command Code Provider API.
Disclaimer: This is an unofficial, community-maintained integration. It is not affiliated with, endorsed by, or supported by Command Code. You need your own Command Code account, API key, and a plan with Provider API access. Command Code's terms, availability, and pricing apply.
Provider API access required
This extension requires Provider API access. GOAT, Pro, Max, Team and Provider accounts with API entitlement use the documented inference endpoints. The Go plan does not include API access. A successful login or quota response does not establish inference entitlement.
A 403 upgrade_required stops with an actionable error; the extension never retries the prompt on the internal /alpha/generate endpoint. There is no switch to restore that fallback. Endpoint overrides select a supported Provider API wire, not a way around plan restrictions.
If you previously used the Go fallback, use the official Command Code CLI within its supported plan, or an account with Provider API entitlement. After an entitlement change, retry a small request; if you changed accounts, run /login again and reload the host. Existing credentials, sessions and persisted endpoint choices are not deleted or migrated.
The Provider API-only rule here applies to inference. Authentication/key validation and read-only account/quota reporting still use internal account endpoints; they do not generate text or grant missing API access. These are not claimed to be documented Provider API routes. See the quota limitations below.
Install
pi install npm:pi-commandcode-provider
Start or reload pi, then authenticate:
/login
Select Use a subscription, then Command Code. Choose browser login or paste an API key, then select a model with /model.
Oh My Pi
Install the same package in Oh My Pi:
omp plugin install pi-commandcode-provider
Restart OMP or run /reload, then use /login and select Use a subscription followed by Command Code.
Authentication
Login dialog
Run /login in pi or OMP. Select Use a subscription, then Command Code. Press Enter for browser login, type key to open a paste prompt, or paste the API key directly. The selected credential is stored in the host's auth file.
If automatic transfer from the browser fails, copy the API key shown by Command Code and paste it into the terminal prompt.
On Oh My Pi, /login stores those credentials in OMP's credential store and chat uses them directly. If chat still returns 401 Invalid 'Authorization' header, restart OMP after /login and confirm /commandcode-quota shows your account.
Environment variable
export COMMAND_CODE_API_KEY="user_..."
Auth file
The provider also reads existing credentials from, in this order:
~/.commandcode/auth.json~/.pi/agent/auth.json(or$PI_CODING_AGENT_DIR/auth.jsonwhen pi runs with that variable)~/.omp/agent/auth.json
The Provider API path and the quota commands use the same ambient lookup, after any credentials supplied by the host. PI_CODING_AGENT_DIR redirects only the pi auth-file slot; the .commandcode and .omp paths still use HOME. Isolate HOME as well when a sandbox must not read those credentials.
Supported examples:
{
"apiKey": "user_..."
}
{
"command-code": {
"type": "api",
"key": "user_..."
}
}
{
"commandcode": "user_..."
}
Usage
Open /model and select one of the models provided by Command Code. Model availability changes over time and is refreshed from the Provider API when the extension loads.
Other extensions that stream with the active Command Code model, such as background agents or memory workers, use the same connection and the same credentials as the chat, so their requests count against your Command Code usage.
Endpoint selection
The Provider API serves models on different wires, and /provider/v1/models advertises the routes each model answers on through its supported_endpoints field. The provider maps that to the matching wire:
- Claude models answer on
/provider/v1/messagesonly. - Models advertising
/responsesuse the OpenAI Responses wire on/provider/v1/responses. - Every other model uses OpenAI Chat Completions on
/provider/v1/chat/completions.
A model whose catalog entry omits supported_endpoints keeps Chat Completions, which every non-Claude model serves, so discovery keeps working when the field is absent. The selection is applied per model, so a catalog that mixes wires streams each model correctly.
Persistent endpoint overrides
Use /commandcode-endpoint <model-id> chat-completions to select Chat Completions for one model, for example:
/commandcode-endpoint zai-org/GLM-5.3 chat-completions
Use responses to select Responses where the catalog advertises it, or auto to remove that model's override and restore catalog routing. Claude models require auto (Anthropic Messages). Use the exact catalog model ID, without the host's commandcode/ provider prefix. The command waits for the current turn to finish and affects subsequent requests; it never retries a partial stream on another endpoint. /commandcode-status and /commandcode-diagnostics show the effective model endpoint and whether it came from the catalog or a user override. Endpoint overrides apply only to Provider API requests and cannot grant missing plan access. This is a routing choice, not a guarantee of upstream capacity, throughput or caching.
Choices are stored in commandcode-routing.json inside the host agent directory, separate from the generated model cache. They survive refreshes, restarts and package updates. Do not edit the model cache. A malformed or unreadable routing file is ignored with a visible warning, so requests use catalog routing until repaired. Startup does not rewrite it. Run an explicit /commandcode-endpoint command to repair a malformed file: the invalid choices are replaced, and its previous contents are preserved in a mode-0600 commandcode-routing.json.invalid-*.bak file in the same directory. An unreadable file is not overwritten; fix its permissions first. A syntactically valid choice that the current catalog no longer supports is rejected for that model; use auto to reset it.
Host/user compatibility settings are preserved when they are associated with the same wire as the request. Switching wires (including a catalog change) replaces stale compatibility flags with the new wire's defaults instead of merging them; an old host model must not carry Responses flags into Chat Completions. Models no longer in the catalog use the ID-based fallback, and status explicitly notes that stored endpoint choices are ignored until that model returns.
Changes made to the file externally require a reload (or a successful endpoint command). Commands within one host are serialized, but writes from separate host processes are not coordinated; use one host to change routing settings.
Reasoning support
Reasoning capability and selectable effort levels follow the official CLI catalog independently. Models can therefore be marked as reasoning-capable even when Command Code chooses their depth automatically. Models with explicit effort support register a model-specific thinkingLevelMap, so pi and OMP expose only valid levels. For a few reasoning models the CLI catalog ships no effort levels although the endpoint accepts reasoning_effort; src/commandcode-catalog-overrides.ts adds a manual level set for those on top of the generated catalog (currently empty because upstream publishes every level). The catalog sync removes an override as soon as upstream publishes its own levels. Pi's native OpenAI- and Anthropic-compatible providers translate the selected level for Provider API accounts.
List Command Code models from the terminal:
pi --list-models commandcode
In OMP, use:
omp models
For non-interactive OMP requests, use a provider-qualified model ID shown by omp models. For example:
omp -p "hello" --model commandcode/deepseek/deepseek-v4-flash
Model discovery and offline behavior
The provider fetches the current model catalog from:
https://api.commandcode.ai/provider/v1/models
The last successful catalog is cached at <agent-dir>/commandcode-models.json. For pi this is ~/.pi/agent/commandcode-models.json by default. Compatible hosts such as OMP use their own agent directory.
When a valid cache exists, the provider registers the cached catalog immediately and refreshes it from the endpoint in the background, so startup does not wait for the network. The refreshed catalog replaces the cached one as soon as it arrives; /commandcode-status reports source: cache until then. If the endpoint is temporarily unavailable, the cached catalog stays active. On a first start without a cache, the provider waits for the live catalog; if that fails offline, pi still loads, but Command Code models remain unavailable until the connection is restored and /commandcode-refresh succeeds.
While pi is running, use these provider commands without restarting:
/commandcode-refreshfetches and re-registers the current model catalog, and resets the latest transport status. Every inference attempt uses the Provider API; entitlement denials are not cached. Overlapping refreshes are coalesced, and a failed refresh keeps the last valid catalog active./commandcode-statusshows redacted discovery diagnostics, including the source, model count, timestamps, cache path, endpoint, and warning. Transport status isunknownuntil the latest inference attempt completes successfully; a denial remainsunknown, not proof of API entitlement. If a Responses reasoning event has an unsupported shape, a separate stream warning is cleared when the next Responses HTTP request starts, before its outcome is known. Requests on Chat Completions or Messages do not clear it. The slot is shared by concurrent Responses requests, so a late warning from an older in-flight response can still replace it. The event is preserved unchanged; no reasoning text is included in the warning./commandcode-diagnosticsshows a shareable support report: plugin/host version, CLI snapshot, selected transport and wire, capability provenance, price status, and the latest request's HTTP status, attempts, outcome, first body-chunk latency and longest gap. It keeps only one request summary in memory. It never collects prompts, tool content, credentials, raw errors, account data or configured local paths. Model identifiers come from the host; recognized path-/credential-shaped values are redacted, but custom names can still identify your setup. Request IDs are included only when they match a bounded hexadecimal/UUID format. Timing is measured between body chunks, not tokens; first-chunk latency may include an error response. A request started most recently owns the report even if another request finishes later. Retry counts are scoped to that stream call, not host-level retries. Review the report before sharing it./commandcode-quotashows your Command Code account usage and quota in a dashboard-style layout: credits remaining and used with a percentage, monthly/purchased/free sources, the current plan, available usage totals, the API key name, and the 5-hour and weekly usage windows.
As an explicit exception to the inference policy, the commandcode-quota command reads from the internal Command Code alpha usage endpoints (the same ones the cmd CLI /usage command uses): whoami, billing/credits, billing/subscriptions, and usage/summary. It authenticates with the same API key the provider already uses. These requests are GET-only account/usage reads, not an inference fallback. Their success says nothing about Provider API entitlement; the undocumented schemas and availability may change independently. If the command cannot reach those endpoints or an endpoint schema changes, unavailable sections are reported explicitly instead of being displayed as zero usage. Output is plain text (via ui.notify) so it works across pi and compatible hosts such as OMP.
On Oh My Pi the provider also registers an OMP usage provider through the usage field of pi.registerProvider, reading the same endpoints with the same credentials. It supplies the account's 5-hour and weekly usage windows, credits remaining and used against the billing-period pool, and the current plan to the host's usage surfaces, and it follows the same rule for sections the API does not report. pi has no such field and ignores it.
Set CMD_ZDR=1 to send Command Code's documented x-cmd-zdr: 1 zero-data-retention header. The legacy COMMANDCODE_ZDR=1 alias remains supported.
The following environment variables are intended for tests, local mocks, and compatible API endpoints:
COMMANDCODE_API_BASE(Provider API base; the alpha endpoints used by/loginkey validation and/commandcode-quotaare derived from it without the/provider/v1suffix; an explicitly empty value does not fall back to production)COMMANDCODE_MODELS_URLCOMMANDCODE_MODELS_CACHECOMMANDCODE_MODELS_TIMEOUT_MS(defaults to 10 seconds; invalid or non-positive values use the default)
Image input
The provider advertises image input only for models marked with the image input modality in the official Command Code CLI model catalog. The capability snapshot currently follows command-code@1.88.3; unknown models default to text-only until their upstream metadata is reviewed. A daily GitHub Actions job synchronizes the CLI version, image capabilities, reasoning flags, reasoning efforts, and model-specific output limits with the latest published CLI package, also dropping manual effort overrides that upstream has published itself, and opens or updates a reviewable pull request when they change. Pricing remains manually reviewed because temporary promotions and long-context tiers require explicit review.
For vision-capable models, Pi's native provider adapters forward image blocks from user messages and tool results using the documented OpenAI or Anthropic message schema. Unknown and text-only models remain marked text-only in Pi.
The native host adapter uses the registered model's input capabilities on the Provider API. Host overrides can advertise image support before the catalog catches up, but cannot grant missing model or plan access.
Pricing display
The Command Code Provider API does not currently include prices in its model catalog. This extension therefore keeps a static table for models with known prices so pi and OMP can display estimated request costs. DeepSeek V4 uses time-dependent rates: the extension applies the documented 2x peak rates on weekdays from 01:00-04:00 and 06:00-10:00 UTC, and off-peak rates at all other times, including the entire weekend. These rates are selected at request time on the native Provider API path.
Models missing from that table display zero cost in pi. The provider warns once per selected unpriced model per load, and diagnostics distinguishes an unknown price from an explicitly free model. An expired tracked promotion is marked review-required; the snapshot verification date is always shown. This does not mean that Command Code will bill the request at zero. The Command Code Usage page remains authoritative for each request. Check the current Command Code pricing before relying on the displayed value.
A read-only companion check, npm run check:commandcode-pricing, compares the live Provider API catalog and the official pricing page with the static table. It never writes prices: exit code 0 means every compared rate matches, 1 means drift or an expired promotion needs manual review, and 2 means the price could not be checked. The daily catalog workflow and applicable pull requests publish the Markdown report to the GitHub Actions summary. The pricing page has no public pricing API, so the check parses its private Next.js Flight payload; if that format changes the check fails loudly instead of reporting a false pass, and prices stay manually reviewed.
Update and remove
Update installed pi packages:
pi update --extensions
Remove the provider:
pi remove npm:pi-commandcode-provider
For OMP:
# Update
omp plugin install pi-commandcode-provider --force
# Remove
omp plugin uninstall pi-commandcode-provider
Development
Start an isolated pi instance with only the current checkout installed and no existing Command Code credentials:
npm run pi:isolated
Run /login inside pi. Temporary credentials, configuration, and sessions are deleted when pi exits.
Start the current checkout with your existing pi credentials and only Command Code models in the model picker:
npm run pi:authenticated
Both commands accept additional pi arguments after --, for example npm run pi:authenticated -- --model claude-sonnet-4-6.
Live transport tests
Keep GOAT- and Provider-plan test keys in separate secret-manager entries. Pass them through protected files so the keys do not enter shell history:
COMMANDCODE_E2E_GOAT_API_KEY_FILE=/path/to/goat-key \
npm run test:e2e:live:goat
COMMANDCODE_E2E_PROVIDER_API_KEY_FILE=/path/to/provider-key \
npm run test:e2e:live:provider
COMMANDCODE_E2E_PROVIDER_API_KEY_FILE=/path/to/provider-key \
COMMANDCODE_E2E_GOAT_API_KEY_FILE=/path/to/goat-key \
npm run test:e2e:live:all
Each profile runs with an isolated Pi agent directory and asserts transport selection, reasoning across turns, quota plan identity, abort handling, tool calls, and the packed npm artifact. Both profiles must select provider; GOAT also completes a live vision request. Go entitlement denial and zero internal-generation requests are covered by isolated mock Pi/OMP tests, not paid probes. The profile-specific *_API_KEY environment variables are also supported for CI secrets, but key files are preferred for local use.
The Provider profile defaults to DeepSeek V4 Flash; GOAT defaults to Grok 4.6 because its Provider API stream exposes reasoning consistently across consecutive turns. Override them with COMMANDCODE_E2E_GOAT_MODEL or COMMANDCODE_E2E_PROVIDER_MODEL. The GOAT vision phase defaults to GPT-5.6 Luna and can be overridden with COMMANDCODE_E2E_GOAT_VISION_MODEL. A successful live Anthropic /provider/v1/messages test requires a paid account whose plan includes the selected Claude model.
See CONTRIBUTING.md for local setup and tests. See RELEASE.md for the release process.
Maintainers
License
MIT