Skip to content

[Bug]: Bundled CLI headless mode (-p) cannot use Coding Plan — zcode login mints a PAYG key that returns 1113 #34

Open

Description

@EduerPJ

What happened?

The CLI bundled with the ZCode desktop app (v0.16.5, node …/ZCode.app/Contents/Resources/glm/zcode.cjs) cannot authenticate headless mode (zcode -p) against a paid GLM Coding Plan (team plan, provider builtin:zai-coding-plan).

What we verified step by step on macOS (ZCode desktop 3.11.2):

  1. zcode login (browser OAuth, same account as the desktop app) succeeds and writes provider["builtin:zai-coding-plan"] + model.main = "builtin:zai-coding-plan/GLM-5.3" to ~/.zcode/cli/config.json.
  2. Any zcode -p "…" run then fails with HTTP 429 / business code 1113 ("Insufficient balance or no resource package. Please recharge.") — the exchanged key is a public PAYG key; the Coding Plan subscription is not attached to it. Example request id: 2026090603152417b590b052694c30.
  3. The desktop app itself works at the same time, same account, same provider id, logging model.network requests to https://api.z.ai/api/anthropic with builtin:zai-coding-plan/GLM-5.3. So the working credential never leaves the app's memory (passed to the runtime over the protocol, not env/config).
  4. Direct probes against the plan gateway:
    • https://zcode.z.ai/api/v1/zcode-plan/anthropic/v1/messages with the official ZCode JWT (zcodejwttoken from the shared credential store) as Authorization: Bearer … → HTTP 400, {"code":3007,"msg":"captcha verify failed"}; as x-api-key → 401.
    • https://api.z.ai/api/anthropic/v1/messages with every persisted credential (exchanged key, OAuth access token, JWT) → 1113 or 401.
  5. The interactive tui subcommand is also unusable in this distribution: Cannot find package '@zcode/tui' (the package is neither bundled next to zcode.cjs nor published on npm), so the /login zai-coding-plan flow documented in the bundle cannot be reached from a terminal. Running /login zai-coding-plan via -p answers "not available in this client".

Related community report describing the same key-minting behavior in a third-party client: can1357/oh-my-pi#8802.

Question / expected behavior: is there a supported way for the standalone CLI (headless -p) to consume a paid Coding Plan? Expected: zcode login on a Coding-Plan account should produce credentials that actually serve plan traffic (either a plan-attached key on api.z.ai or the official JWT against zcode.z.ai/api/v1/zcode-plan/anthropic), instead of a PAYG key that returns 1113.

Relevant log output

$ zcode -p "test" --cwd ~/Herd/zalvadora
ProviderBusinessError: [1113][Insufficient balance or no resource package. Please recharge.][2026090603152417b590b052694c30]
  code: 'PROVIDER_BUSINESS_ERROR',
  providerCode: '1113',
  providerId: 'builtin:zai-coding-plan',
  providerKind: 'anthropic',
  responseStatus: 429

$ zcode            # TUI
Error: Cannot find package '@zcode/tui' imported from /Applications/ZCode.app/Contents/Resources/glm/zcode.cjs

Environment: macOS 15 (darwin 25.6.0 arm64), ZCode desktop 3.11.2, bundled CLI 0.16.5, node v24.15.0, Z.ai Coding Plan (team plan) on the logged-in account.

No API keys or tokens are included in this report.

Activity

  1. Motoharu-Kataoka commented on Oct 24, 2026

    @Motoharu-Kataoka

    Same wall here, on a different plan tier and error signature — adding repro data.

    Environment

    • ZCode desktop 3.16.3 / bundled CLI 0.17.0 (resources/glm/zcode.cjs, run with node v22.23.4)
    • Windows 11 (build 26300) x64
    • Plan: Z.AI Start Plan (free entry tier, via zcode.z.ai gateway)
    • The desktop app itself works fine on the same account (this report is even being written from a working desktop-hosted session).

    Reproduction

    1. zcode login zai --no-browser → OAuth succeeds, writes defaultModelSelection: account:zai-individual-coding-plan/GLM-5.3 into ~/.zcode/v2/provider_config.json.
    2. zcode -p "..." --json --mode yolo → model selection now passes, but turn execution fails:
    [project-access-token] { family: 'zai', stage: 'resolve', code: 'project_token_login_failed' }
    Error: Turn execution failed
    
    1. Root cause (traced): the CLI mints a project access token by POST https://api.z.ai/api/auth/z/login with the OAuth access token, and the endpoint answers:
    {"code":500,"msg":"Z.ai user information is invalid","data":null,"success":false}

    The same token works for desktop sessions because the desktop host injects the coding-plan key into CLI child processes via env instead of minting one — so the plan credential never reaches the standalone CLI.

    Notes

    • Not a permission-mode issue: --mode plan and --mode guarded fail identically (it is authentication, not tool policy).
    • Attempts to bypass locally all fail: personal providerRules in provider_config.json never reach the standalone registry; the builtin provider config is integrity-protected by the signed remote-refresh mechanism; writing account-provider:…:api-key slots into the shared credential store does not change the mint flow.
    • This blocks any unattended/automation use of the CLI against a plan subscription (CI, agent orchestration), which is the same effect described in this issue for team plans.

    Would be great to know if there is (or is planned) a supported path for headless CLI usage of plan subscriptions — either fixing the standalone mint flow, exposing a coding-plan API key usable by the CLI, or letting the desktop act as a credential host for headless child sessions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions