Skip to content
SearchSubscribe
Expert · Lesson 17 — Programmatic cost ceiling enforcement
E17Expert
Expert · Lesson 17● live

Programmatic cost ceiling enforcement

Hooks, statusline, and a kill-switch script. The complete stack for enforcing spending ceilings on agentic AI work — not just tracking them.

20 min read · 90 min applyprereq: Operating 04 (hooks) · Expert 03 (token spend)

The difference between tracking and enforcing

TruPath's out-of-pocket AI spend reached $438.58 by April 13, 2026 — Claude subscriptions $300, OpenRouter $15.37, productive GPU $28.56, wasted GPU $90.66, RunPod $3.99. Anthropic estimated compute on top: $1,040. Total across both: roughly $1,480 in under four months across three ventures.

The $90.66 wasted GPU is the number that matters most. It represents 45% of total GPU spend. Every dollar of it was spent on training runs that produced no committed output — abandoned experiments, exploratory runs, hypothesis tests that didn't pan out. Each individual run seemed worth trying at the time. The accumulated cost only became visible at month end.

Tracking that waste is useful. Preventing it requires enforcement. Tracking tells you what happened. Enforcement changes what happens next. The enforcement stack — a pre-commitment gate before expensive GPU runs, a model-tier routing rule in CLAUDE.md, a PostToolUse hook that shows current burn, and a Sunday-night kill-switch. converts the ceiling from a monitoring exercise into a structural constraint.

Where spend goes wrong

AI spending has three distinct waste categories, each requiring a different intervention.

Waste categoryMechanismEnforcement lever
Model tier mismatchUsing Opus for tasks Sonnet handles; Sonnet for tasks Haiku handles. Multiplies cost 3-10x for equivalent output.Routing rule in CLAUDE.md; default to Sonnet
Uncommitted GPU runsTraining experiments that produce no committed output. Cost arrives regardless of whether output ships.Pre-commitment gate before runs over threshold
Idle context daysSessions consuming tokens on context management, re-reading files, re-orienting — not productive work.Session restart hygiene; context window monitoring

The TruPath cost structure shows all three: the $300 Claude subscription plus $1,040 estimated compute suggests potential model tier mismatch on high-volume sessions; the $90.66 wasted GPU is pure uncommitted-run waste; and context drift is the invisible category — it doesn't appear in the invoice but shows up as sessions that take twice as long to produce half the output.

The enforcement stack

Layer 1: Model-tier routing rule

The highest-advantage intervention for subscription and API spend. A three-line routing rule in CLAUDE.md reduces Opus usage to the tasks it's actually justified for and moves drafting, research, and standard coding to Sonnet.

For TruPath specifically: Opus is justified for AXIOM sessions doing multi-file architecture reasoning across the QC codebase, CIPHER sessions doing claim structure work for the provisional patent, and any session producing investor or partner materials requiring high accuracy. Sonnet handles the majority of work: SUMMIT sessions on the SBA packet, VELOCITY sessions on business strategy, AXIOM sessions on single-component debugging, all drafting and editing. Haiku handles: quick reformatting, single-file edits, short Q&A with known answers, changelog generation.

The routing rule doesn't need to be perfect. Moving 50% of current Opus sessions to Sonnet produces roughly two-thirds cost reduction on those sessions. That compounds over months.

Layer 2: Pre-commitment gate for GPU runs

The intervention for the $90.66 wasted GPU problem. Any training run estimated at over $10 requires a one-paragraph pre-commitment before it starts: hypothesis, success signal, failure signal, hard cancel condition.

The hard cancel condition is the critical element. "Cancel if validation loss doesn't improve for 3 epochs" is a hard cancel condition. "Cancel if it doesn't look promising" is not — "promising" is redefined in the moment of a running experiment. The condition must be specific and measurable, written before the run starts.

The gate adds 5 minutes per qualifying run. The QC training history (an on-device language model tuned across multiple runs; the production detector reaching v15 after a series of experiments) suggests roughly 2-3 qualifying runs per month. That's 10-15 minutes of gate time preventing the equivalent of 2-3 abandoned experiments at $15-30 each.

