glm

command module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

glm

Quota monitor and activation tool for the GLM coding plan, Command Code, and ChatGPT Codex, with systemd-based scheduling. The Google Antigravity (Gemini) provider is usage-query only (glm status --provider agy): activation logic was removed after Google tightened risk controls around non-CLI generation traffic.

All backends share the same 5-hour window model, so one daemon drives any of them: it wakes at the reported reset (or the configured schedule), fires a minimal request to anchor a fresh window, and verifies via the quota API. Codex is the exception on when it fires: the hello goes out only when the 5h window is not already open.

Providers

glm (default) — GLM coding plan quota via the bigmodel API.

agy — Google Antigravity / Gemini Code Assist (what the agy CLI uses). Usage query only. Quota is reported per pool — Gemini Models and Claude & GPT Models — each with a 5h bucket plus a weekly bucket (weekly buckets self-refill on a rolling 7-day window on their own). glm sends exactly one read per status call (retrieveUserQuotaSummary) plus the OAuth token refresh; it never fires warmup/generateContent probes. active/install reject the provider.

commandcode — Command Code (commandcode.ai), the account's static CLI key. Quota comes from /alpha/billing/credits (a 5h credit bucket, cap 14 on the individual plan, plus a rolling weekly one); the warmup is a single minimal /provider/v1/responses request (~1.4e-5 credits on the contributor model). Models are plan-gated — the default warmup model answers on the individual plan, set commandcode.model to change it.

codex — ChatGPT Codex, using the local Codex CLI login (~/.codex/auth.json, or CODEX_HOME). Quota is GET /backend-api/wham/usage. The 5h window starts at the first request after the previous one ends, so the daemon does not ping on startup when the window is already open: it sleeps until the reported reset (wall clock, in 30s chunks, so a suspend is noticed on wake), reads usage again, and sends one gpt-6-luna "hello" only if the window is not open. Real use that moved the reset just updates the next check. A boot after shutdown is the same check. Tokens stay in the CLI's auth.json and are refreshed in place when they are about to expire.

With a single config file, --provider picks the section (and systemd unit), so all daemons run side by side:

glm agy commandcode codex
config section top level (api_key, schedule) agy: (refresh_token) commandcode: (api_key, schedule) codex: (no key; model, schedule)
service glm.service — (no daemon; usage query only) glm-commandcode.service glm-codex.service

(An explicit --config path overrides the default file for all providers.) The access token is cached in ~/.cache/glm/agy.json (0600) so a warm glm status --provider agy is a single HTTPS round trip (~1s).

Commands

glm login                 # set API key (prompts; or -k <key>)
glm status                # show current quota
glm active [-f]           # activate quota once (use --service to run as daemon)
glm install               # install/update the systemd service with the configured schedule
glm install --auto        # ... in auto mode (follow the API quota reset)
glm install --at "+8 09:00 20:00" # ... in fixed-time mode (timezone + times)
glm reload                # reload config without restarting (SIGHUP)
glm uninstall             # stop, disable, and remove the service
glm completion install    # install completion for the current shell ($SHELL)
glm version               # print the glm version
glm update [--check]      # self-update from GitHub releases (sha256-verified)

Shell completion: run glm completion install once (for zsh use sudo glm completion install so it lands in /usr/local/share/zsh/site-functions, which is in the stock fpath). glm completion <shell> prints the raw script instead.

Every command takes the global --provider agy flag to operate on the agy scope instead (usage query only):

glm login --provider agy            # auto-import refresh token from the
                                    # local agy CLI login (or -k <token>)
glm status --provider agy           # both pools, 5h + weekly buckets
glm active --provider agy           # error: activation was removed
glm install --provider agy          # error: no daemon for agy
glm uninstall --provider agy        # removes a legacy glm-agy.service

And for Command Code:

glm login --provider commandcode -k <key>   # the CLI's static Bearer token
glm status --provider commandcode           # 5h + weekly windows, monthly credits
glm active --provider commandcode           # one-shot warmup of the 5h window
glm install --provider commandcode --auto   # glm-commandcode.service
glm reload --provider commandcode
glm uninstall --provider commandcode

And for Codex (the Codex CLI must already be signed in with ChatGPT):

glm login --provider codex              # checks ~/.codex/auth.json; copies nothing
glm status --provider codex             # 5h + weekly, and whether the 5h window is open
glm active --provider codex             # one hello, only if the 5h window is not open
glm install --provider codex --auto     # glm-codex.service; follows the API reset
glm reload --provider codex
glm uninstall --provider codex

And the coding plan's reset cards — the CLI talks to zcode.z.ai directly (no local gateway involved); auth comes from the zcode CLI's own credential store (~/.zcode/v2/credentials.json, so sign in once with zcode):

glm status                  # provider windows + the reset-card section
glm reset use               # spend one card on the 5h window now
glm reset use --window week
glm reset claim             # ask the server for a new card (one attempt)

The engine is manual-only: it advises (the reset section in glm status) and never spends cards on its own. Advice thresholds are tunable under reset: in the config (exhausted_pct, reset_gap_min, expiry_fire_min, value_max_pct_per_h, min_gain_pct, cooldown_min, exhausted_trigger / expiry_trigger — unset = engine defaults). The JWTs can be overridden with ZCODE_JWT / MAAS_JWT. Retried use/claim requests reuse their idempotency key (state in ~/.local/state/glm/reset-state.json), so a timeout can't double-spend a card.

