← Back to Insights

Insight

Rules That Run, Part 1: The 93,000-Token Hello

Ariel Agor
Updated
The cover illustration with subtle ambient motion, for "Rules That Run, Part 1: The 93,000-Token Hello".

Listen · Read by Ariel

0:00 / n/a

Rules That Run is a ten-part series on the rules that keep an AI agent setup honest. This is part 1.

I run a lot of Claude Code on one machine. Some of it is me at the keyboard, and a growing share is unattended: scheduled jobs that draft, classify, score and summarise while I sleep. Over the summer I wrote rules for all of it in instruction files, and the rules drifted. The agent followed them most days and forgot them on the days that mattered. What held was the subset I moved out of prose and into the harness, where a hook or a wrapper enforces the rule whether or not the model remembers it. This series covers ten of those rules, one a day for ten days, with enough mechanics that you can build each one yourself. Read it as the practitioner's companion to Anthropic's own page on managing Claude Code costs.

The first rule is about the cheapest-looking thing in the setup, a single unattended call.

What a plain call actually loads

On September 24, 2026 I measured what happened when a scheduled job ran claude -p "Reply OK" from inside a project folder. Before the model read my one-word request, the harness had loaded about 93,000 tokens of context. Roughly 50,000 of that was the skill listing. About 31,000 was instruction files, the global one plus the project's own. The rest was the agent listing and whatever the session-start hooks printed.

None of it was wrong. An interactive session should know what skills exist and what the house rules are. A job whose whole task is "classify this subject line" needs none of it, and it was paying for all of it on every call. At API list price, that hello cost about $1.15. The jobs run on a subscription, so the real cost was quota rather than dollars, but quota is the thing that runs out.

The Claude Code docs say it directly: "Token costs scale with context size." That sentence is easy to agree with and easy to ignore, because the context you pay for is mostly context you never see.

The seam

The fix is a wrapper every unattended call goes through. I call it the seam, because every scheduled job's model call passes through it and nowhere else. It is one Node module, and the rule is that no job spawns claude -p by hand.

The wrapper does a handful of things:

  • It runs the child process from an empty folder, so no project instruction file is in reach.
  • It loads only project-level settings and passes a strict, empty MCP config.
  • It allows no tools unless the caller names them in an allowlist.
  • It passes its own short system prompt and turns off instruction-file loading.
  • It disables session persistence and asks for JSON output, so the reply is data the job can parse.
  • It builds the child's environment from an allowlist that strips any API key, so a stray key in the parent shell cannot quietly move the call onto the metered API.

The core of the spawn looks like this:

// ~/.claude/scripts/lib/lean-call.mjs (core of the spawn)
const args = [
  '-p', '--model', modelFor(tier),
  '--output-format', 'json',
  '--setting-sources', 'project',
  '--strict-mcp-config',
  '--no-session-persistence',
  '--system-prompt', systemPrompt,
  ...(tools ? ['--tools', tools, '--allowedTools', tools] : ['--tools=']),
];
const env = pick(process.env, ENV_ALLOWLIST); // no API keys survive this
const child = spawn('claude', args, { cwd: EMPTY_DIR, env });

Measured the same day, the same "Reply OK" through the wrapper used 438 input tokens. The API-equivalent price went from about $1.15 a call to $0.0018.

The bigger win came from changing how jobs called it. One morning job, a landing-page agent, had been making 84 calls a run at about $97 in API-equivalent terms. After the wrapper, and after batching independent items into a single call, it made 7 calls for $0.18. Batching mattered as much as the wrapper. A fixed harness cost paid once per item adds up fast when the items are small.

The ledger row

Each call through the seam writes one line to a ledger: the job label, the model that actually answered, input and output tokens, cost, and status. "The model that actually answered" matters. A job can ask for one model and get another, and if you log only what you asked for you will never see it.

{"job":"<job label>","tier":"fast","model":"<model that answered>","in":"<n>","out":"<n>","usd":"<cost>","status":"ok"}

That row is how I know the seam is used and what each job costs. A rule that says "use the wrapper" can be checked against it. A rule that only lives in an instruction file cannot be checked against anything.

A limit reply is an error

Here is a failure that took me too long to see. When a subscription hits its weekly limit, claude -p replies with a polite sentence saying so. A job that reads stdout and treats it as the answer will happily store "You've hit your weekly limit" as a classification, a summary, or a draft.

On September 24, 2026 one accounting job treated 19 of those replies as answers in a single day. Nothing crashed. The data was simply wrong.

The seam now pattern-matches the limit message and throws it as an error with its own code. The caller can catch it, skip, and retry later. It can never mistake it for output. If you build one thing from this post, build that check, because it fails silently in exactly the jobs nobody is watching.

The same wrapper also carries a quota governor. When weekly usage is running ahead of the week's pace, it skips jobs marked low priority and throws a distinct "skipped" error, so background work gives way before the interactive sessions run out of room.

Models by role, never by id

The second half of the rule is about which model each job gets. Early on, jobs pinned a model id. Every new model release meant a hunt through every job for strings to change, and any job the hunt missed kept running on the old model with nothing to say so.

Now every call names a tier, and the tier names a role:

  • deep, the Opus family: judgment, planning, published writing, anything a customer reads.
  • standard, the Sonnet family: drafting, research, scoring.
  • fast, the Haiku family: classification and extraction.

A small tiers file maps each role to a family. Code that needs a concrete id calls a resolver with the tier. Nothing in a job names a model.

{
  "deep":     { "family": "opus",   "ceiling": "<max price per Mtok>" },
  "standard": { "family": "sonnet", "ceiling": "<max price per Mtok>" },
  "fast":     { "family": "haiku",  "ceiling": "<max price per Mtok>" }
}

A daily job records which concrete model each family currently serves. When that changes, it emails me. If a successor is priced above the tier's ceiling, it holds the old model back until I look. Retries stay inside the same tier, and the wrapper never downgrades silently: if the deep tier fails, the job fails and says so, instead of quietly handing a customer email to the fast model.

This is the docs' advice on choosing the right model, with the choice taken out of each call site. The docs tell a person to reserve Opus for hard reasoning. A tier file makes the same decision once, by role, for every scheduled job.

What changed

The audit of the week starting October 1, 2026 put unattended jobs at 0.6% of weekly usage. The jobs still ran on their schedules, now without an interactive session's luggage on every call.

The same audit showed where the rest of the week's usage went: the subagents in my own interactive sessions. Part 2 covers them.

Build it yourself

  1. Measure one bare claude -p call from a project folder with JSON output and read the input token count. Do the same from an empty folder with --setting-sources project and --strict-mcp-config.
  2. Write one wrapper module and make it the only place that spawns claude -p. Grep your scheduled jobs for direct spawns and move them over.
  3. Build the child's environment from an allowlist and leave every API key out of it.
  4. Pass --tools= by default and an explicit allowlist when a job needs tools.
  5. Detect the usage-limit reply and throw it as an error with its own code.
  6. Log one ledger row per call, including the model that actually answered.
  7. Replace model ids in jobs with a tier name, and keep the role-to-family mapping in one file.
  8. Batch independent items into one call wherever the job allows it.

Agor AI reviews agent setups like this one for teams running Claude Code in production.

Want this kind of automation working for your business?

Agor AI designs and ships the systems these posts describe, scoped in weeks, not quarters.

Book a Free Strategy Call