glm

command module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 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, Google Antigravity (Gemini), Command Code, and ChatGPT Codex, with systemd-based scheduling.

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). Quota is reported per pool — Gemini Models and Claude & GPT Models — each with a 5h bucket plus a weekly bucket. Warmup is a single minimal generateContent (maxOutputTokens 1, ~0.1% of the bucket). Weekly buckets self-refill on a rolling 7-day window and cannot be accelerated by a request; opt into weekly: true to have the daemon wake at the weekly reset moment and fire a passive refresh anyway (costs ~0.02% of the weekly bucket; also anchors the 5h window if that one happens to be fresh at the time).

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.

Each pool can have its own schedule (and warmup model) via agy.pools; the daemon then runs one independent anchor loop per pool. A pool with weekly_only: true drops 5h anchoring entirely — its 5h window stays passive (anchored by real usage whenever it happens) and the loop only keeps the weekly bucket rolling: one warmup at startup while the bucket is fresh (a window nobody ever requests stays "not started"), then again at each reported weekly reset. 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, pools/schedule) commandcode: (api_key, schedule) codex: (no key; model, schedule)
service glm.service glm-agy.service glm-commandcode.service glm-codex.service

(An explicit --config path overrides the default file for all providers.) Access token and project id are cached in ~/.cache/glm/agy.json (0600) so a warm status is a single HTTPS round trip (~1s) instead of three.

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:

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           # one-shot warmup of the 5h window
glm install --provider agy --auto   # glm-agy.service, independent schedule
glm reload --provider agy
glm uninstall --provider agy

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. Under sudo, glm rewrites HOME to your real home so the config and schedule land in the right place. Install the agy daemon alongside with sudo glm install --provider agy --auto (or pass times).

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 (agy and commandcode fall back to the shared top-level schedule when their 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 ---
agy:
  refresh_token: 1//0xxxxx    # or omit to read it from the local agy CLI
  # client_id / client_secret: defaults to the Antigravity client
  # pool: gemini              # single-pool anchor (ignored when pools: is set)
  # model: gemini-2.5-flash   # warmup model (pool default if unset)
  # weekly: true              # passive refresh at the weekly reset moment
  # endpoint / project / token_file: rarely needed
  schedule:                   # agy's own policy; omit to share the top-level one
    timezone: "+8"
    times:
      - "06:00:00"
      - "16:00:00"
  pools:                      # multi-pool: one anchor loop per listed pool,
    gemini:                   # each with its own schedule/model/weekly
      schedule:
        timezone: "+8"
        times: ["06:00:00", "16:00:00"]
      weekly: true            # wake at the weekly reset, fire a warmup
    "3p":
      model: claude-sonnet-4-6
      weekly_only: true       # no 5h anchoring at all — the 5h window stays
                              # passive; the loop only keeps the weekly bucket
                              # rolling (startup fire while fresh, then at
                              # each weekly reset). schedule: is unused here.

# --- 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

Every pools: entry must set at least one key — an empty pool: {} is dropped by viper's config parsing and the pool silently vanishes (give it weekly: false or any explicit key instead).

proxy is shared; schedules are per provider (and per pool).

Use a custom config path with --config:

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

Account risk & client-version gating (agy)

Honest caveats before you point the agy provider at a Google account:

  • This automation is outside the product's intended use. Anchoring quota windows with scheduled 1-token probes is not something Antigravity sanctions; Google could detect and enforce against it. No account bans are known from this pattern (protocol studied live 2026-09), but the residual risk is yours: run it on your own account, keep the default gentle cadence (one anchor per 5h window), and don't share the refresh token across many machines. glm sends exactly what the official CLI sends — same OAuth client pair, same headers, same paths, no extra identifiers — at a volume of one quota read per wake and one warmup per window.
  • Stale client version is the risk you will actually hit. Google gates generateContent billing on a current official client version. With an outdated User-Agent: the prod endpoint answers blanket 429 RESOURCE_EXHAUSTED; the daily endpoint (glm's default) is worse — it returns HTTP 200 and real generations that never touch the quota buckets, leaving the window timer frozen at "4h59m". Symptom: warmups "succeed" but verification stays inconclusive forever. Fix: update the agy CLI and capture its current UA, then set agy.user_agent in the config (or wait for a glm release that bumps the pinned default).

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, quota summaries, and the minimal warmup request that anchors a fresh 5-hour window.
Package agy implements the Antigravity (Google Gemini Code Assist for individuals) quota provider: OAuth token refresh, quota summaries, and the minimal warmup request that anchors a fresh 5-hour window.
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