Layer 3: PostToolUse hook + statusline

The mechanism that makes current burn visible at session time, not month end. A PostToolUse hook logs estimated token usage per tool call to a running daily total. The statusline (a prompt suffix or terminal indicator) shows the current day's burn and the month-to-date total against ceiling.

The hook doesn't require exact pricing data — it works from token counts, which are available in the Claude Code session. Multiply tokens by the current model's per-token rate for an estimate. The estimate doesn't need to be precise; it needs to be visible.

Layer 4: Sunday-night kill-switch

A weekly ritual: run the kill-switch script to see where the month stands against ceiling. The script reads the cost log, calculates percentage used, and creates a block file if the ceiling is hit. The block file is checked by a SessionStart hook — if it exists, the hook surfaces a warning at the start of any new session.

The block file is a friction mechanism, not a hard block. A hard block would be disabled. A friction-adding mechanism that requires deliberate override persists because the cost of overriding it — deleting a file. is low enough to allow legitimate work but high enough to make the ceiling breach visible at the moment of decision.

Three failure patterns

The ways cost ceilings fail to produce cost control. All three are structural failures, not discipline failures.

№ 01

The tracking-without-enforcement gap

claim looks like“An operator sets a $200/month ceiling and tracks spend in a spreadsheet. Month one: $198. Month two: $247. The spreadsheet shows the overage. The operator notes it, plans to 'be more careful.' Month three: $289. The ceiling was a wish, not a mechanism.”
what’s missingEnforcement at the system level. Tracking tells you what happened. Enforcement changes what happens next. A ceiling without a mechanism is a preference. The distinction: tracking is retrospective; enforcement is prospective.
the moveEvery spending ceiling needs a corresponding enforcement mechanism: a hook that fires when spend reaches 80% of ceiling, a statusline that makes current burn visible at all times, and a kill-switch script that terminates new sessions when ceiling is hit. The spreadsheet is a log, not a mechanism. The hook is a mechanism.
№ 02

GPU waste from uncommitted training runs

