Skip to Content

Context: how zerd stays cheap

How zerd keeps the prompt small and stable by capping, archiving, pruning and folding old context.

The cheapest token is the one never sent. Input tokens dominate cost because every call re-sends the whole conversation, so most of zerd's savings come from keeping that prefix small and stable.

  • Small system prompt. About 3k tokens for a small-window model, 4.1k with the skill list. The skill list is capped at ~1% of the context window and shortens its descriptions to fit. Open models get a few extra rules for their known habits.
  • Prompt caching that actually hits. Claude calls cache the system prompt and the conversation prefix. The Codex backend only caches when session_id and prompt_cache_key are sent, so zerd sends both. A model that isn't caching triggers a warning, and /cost says why a miss happened (idle gap, model changed, prefix changed).
  • Incremental reads. Only new lines, or a diff since the last copy the model saw.
  • Output caps and archive. Over-broad grep collapses into a summary; every result is capped; the full text is recallable.
  • Pruning inside a task. Old results are dropped once the prompt passes 180k tokens, with a hint of what was cleared.
  • Compaction that reuses the cache. With no separate summarizer configured, the summary is asked of the same model on the exact prefix the loop just sent (system prompt, tools, older messages) plus one text-only instruction, so the provider serves it from cache and every tool result is seen whole. The trimmed copy is the fallback, and is used after an idle pause (cold cache). If the context refills within 3 turns of each of 3 compactions in a row, zerd prunes old output and stops summarising for 10 turns.
  • Thinking stays cache-stable. A model's reasoning goes back on every turn of the model that wrote it and is dropped only when the model changes, so the history only grows and the cache keeps hitting.
  • Reminders, not rewrites. Files changed on disk by something else, a todo list idle for 10 rounds, and text that looks like a tool call are flagged with a short <system-reminder> message.
  • Compaction that keeps facts. A summary with a FILES AND CODE section of verbatim snippets, every user message kept (lists and file:line whole), an errors-and-fixes section, and the replaced messages saved to transcripts/<session>.jsonl so nothing is truly lost. Terminal noise is stripped for free before the summarizer sees it.
  • Folder rules follow the model. Reading apps/web/src/a.tsx attaches apps/web/AGENTS.md once, and re-attaches it after a prune or compaction clears the result that carried it.
  • Task notes. A notes tool keeps goal, decisions, done and next on disk, so a long job survives compaction and --resume.
  • Cost-weighted accounting. Each result is weighted by how many later calls re-sent it, so /cost points at the thing worth fixing, and only shows the breakdown when it is worth acting on.
  • Persistent search index. Built once per repo, then loaded from disk.
  • Long commands go to the background. A shell command still running after 15s becomes a job (/jobs); the model is told when it finishes.
  • No stalls. A stuck stream can't outlive the request budget; a hung worker fails after 15 minutes; sub-agents have a hard timeout.