
GLM-5.4 in Claude Code: Meter Your Coding Plan Credits
Summary
Wire Z.ai's GLM-5.4 into Claude Code and track Coding Plan credit burn in Python.
Z.ai shipped GLM-5.4 on November 23, and within a day the announcement post was sitting at the top of Hacker News with more than a thousand points. The hook is the architecture: it is Z.ai's first Loop Transformer. Instead of stacking more layers, a 28-layer block taken from the GLM-5 base runs twice per token with shared weights. Z.ai's pitch is quality closer to a 2-3T-parameter model from something reported at roughly 750B parameters, plus a 1M-token context window and 128K tokens of output.
The catch that most launch threads skipped: GLM-5.4 is not on the pay-as-you-go API yet. Right now it lives on the GLM Coding Plan, which you consume through supported tools such as Claude Code, and the plan bills in credits per 5-hour window, not dollars. The model also thinks hard by default, and Z.ai itself warns about long "marathon thinking" turns. Put those together and the practical question for anyone switching today is simple: how fast will this thing eat my quota, and which turns are doing the eating?
This guide answers that. You will wire GLM-5.4 into Claude Code using Z.ai's documented settings, then build a small Python credit meter that reads Claude Code's own session transcripts, applies the Coding Plan's credit formula and peak-hour pricing, flags marathon turns, and runs live in your status line. Everything here runs on a laptop and the meter needs nothing beyond the standard library.
What you need
- A GLM Coding Plan subscription (Lite, Pro or Max) and a Coding Plan API key. Since October 16, 2026, Coding Plan keys and standard API keys are managed separately and are not interchangeable.
- Node.js 18+ and Claude Code (
npm install -g @anthropic-ai/claude-code). - Python 3.9+ for the meter. No third-party packages.
- About 20 minutes.
How GLM-5.4 differs from a normal model upgrade
A Loop Transformer re-applies the same block of layers more than once per token. In GLM-5.4 that block is 28 layers deep and runs twice, so the model gets extra depth of computation without storing a second set of weights. Reports of the technical post describe per-token gates that decide how much of each pass is written back, and a shared KV cache where the second pass keeps only a sliding window. Z.ai built it by converting the already-trained GLM-5 base with continued training rather than training from scratch.
Two things matter for you as a user. First, looping saves memory, not compute: each token still pays for both passes, which is part of why peak-hour throughput drops to around 70-80 tokens per second (Z.ai quotes up to 200 tok/s off-peak). Second, Z.ai has not published headline benchmark scores for GLM-5.4 itself yet; the evidence so far is an ablation on a 30B model of the same design. Treat it as promising and measure it on your own work, which is exactly what the meter helps with.
| Spec | GLM-5.4 | Source |
|---|---|---|
| Architecture | Loop Transformer, 28-layer block x 2 loops | Z.ai blog / launch coverage |
| Parameters | ~750B (unofficial; one report says 700B) | Launch coverage |
| Context / max output | 1M / 128K tokens | docs.z.ai GLM-5.4 page |
| Input | Text, image (docs table also lists video, file) | docs.z.ai |
| Where to use it | GLM Coding Plan (Claude Code, other supported tools) | docs.z.ai |
| Pay-as-you-go API | Not yet, pending security assessment | docs.z.ai |
| Open weights | Planned, no date | Launch coverage |
Step 1: Point Claude Code at GLM-5.4
Claude Code talks the Anthropic Messages protocol, and Z.ai exposes a compatible endpoint at https://api.z.ai/api/anthropic. Edit ~/.claude/settings.json and add an env block. These keys come from Z.ai's Claude Code setup page; the [1m] suffix selects the 1M-context variant.
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "your_coding_plan_key",
"ANTHROPIC_BASE_URL": "https://api.z.ai/api/anthropic",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "glm-5.4[1m]",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "glm-5.4[1m]",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "glm-5.3-flash[1m]",
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000",
"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "1000000",
"API_TIMEOUT_MS": "3000000"
}
}
Note the mapping. Anything Claude Code would send to its Opus or Sonnet slot now goes to GLM-5.4, and the Haiku slot goes to the much cheaper GLM-5.3-Flash. That split is the main lever you have over cost, and Step 5 uses it on purpose. API_TIMEOUT_MS at 3,000,000 (50 minutes) looks absurd until you hit a long thinking turn at peak speed; a 10K-token answer at 70 tok/s is already well over two minutes.
Smoke-test it in headless mode. The JSON result includes token usage, which is the raw material for everything that follows.
cd ~/code/shop-api
claude -p "In one sentence, what does src/orders.py do?" --output-format json | python3 -m json.tool | head -30
If you get an authentication error, the most common cause is pasting a standard API key instead of a Coding Plan key. If requests succeed but your quota does not move, double-check the base URL: Z.ai's docs warn that the wrong endpoint means your Coding Plan quota is not used.
Step 2: Understand how the Coding Plan charges you
The plan does not bill per dollar. Each request costs credits, using this formula from Z.ai's Coding Plan overview:
credits = (input_tokens x input_multiplier
+ cached_tokens x cached_input_multiplier
+ output_tokens x output_multiplier) / 10,000
Every plan has a 5-hour credit allowance and a weekly allowance: Lite 2,000 / 10,000, Pro 12,000 / 60,000, Max 28,000 / 140,000. Off-peak usage is charged at 50% of the standard rate, and peak hours are Monday to Friday, 14:00-18:00 Singapore time (UTC+8). That is 06:00-10:00 UTC, which lands on the European morning and the US late night.
| Model | Input | Cached input | Output | Status |
|---|---|---|---|---|
| GLM-5.4 | 4.6 | 1.1 | 16 | Reported at launch; confirm on the plan page |
| GLM-5.3 | 6.9 | 1.7 | 24 | docs.z.ai |
| GLM-5.3-Flash | 2.3 | 0.56 | 8 | docs.z.ai |
Two takeaways before writing any code. Output tokens cost roughly 3.5x input tokens and about 15x cached input, so long thinking is what drains a window, not big prompts. And cached input is cheap, which means Claude Code's habit of re-sending a stable prefix works in your favor as long as the prefix stays stable. Z.ai also raised the weekly GLM-5.4 allowance to 1.5x what GLM-5.3 got, so do not assume the old numbers transfer.
Step 3: Build the credit meter
Claude Code writes every session to a JSONL transcript under ~/.claude/projects/<project-slug>/<session-id>.jsonl. Each assistant entry carries the model name and a usage object with input_tokens, cache_creation_input_tokens, cache_read_input_tokens and output_tokens. That is everything the credit formula needs. Save this as glm_meter.py:
#!/usr/bin/env python3
"""glm_meter.py - estimate GLM Coding Plan credits from Claude Code transcripts."""
import argparse, json, sys
from datetime import datetime, timedelta, timezone
from pathlib import Path
# (input, cached_input, output) multipliers. GLM-5.3 and Flash are from docs.z.ai;
# GLM-5.4 values are as reported at launch -- check the Coding Plan overview page.
MULTIPLIERS = {
"glm-5.4": (4.6, 1.1, 16.0),
"glm-5.3": (6.9, 1.7, 24.0),
"glm-5.3-flash": (2.3, 0.56, 8.0),
}
PLANS = {"lite": 2_000, "pro": 12_000, "max": 28_000} # credits per 5-hour window
SGT = timezone(timedelta(hours=8))
def base_model(name):
name = (name or "").lower().split("[")[0] # strip "[1m]"
return name if name in MULTIPLIERS else None
def is_peak(ts):
t = ts.astimezone(SGT) # peak: Mon-Fri 14:00-18:00 SGT
return t.weekday() < 5 and 14 <= t.hour < 18
def credits(model, u, ts):
m_in, m_cache, m_out = MULTIPLIERS[model]
fresh = u.get("input_tokens", 0) + u.get("cache_creation_input_tokens", 0)
raw = (fresh * m_in + u.get("cache_read_input_tokens", 0) * m_cache
+ u.get("output_tokens", 0) * m_out) / 10_000
return raw if is_peak(ts) else raw * 0.5 # off-peak billed at 50%
def turns(paths):
seen = set()
for p in paths:
for line in p.open(encoding="utf-8"):
try:
e = json.loads(line)
except json.JSONDecodeError:
continue
msg = e.get("message") or {}
if e.get("type") != "assistant" or "usage" not in msg:
continue
mid = msg.get("id")
if mid in seen: # one API call can span several lines
continue
seen.add(mid)
model = base_model(msg.get("model"))
if not model:
continue
ts = datetime.fromisoformat(e["timestamp"].replace("Z", "+00:00"))
yield ts, model, msg["usage"], p.name
def main():
ap = argparse.ArgumentParser()
ap.add_argument("path", nargs="?", default=str(Path.home() / ".claude/projects"))
ap.add_argument("--plan", choices=PLANS, default="pro")
ap.add_argument("--hours", type=float, default=5.0)
ap.add_argument("--marathon", type=int, default=8_000, help="flag turns with more output tokens than this")
ap.add_argument("--now", help="ISO time to treat as now (for replaying old logs)")
a = ap.parse_args()
root = Path(a.path).expanduser()
files = [root] if root.is_file() else sorted(root.rglob("*.jsonl"))
now = datetime.fromisoformat(a.now) if a.now else datetime.now(timezone.utc)
since = now - timedelta(hours=a.hours)
per_model, total, flagged = {}, 0.0, []
for ts, model, u, fname in turns(files):
if ts < since:
continue
c = credits(model, u, ts)
total += c
per_model[model] = per_model.get(model, 0.0) + c
if u.get("output_tokens", 0) > a.marathon:
flagged.append((ts, model, u["output_tokens"], c, fname))
budget = PLANS[a.plan]
print(f"Window: last {a.hours:g}h plan={a.plan} ({budget:,} credits)")
for m, c in sorted(per_model.items(), key=lambda kv: -kv[1]):
print(f" {m:<14} {c:9.1f} credits")
print(f" {'TOTAL':<14} {total:9.1f} ({100 * total / budget:.1f}% of window)")
print(f" now is {'PEAK (full rate)' if is_peak(now) else 'off-peak (50% rate)'}")
for ts, m, out, c, f in flagged:
print(f" ! marathon turn {ts:%H:%M}Z {m} output={out:,} tok cost={c:.1f} ({f})")
return 1 if total > 0.8 * budget else 0
if __name__ == "__main__":
sys.exit(main())
A few design choices worth calling out. The multipliers live in one dict so you can update them the moment Z.ai changes the table. The [1m] suffix is stripped so glm-5.4[1m] and glm-5.4 count the same. Entries are de-duplicated by message ID because a single API response can be written to the transcript across several lines (one per content block), and counting each would multiply your bill on paper. Peak detection converts every timestamp to UTC+8 so the meter is correct wherever you live. Finally, the script exits with status 1 once you pass 80% of the window, which makes it usable in shell scripts and hooks.
One assumption to know about: the meter treats cache_creation_input_tokens as regular input, since Z.ai's formula only distinguishes fresh input from cached input. If your dashboard numbers disagree, that line is the first place to look.
Step 4: Run it on a real session
Here is a short session from a project called shop-api: one prompt asking GLM-5.4 to add rate limiting to an /orders endpoint, four GLM-5.4 calls, one call from a Haiku-slot helper, and a follow-up a few hours later. The transcript lines look like this (trimmed to the fields that matter):
{"type":"assistant","timestamp":"2026-11-24T06:09:05Z","message":{"id":"msg_3","model":"glm-5.4[1m]",
"usage":{"input_tokens":1200,"cache_creation_input_tokens":2800,"cache_read_input_tokens":45800,"output_tokens":14600}}}
Run the meter against the project folder on a Lite plan, replaying the log as if it were 11:00 UTC:
$ python3 glm_meter.py ~/.claude/projects/-Users-me-shop-api --plan lite --now 2026-11-24T11:00:00+00:00
Window: last 5h plan=lite (2,000 credits)
glm-5.4 68.8 credits
glm-5.3-flash 1.8 credits
TOTAL 70.6 (3.5% of window)
now is off-peak (50% rate)
! marathon turn 06:09Z glm-5.4 output=14,600 tok cost=30.2 (s1.jsonl)
That output is from an actual run of the script above. Look at the flagged turn. It is one of five GLM-5.4 calls, yet it costs 30.2 of the 68.8 credits, about 44% of the session. The math: 4,000 fresh input tokens x 4.6 = 18,400, 45,800 cached tokens x 1.1 = 50,380, and 14,600 output tokens x 16 = 233,600, for 302,380 / 10,000 = 30.2. It also ran at 06:09 UTC, which is 14:09 in Singapore, so it paid full peak rate. The same turn three hours later would have cost about 15.
Narrow the window to see only the last hour:
$ python3 glm_meter.py ~/.claude/projects/-Users-me-shop-api --plan pro --hours 1 --now 2026-11-24T11:00:00+00:00
Window: last 1h plan=pro (12,000 credits)
glm-5.4 6.1 credits
TOTAL 6.1 (0.1% of window)
now is off-peak (50% rate)
Note that the meter counts a rolling window from --now, while Z.ai resets the 5-hour allowance 5 hours after consumption. They line up closely in practice, but the Z.ai usage page is the source of truth if you are right at the edge.
Step 5: Stop paying GLM-5.4 prices for chores
Not every step of a coding session needs a 1M-context loop transformer. Searching for files, summarizing a diff, or writing a commit message are fine on GLM-5.3-Flash at half the input multiplier and half the output multiplier of GLM-5.4. Because of the settings in Step 1, any Claude Code subagent declared with model: haiku is routed to Flash. Create .claude/agents/scout.md in your project:
---
name: scout
description: Use for file search, grep, reading logs, and summarizing diffs or test output. Never for writing or editing code.
tools: Read, Grep, Glob, Bash
model: haiku
---
You are a fast research helper. Find what was asked, quote the exact lines
and file paths, and keep your answer under 200 words. Do not propose fixes.
Now when the main GLM-5.4 agent needs to look something up, it can hand that to scout and get a short answer back, instead of reading twenty files into its own expensive context and thinking about each one. Run the meter after a session with and without the subagent, and you will see the Flash line grow while the GLM-5.4 line shrinks.
Two other habits help with marathon turns. Ask for scoped work ("change only rate_limit.py, then stop") so the model has less to reason about. And schedule the big refactors outside 06:00-10:00 UTC on weekdays, since the identical request costs half as much off-peak.
Step 6: Put the meter in your status line
Claude Code can run a command to render its status line, and it passes session info as JSON on stdin, including the path to the current transcript. Save this next to the meter as glm_status.py:
#!/usr/bin/env python3
# Claude Code statusLine command: prints credits used by this session's transcript.
import json, sys
from datetime import datetime, timezone
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from glm_meter import turns, credits, is_peak
info = json.load(sys.stdin)
path = Path(info.get("transcript_path", ""))
used = sum(credits(m, u, ts) for ts, m, u, _ in turns([path])) if path.is_file() else 0.0
rate = "PEAK" if is_peak(datetime.now(timezone.utc)) else "off-peak"
print(f"GLM {used:.0f} cr this session | {rate}")
Then register it in ~/.claude/settings.json alongside the env block:
"statusLine": {
"type": "command",
"command": "python3 ~/tools/glm_status.py"
}
Testing it by hand with a fake payload:
$ echo '{"transcript_path": "/Users/me/.claude/projects/-Users-me-shop-api/s1.jsonl"}' | python3 ~/tools/glm_status.py
GLM 71 cr this session | off-peak
Now every turn shows what the session has cost so far and whether you are in the expensive window. It is a small thing, but seeing the number jump by 30 after one turn changes how you phrase the next prompt.
A worked example: deciding whether to switch a team
Say a three-person team on Pro seats is evaluating GLM-5.4 against their current GLM-5.3 setup. A sensible test looks like this. Each developer works one normal day with GLM-5.4 in the Opus and Sonnet slots. At the end of the day, run the meter over everyone's projects folder with --hours 24, and again against the previous day's GLM-5.3 sessions. Compare three numbers: total credits, credits per merged PR, and the count of flagged marathon turns.
Using the multipliers above, the same token mix is about a third cheaper per token on GLM-5.4 than on GLM-5.3 (16 vs 24 on output). So if GLM-5.4 produces more output per task because it thinks longer, it can still come out ahead or roughly even. If the marathon count is high and those turns did not produce better patches, that tells you to lean on scoped prompts and the Flash subagent before deciding the model is too expensive. This is the kind of question launch benchmarks cannot answer and your own transcripts can.
Common pitfalls
- Using a standard API key. Coding Plan and standard API keys are separate. The standard pay-as-you-go endpoint (
/api/paas/v4) does not serve GLM-5.4 yet, so a script pointed there will fail or fall back to an older model. - Wrong base URL. Claude Code needs
https://api.z.ai/api/anthropic. OpenAI-style tools usehttps://api.z.ai/api/coding/paas/v4. Z.ai warns that a wrong endpoint means your plan quota is not applied. - Building a product on your plan key. The Coding Plan is meant for supported tools. Wiring the key into a customer-facing app is outside its usage policy; wait for the Model API for that.
- Client timeouts on long turns. Default HTTP timeouts in many tools are a few minutes. At peak-hour speeds a long thinking turn can blow past that. Raise
API_TIMEOUT_MSas shown, or the request dies after you have already paid for most of it. - Counting duplicate transcript lines. If you write your own parser, de-duplicate by message ID. One response with thinking, text and a tool call can appear as several lines, each with the same usage.
- Stale multipliers. Z.ai has already revised usage tables once this year. The GLM-5.4 numbers in this guide are the launch figures; check the Coding Plan overview before trusting the meter for billing decisions.
- Breaking the cache. Cached input costs about a quarter of fresh input on GLM-5.4. Editing
CLAUDE.mdor swapping MCP servers mid-session changes the prefix and turns cheap cached tokens back into full-price ones. - Assuming benchmarks exist. Z.ai has not published GLM-5.4 scores yet. Comparisons you see on social media are either the 30B ablation or someone's personal test.
Quick reference
| Thing | Value |
|---|---|
| Model IDs (Claude Code) | glm-5.4[1m], glm-5.3-flash[1m] |
| Anthropic-compatible endpoint | https://api.z.ai/api/anthropic |
| OpenAI-compatible (Coding Plan) | https://api.z.ai/api/coding/paas/v4 |
| Credit formula | (in x m_in + cached x m_cache + out x m_out) / 10,000 |
| GLM-5.4 multipliers (launch) | 4.6 / 1.1 / 16 |
| 5-hour credits | Lite 2,000 · Pro 12,000 · Max 28,000 |
| Peak hours | Mon-Fri 14:00-18:00 UTC+8 (06:00-10:00 UTC) |
| Off-peak rate | 50% of standard |
| Transcripts | ~/.claude/projects/<slug>/<session>.jsonl |
| Cheap subagent | model: haiku in .claude/agents/*.md |
| Meter alert | exit code 1 above 80% of window |
Next steps
- Add a weekly mode to the meter (sum the last 7 days against 10,000 / 60,000 / 140,000) so you can see when you will hit the weekly wall, not just the 5-hour one.
- Call the meter from a Claude Code hook before large tasks and print a warning when it exits 1.
- Log credits per git commit by matching transcript timestamps to
git log, which gives you a real cost-per-change number for the team comparison. - When Z.ai opens the GLM-5.4 Model API, swap the credit formula for per-token dollar pricing and the same meter works for API usage.
- Read Z.ai's GLM-5.4 page and Coding Plan overview at docs.z.ai for any changes to multipliers, quotas and endpoints.
Sources: Z.ai GLM-5.4 announcement (z.ai/blog/glm-5.4), docs.z.ai GLM-5.4 model page, GLM Coding Plan overview and Claude Code setup pages, and launch coverage from TestingCatalog, i10x and Apidog on DEV.
Comments
Be the first to comment
Found this useful?
Get new AI guides for builders by email. Free.
Join 3,605 newsletter subscribers.