claim looks like“A researcher runs six experimental training runs over a weekend. Three produce interesting results and are committed to the project. Three are abandoned. The abandoned runs cost $30.22 in GPU compute. At the end of the month, total wasted GPU cost is $90.66 — 45% of total GPU spend. The waste wasn't intentional; each abandoned run seemed worth trying at the time.”
what’s missingA pre-commitment gate before GPU runs over a defined cost threshold. 'Seems worth trying' is not a gate. A gate requires: what's the hypothesis, what does a success look like, what does a failure look like, how long should this run before I cancel if it's not working? Without a gate, the bar for starting a run is low and the bar for canceling a running experiment is also low — but the bill for both arrives.
the moveDefine a GPU cost threshold (e.g., $10). Any training run estimated to exceed that threshold requires a one-paragraph pre-commitment: hypothesis, success signal, failure signal, hard cancel condition (e.g., 'val loss doesn't improve for 3 epochs'). Runs below the threshold: informal. Runs above: pre-commitment required. This adds 5 minutes before a run and prevents $30+ of waste per abandoned experiment.
№ 03

Model tier mismatch

claim looks like“An operator uses Opus (highest-cost model) for all sessions by default. Monthly invoice: $340. An audit finds that 60% of sessions were drafting tasks (writing, editing, summarizing) — tasks where Sonnet performs equivalently at one-third the cost. An additional 20% were simple lookups and reformatting — tasks Haiku handles at one-tenth the cost. Effective overspend from tier mismatch: $220+/month.”
what’s missingA model-tier routing rule in the CLAUDE.md. Without a routing rule, sessions default to the highest-tier model regardless of task complexity. The routing rule doesn't require perfect classification — even a rough heuristic (Opus for multi-file reasoning, Sonnet for drafting, Haiku for lookups) captures most of the savings.
the moveAdd an explicit model-tier routing rule to CLAUDE.md. Three-tier heuristic: Opus for tasks requiring multi-file codebase reasoning, deep synthesis, or high-stakes decision support; Sonnet for drafting, editing, structured research, standard coding; Haiku for lookups, reformatting, single-file edits, quick Q&A. Log model used per session for one month. If the distribution matches the routing rule, savings are real. If not, adjust the rule.

All three failures share the same structure: a ceiling that exists in a tracking system rather than in the execution environment. The enforcement stack moves the ceiling from the spreadsheet into the session, the hook, and the pre-commitment gate.

The waste ratio check

Run this monthly, on the Sunday before the new month, as part of the kill-switch ritual. It takes 10 minutes and identifies the highest-advantage intervention for next month.

Waste ratio check
Run a waste ratio check on this period's AI spending.

Period: [month and year]
Total AI spend: $[N]

Break down into:
- Claude/API subscription spend: $[N]
- Productive GPU (training runs with committed output): $[N]
- Wasted GPU (training runs abandoned or uncommitted): $[N]
- Other (tools, APIs, compute): $[N]

For each category:
1. WASTE RATIO: (wasted cost / total cost in category) × 100
2. HIGHEST-LEVERAGE INTERVENTION: What one change would
   reduce waste in this category by the most?
3. GATE NEEDED: Is there a pre-commitment or routing
   rule that would have prevented this waste?

Output: waste ratio by category + the top intervention
per category + a draft gate rule for the highest-waste
category.

Calculates waste ratio by category and identifies the highest-leverage intervention. Run monthly as part of the Sunday-night kill-switch ritual.

Annotated transcript

Building the enforcement stack from TruPath's actual cost breakdown. Two turns — one on the overall stack, one on the specific kill-switch script. Real numbers produce concrete interventions.

Building cost ceiling enforcement from the TruPath spend breakdown

Two operator turns, two agent turns. Result: three enforcement mechanisms targeting each waste category, kill-switch script with friction-not-block design.

  1. operator

    TruPath's out-of-pocket AI spend was $438.58 as of April 13 — Claude subscriptions $300, OpenRouter $15.37, productive GPU $28.56, wasted GPU $90.66, RunPod $3.99. Anthropic compute on top of that was estimated at $1,040. How do I turn the ceiling into enforcement instead of tracking?

  2. agent

    Three mechanisms, each targeting a different waste category from your numbers:

    Mechanism 1 — Session hook for Claude spend. A PostToolUse hook that reads the current session token count and fires a warning when you hit 80% of your monthly ceiling. At 100%, it outputs a CEILING HIT banner and suggests a forced session end. This doesn't terminate the session automatically — that's too aggressive — but it makes the cost visible at the moment of spending, not at month end. The hook writes to a running log file (~/.trupath-cost-log.json) that accumulates daily totals.

    Mechanism 2 — GPU pre-commitment gate. Your $90.66 wasted GPU represents 45% of your total GPU spend. That's the highest-leverage waste category. Any training run I estimate at over $10 requires a one-paragraph pre-commitment from you: hypothesis, success signal, failure signal, hard cancel condition. Runs under $10 are informal. This gate adds 5 minutes before a run and prevents the incremental 'worth a try' experiment that costs $30 and produces nothing committable.

    Mechanism 3 — Model-tier routing rule in CLAUDE.md. Your $300/month Claude subscription plus $1,040 Anthropic compute suggests consistent use of high-tier models. Add three routing rules: Opus for multi-file architecture reasoning and investor/partner work; Sonnet for drafting, editing, research, standard coding (this is the workhorse — most QC and MHG work lives here); Haiku for lookups, quick edits, single-file reformatting. Review the rules monthly and adjust based on task distribution.

  3. operator

    What should the kill-switch script look like? I want something I can run on Sunday nights to check where I am against ceiling and block new sessions if I'm over.

  4. agent

    Here's the Sunday-night kill-switch pattern:

    #!/bin/bash
    # trupath-cost-check.sh — Sunday night ceiling check
    # Usage: bash trupath-cost-check.sh
    
    CEILING=200  # monthly ceiling in USD
    LOG=~/.trupath-cost-log.json
    
    # Pull current month's spend from log
    CURRENT=$(jq '[.[] | select(.month == "'$(date +%Y-%m)'") | .cost] | add // 0' $LOG)
    
    PCT=$(echo "$CURRENT $CEILING" | awk '{printf "%.0f", ($1/$2)*100}')
    
    echo "=== TruPath Cost Check — $(date) ==="
    echo "Current month spend: \$$CURRENT"
    echo "Ceiling: \$$CEILING"
    echo "Used: $PCT%"
    
    if [ "$PCT" -ge 100 ]; then
      echo "CEILING HIT — Writing block file"
      touch ~/.trupath-cost-blocked
      echo "New sessions blocked until ceiling resets."
    elif [ "$PCT" -ge 80 ]; then
      echo "WARNING: 80%+ of ceiling consumed."
      echo "Review spend before starting new sessions."
    fi

    The block file (~/.trupath-cost-blocked) is checked by a SessionStart hook. If the file exists, the hook outputs a warning at the start of any new session. This doesn't prevent you from starting sessions — you can delete the file — but it makes the ceiling breach visible at the moment of starting work, not retrospectively.

    Two additions for the Sunday ritual: (1) review the task log for sessions that didn't produce a committed artifact — those are your waste candidates; (2) run the GPU pre-commitment audit — any GPU run from the past week that cost more than $10 and produced nothing committed is a waste event to log and learn from.

Cost ceiling runbook

The complete enforcement runbook. Walk it weekly (kill-switch) and monthly (waste ratio check). Each item is a mechanism, not a reminder.

COST CEILING ENFORCEMENT RUNBOOK

CLAUDE.md RULES (set once, review quarterly)
[ ] Model-tier routing rule:
    - Opus: [your Opus conditions — keep short, be specific]
    - Sonnet: [your default — most work lives here]
    - Haiku: [lookups, reformatting, quick edits]
[ ] GPU pre-commitment threshold: $[N]
    (any run above this requires pre-commitment)
[ ] Compliance trigger: if monthly spend > ceiling,
    review before starting new sessions

HOOKS (set once, verify monthly)
[ ] PostToolUse: logs estimated token count per call
    to ~/.trupath-cost-log.json (or equivalent)
[ ] SessionStart: checks for ~/.trupath-cost-blocked;
    if present, outputs ceiling warning before session starts
[ ] Pre-commit: for GPU runs over threshold, checks
    for pre-commitment file before allowing esptool/
    training script execution

WEEKLY (Sunday night — 5 minutes)
[ ] Run trupath-cost-check.sh
[ ] Review current month % vs ceiling
[ ] If >= 80%: no new exploratory GPU runs this week
[ ] If >= 100%: cost blocked — review before override
[ ] Review past week's sessions for uncommitted output
    (sessions that consumed tokens but produced no artifact)

MONTHLY (first Sunday of month — 15 minutes)
[ ] Run waste ratio check prompt
[ ] Calculate: wasted GPU cost / total GPU spend
[ ] Calculate: Opus sessions that could have been Sonnet
[ ] Identify highest-leverage intervention for next month
[ ] Update routing rule if task distribution has changed
[ ] Log results in: cost-log/YYYY-MM-audit.md

PRE-COMMITMENT GATE (before any qualifying GPU run)
[ ] Hypothesis: [one sentence — specific, testable]
[ ] Success signal: [metric + threshold]
[ ] Failure signal: [the condition that proves it wrong]
[ ] Hard cancel: [specific, measurable cancel condition]
[ ] Estimated cost: $[N] and duration: [N hours]
[ ] Log: save as precommit/YYYY-MM-DD-[experiment].md

Prompt kit

Three prompts: waste ratio check, model-tier routing rule, and GPU pre-commitment gate. Save in your CLAUDE.md cost section.

Waste ratio check
Run a waste ratio check on this period's AI spending.

Period: [month and year]
Total AI spend: $[N]

Break down into:
- Claude/API subscription spend: $[N]
- Productive GPU (training runs with committed output): $[N]
- Wasted GPU (training runs abandoned or uncommitted): $[N]
- Other (tools, APIs, compute): $[N]

For each category:
1. WASTE RATIO: (wasted cost / total cost in category) × 100
2. HIGHEST-LEVERAGE INTERVENTION: What one change would
   reduce waste in this category by the most?
3. GATE NEEDED: Is there a pre-commitment or routing
   rule that would have prevented this waste?

Output: waste ratio by category + the top intervention
per category + a draft gate rule for the highest-waste
category.
Write a model-tier routing rule
Write a model-tier routing rule for my CLAUDE.md.

My work types (describe the tasks I do most frequently):
[e.g., firmware debugging, SBA document drafting,
  patent claim writing, marketing copy, research, etc.]

For each work type, assign a model tier:
- Opus: [conditions — when is the highest tier justified?]
- Sonnet: [conditions — the workhorse tier]
- Haiku: [conditions — simple, fast, cheap tasks]

Rules for the routing rule:
- Default tier should be Sonnet (not Opus)
- Opus is reserved for: multi-file reasoning across a
  large codebase, high-stakes decisions, investor or
  partner materials
- Haiku handles: lookups, reformatting, single-file
  edits, quick Q&A with known answers

Output: a 5-10 line model-tier routing rule, formatted
for insertion directly into CLAUDE.md.
GPU pre-commitment gate
Write a pre-commitment statement for this training run.

Experiment: [describe what you're training or fine-tuning]
Estimated cost: $[N]
Estimated duration: [N hours]

The pre-commitment must answer:
1. HYPOTHESIS: What do you expect this run to produce?
   (not "see what happens" — a specific, testable claim)
2. SUCCESS SIGNAL: What result would confirm the
   hypothesis? (specific metric, threshold, behavior)
3. FAILURE SIGNAL: What result would disconfirm it?
   (the condition under which you would NOT commit
   the output)
4. HARD CANCEL CONDITION: At what point do you cancel
   a running experiment before it finishes?
   (e.g., "val loss doesn't improve for 3 epochs",
   "run exceeds $15 with no success signal")

Output: the one-paragraph pre-commitment statement,
ready to log before the run starts.

Apply this — build your enforcement stack

~90-minute setup. Routing rule, gate, hook, kill-switch. Build all four before next month starts.

Your cost ceiling enforcement stack

Each mechanism takes 15-20 minutes to set up. Progress saves automatically.

0/5
  1. 01Run the waste ratio check on last month's AI spending. Calculate waste ratio by category.If you don't have category-level data yet, estimate. Even a rough breakdown (productive vs wasted vs subscription) identifies the highest-leverage intervention.
  2. 02Add a model-tier routing rule to your CLAUDE.md. Default to Sonnet, not Opus.The routing rule doesn't need to be perfect. A rough heuristic that reduces Opus usage by 50% on drafting tasks saves more than a perfect rule that takes three sessions to write.
  3. 03Write the Sunday-night kill-switch script for your current ceiling. Test that it reads from your cost log and creates the block file correctly.The script is only valuable if it runs consistently. Add it to your calendar: every Sunday, 5 minutes.
  4. 04For your next GPU training run (if applicable): write a pre-commitment before you start. Include the hard cancel condition.The hard cancel condition is the most important part. Without it, you'll let a bad run continue because 'it might turn around.' The condition converts a judgment call into a rule.
  5. 05Review last month's GPU runs. For any run that cost more than $10 and produced no committed output: write a one-paragraph waste postmortem. What was the pre-commitment? What was missing?The waste postmortem is not self-punishment — it's calibration. Most waste events have a pattern: 'I thought it would work because X but Y happened.' That pattern becomes the next pre-commitment gate.
Expert tier · what's next

After this lesson