glm install installs a system service by default (boot-persistent, no login required). Use --user to install a user service instead. The daemon runs active --service: activate, sleep until next run, repeat. Running install again is the update path: it rewrites the unit and restarts the service with the new schedule — the same command installs and updates.

Server deployment

On a headless server, install as a system service so it survives logout and starts at boot — no lingering needed:

sudo glm install --auto

The service runs as the invoking user (resolved from SUDO_USER) and reads that user's config, so first run glm login as yourself, then sudo glm install.

On a desktop or without root, use a user service instead (legacy behavior; needs loginctl enable-linger to survive logout):

glm install --user --auto

Inspect and reload:

systemctl status glm            # system scope (or: systemctl --user status glm)
journalctl -u glm -f            # follow logs (or: journalctl --user -u glm)
glm reload                      # re-read config without restarting
glm uninstall                   # auto-detects scope and removes it

Config

Single file: ~/.config/glm/config.yaml, one section per provider, each with its own schedule (commandcode falls back to the shared top-level schedule when its own schedule: is absent).

# --- glm provider (top level) ---
api_key: sk-xxxxx
# base_url: https://...
# proxy: http://...
schedule:
  auto: true
  # or explicit:
  # timezone: +8
  # times:
  #   - "09:00:00"
  #   - "20:00:00"

# --- agy provider (usage query only) ---
agy:
  refresh_token: 1//0xxxxx    # or omit to read it from the local agy CLI
  # client_id / client_secret: defaults to the Antigravity client
  # user_agent: ...           # quota-query UA override (default: the agy CLI's own)
  # endpoint / token_file: rarely needed
  # proxy: http://...         # routes only agy traffic

# --- commandcode provider ---
commandcode:
  api_key: user_xxxxx         # the commandcode CLI's Bearer token
  # model: meta/muse-spark-1.3-contributor   # warmup model (plan-gated!)
  # cli_version: 1.56.0       # x-command-code-version header override
  # proxy: http://...         # routes only commandcode traffic
  schedule:
    auto: true

# --- codex provider (no key; uses the Codex CLI login) ---
codex:
  # model: gpt-6-luna          # hello model
  # effort: low
  # home: ~/.codex             # or CODEX_HOME
  # cli_version: 0.163.0       # User-Agent; default is models_cache.json
  schedule:
    auto: true                 # recorded by install; the loop follows the API reset

proxy is shared; schedules are per provider.

Use a custom config path with --config:

glm --config ./config.yaml login
glm --config ./config.yaml install --auto

Why agy is usage-query only

Google tightened risk controls around Antigravity (Gemini) traffic that does not come from the official CLI, so glm no longer sends any generation request for this provider. The warmup probes that anchored 5h windows (scheduled 1-token generateContent calls, weekly-bucket refreshes) were removed — that automation was outside the product's intended use, and keeping the account un-flagged matters more than keeping windows warm. Weekly buckets self-refill on their own; a 5h window still anchors whenever the real agy CLI or IDE is used.

What remains is read-only: the OAuth token refresh and one retrieveUserQuotaSummary call per glm status --provider agy, sent with the official client's OAuth pair and User-Agent (agy.user_agent overrides the latter). If you previously installed glm-agy.service, remove it with glm uninstall --provider agy.

Install

Prebuilt binaries: grab one from a GitHub release (glm-<goos>-<goarch>, sha256-verified against the release's checksums.txt), or let the CLI do it:

glm update        # download the latest release for this platform and replace the binary
glm update --check

With a Go toolchain:

go install github.com/xihale/glm@latest

Or build from source:

go build -o glm .

glm version prints what's running: the release tag for go install/release builds, a pseudo-version (commit + dirty flag) for local source builds.

License

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
agy
Package agy implements the Antigravity (Google Gemini Code Assist for individuals) quota provider: OAuth token refresh and the quota summary query behind `glm status`.
Package agy implements the Antigravity (Google Gemini Code Assist for individuals) quota provider: OAuth token refresh and the quota summary query behind `glm status`.
cc
Package cc implements the Command Code (commandcode.ai) quota provider: static-key auth, the minimal OpenAI-Responses-shaped warmup request that anchors a fresh 5-hour window, and the billing/credits view of that window.
Package cc implements the Command Code (commandcode.ai) quota provider: static-key auth, the minimal OpenAI-Responses-shaped warmup request that anchors a fresh 5-hour window, and the billing/credits view of that window.
codex
Package codex anchors a ChatGPT Codex 5-hour window.
Package codex anchors a ChatGPT Codex 5-hour window.
glm
log
reset
Package reset talks to the zcode coding-plan reset-card API (zcode.z.ai/api/v1/coding-plan/reset/*) directly — no local gateway in between.
Package reset talks to the zcode coding-plan reset-card API (zcode.z.ai/api/v1/coding-plan/reset/*) directly — no local gateway in between.
ui
update
Package update implements glm's self-update: find the latest stable GitHub release, compare it against the running version, download the build for this GOOS/GOARCH, verify its sha256 against the release's checksums.txt, and atomically replace the running binary.
Package update implements glm's self-update: find the latest stable GitHub release, compare it against the running version, download the build for this GOOS/GOARCH, verify its sha256 against the release's checksums.txt, and atomically replace the running binary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL