Engineering the zamn Claude Code skill for efficiency
zamn files are a fifth to a third shorter than the HTML Claude writes, but Claude has to read the rules before it writes any, and it thinks longer before writing a language it knows only from them. A dozen setups of the Claude Code skill later, a chat in zamn costs around 6% more than the same chat in HTML. In 140 chats, Claude never left a zamn file that didn't compile.
How it was measured
Claude Code (claude-opus-5-5, default effort, 2.1.319) writes six pages, a landing page, an article and four Vue components, then edits each six times, all in one chat per page. Every setup ran each chat twice. Each step's file is checked: it must compile, and hold the text the prompt asked for.
The comparison is in dollars, at the list prices Claude Code reports, because token types are priced very differently. Most of what a model call reads is the conversation so far, served from a cache at 0.05× the price of fresh input. What is new is written to the cache once at 2×, and output, thinking included, costs 5×. A skill is paid for mostly when it is written to the cache, and every later call reads it again.
Results
Cost of the six chats, against HTML with the same tools, lowest overhead first. A real Claude Code session always has Bash, and Bash's description costs about 6% on its own, so the setups with Bash are compared with HTML with Bash ($1.167), and the others with plain HTML ($1.096).
The first skill was generated by Claude from the docs. The shortened one is that skill with the Prettier step, converting HTML and a rationale cut (−14%); from it on, the hook reports warnings as well as errors. The shipped skill was refactored by hand: its rules reordered as a template reads, and a few clauses cut.
| Skill | Checks | The skill's check step | Cost | vs HTML |
|---|---|---|---|---|
| shipped (manually refactored) | hook, Bash zamn | "you can run zamn --validate yourself, but there is no need: the hook has already checked the file" | $1.240 | +6% |
| generated by Claude | hook, Bash zamn | "you can run zamn --validate yourself as well, but the hook has already checked the file" | $1.272 | +9% |
| generated by Claude, shortened | hook, Bash zamn | the same | $1.288 | +10% |
| generated by Claude, shortened | hook | a hook validates every write, "no extra validation is needed: write the file in one go" | $1.212 | +11% |
| generated by Claude | hook | the same | $1.233 | +12% |
| generated by Claude | hook | a hook validates every write | $1.242 | +13% |
| generated by Claude, shortened | hook, Bash zamn | as at +9%, and "if the project has no hook, run zamn --validate once, after the last change" | $1.351 | +16% |
| generated by Claude | none | run zamn --validate, with no way to run it | $1.304 | +19% |
| generated by Claude | Bash zamn | check with zamn --validate | $1.459 | +25% |
| generated by Claude, shortened | hook, Bash zamn | none | $1.492 | +28% |
What made the difference
The skill is the largest cost. Loading it puts its text in the conversation, where it is written to the cache once and read by every later call. That is about two thirds of the hook setup's extra cost; cutting the skill by 14% took a point or two off.
Claude thinks two to three times as much as for HTML, while composing the page. Recorded per model call, nearly all of it is in the call that writes the file, before the Write: about 3,100 thinking tokens over the six pages with the skill and the hook, against about 1,000 for HTML. Three wordings of the hook step left it where it was, and with no way to check at all it was about the same (3,400). Thinking is a smaller cost than the skill, though: about $0.05 of the hook setup's $0.15.
Told it can run zamn, Claude thinks less before it writes. With Bash zamn and no hook, thinking fell by about half, to 1,700–2,000 tokens, and the drop is in the call that writes the file. Claude doesn't move the thinking to after the check: it writes the draft sooner and lets the compiler find the mistakes, as a programmer would. With the hook and Bash it fell by about a fifth, to 2,400, although Claude never ran zamn in those chats, and the shipped skill, which says there is no need to, thought least of the hook setups (2,100). What does it is being told, not the tool or the check. HTML with Bash thought no less than HTML. A hook, which the skill says checks every write, left thinking as it was. With Bash zamn but a skill that says nothing of a check, Claude thought as much as with no check (3,100): it found zamn only by looking for it, and then ran it 42 times. The likeliest reading is that Claude goes over the rules in its head unless it knows it can check its work itself, even when it then doesn't.
A check names the files and prints nothing when they are valid. At first zamn compiled one template to HTML on stdout and couldn't read a .vue file. To check zamn that wasn't in a .zamn file of its own, a component's template or an answer, Claude had to pipe it into zamn, which means writing the template a second time as output, the most expensive token type, and the HTML came back into the conversation. Checking roughly doubled what Claude wrote for a page. So zamn --validate takes the paths of the files Claude has already written, several at once: .zamn files, and the <template lang="zamn"> of a .vue file where it is. It prints only errors and warnings. A check is now a command of a few dozen tokens, and a valid file returns nothing. The hook runs the same check.
Every check Claude runs costs more than the thinking it saves. A zamn --validate is a tool call of about 100 output tokens, and its call and result stay in the conversation, read again by every later call. With Bash zamn and no hook, that made the setup one of the most expensive. The hook checks for nothing: a valid file adds nothing to the conversation.
The check step is what keeps Claude from checking. A hook that passes says nothing, so Claude can't tell whether there is one. Told that the hook has already checked every write, it left the check to the hook, and ran zamn in 1 chat of 12. Given a fallback for a missing hook, it checked to be safe, in 8 of 12. Told nothing, it went looking for a way to check (which zamn, zamn --help) and ran zamn after most steps, in 10 of 12.
What shipped
The skill and zamn --hook, a PostToolUse hook in .claude/settings.json that validates every .zamn file Claude writes or edits, and the zamn template of every .vue file. It is silent when the file is valid, and reports errors and warnings, each with a code and a hint. The skill says Claude may run zamn --validate, but has no need to: the hook has already checked every write. The refactored skill came in 4 points under the shortened skill it replaced, but was cheaper in only half of the run-against-run comparisons, so the two are tied. It has no fallback: it expects the hook, and the agent rules, for agents without one, keep zamn --validate.
In all 140 chats the hook reported one problem, a line indented as if it were nested, and Claude fixed it in the same step.
Caveats
- Two runs per setup. The six-page cost of the same setup differed by 2.5% between its runs on average, and by up to 7%, so setups a point or two apart are tied.
- One model, at one effort, in one version of Claude Code, on six pages.
- The costs are list prices. Whether a subscription's usage limits weigh token types the same way isn't published.
Measure it yourself
More benchmarking and investigation are welcome: other models and efforts, more runs, other pages, other wordings of the skill. bun run docs:chats in the repository runs the chats on whatever Claude Code is logged in with, the pages and their edits are in docs/token-corpus/chats.yaml, and the measurements so far are in NOTES.md. Results, and setups that cost less, are welcome as issues or pull requests.
