How do you keep AI coding costs down?
32 posts, 1 new this week
Playbook
Practitioners reduce AI coding costs by restricting context size, splitting work across cheaper models, and enforcing hard execution limits.
- Block large files in pre-commit hooks
Matt Pocock recommends creating a pre-commit hook that runs only on staged files and blocks any file over 5,000 tokens. The token count is estimated by dividing bytes by 4. The hook skips lockfiles and generated code, and its error message explains how to split the file. 1
- Trim rule files and set compaction windows
Rodrigo Nask cut global CLAUDE.md and skill descriptions from 97,935 to 16,830 characters, moving details into reference files. He set the auto-compaction window to 500k. Over 262,289 calls, median cost per task fell from $2.57 to $1.06, though daily usage rose 46%. 2
- Raise clear-and-handoff threshold based on quota weights
Alex Slobodianiuk measured Opus 5 quota weights, finding output weighs about 850 times as much as a cache read with a 15% error margin. Recalculating from 31 days of logs, he raised the clear-and-handoff threshold from 200k to 300k tokens and let auto-compaction take over. 3
- Split models by task phase
Alex Finn proposes using Fable 5.2 for planning and brainstorming, then switching to Opus 5.5 to execute tasks one by one. Sonnet or Haiku sub-agents are used to run tests. This detailed upfront planning aims to cut token use during execution. 4
- Enforce hard limits on execution windows and reads
Dean Bogdanovic reports that instead of relying on prompts, the team switched to execution windows, intervals between cycles, and read limits. This approach addressed an agent that burned roughly 500 million cached input tokens, costing about $1000, out of total project spending of about $3900. 6
- Mine session logs to target high-cost areas
Craig Merry analyzed 2,914 local session files after hitting weekly limits. Of 9.5 billion tokens, 96% were cache reads and 98% of cost landed on Opus 5.5. Adjustments include stopping rounds based on review evidence, trying Sonnet for mechanical steps, shrinking file loads, and compressing early at about 450,000 tokens. 8
Choosing between approaches
Reducing context size and using cheaper models can increase daily usage or require more frequent handoffs. For instance, cutting rule files led to a 46% rise in daily usage 2, and raising the clear-and-handoff threshold relies on specific quota weight measurements that may have errors 3. Additionally, newer models like Fable 5.2 may offset price cuts with higher token consumption 10.
Not covered yet
The material lacks data on the long-term impact of multi-model workflows on code quality and maintenance, as well as standardized benchmarks for comparing cost-effectiveness across different project scales.
Posts
- Ask AI for a pre-commit hook that blocks files over 5,000 tokens on staged files onlyIn his prompt of the day, Matt Pocock asks AI to create a pre-commit hook that runs only on staged files and blocks any file over 5,000 tokens, estimated as bytes divided by 4.
- Cut rule files from 97,935 to 16,830 characters and set auto-compaction to 500kThe author cut the global CLAUDE.md and skill descriptions from 97,935 to 16,830 characters, moved details into reference files, and set the auto-compaction window to 500k, then measured over 262,289 calls.

- After measuring quota weights, raise the clear-and-handoff threshold from 200k to 300k tokensThe author used to write a handoff file and run /clear at 200 thousand tokens of context, about 14 times a day.

- Plan with Fable 5.2, execute with Opus 5.5, and test with Sonnet or Haiku sub-agentsThe author proposes a multi-model workflow: use Fable 5.2 for all planning and brainstorming, refine ideas into a detailed task list written into a task manager, then switch to Opus 5.5 to execute the tasks one by one, and have Sonnet or Haiku sub-agents run the tests.
- Track cost, throughput and quality per pull request in a software factory, cutting cost to $15-20Warp CEO Zach Lloyd presents a software factory that turns tasks into pull requests, demoing the full path from a Slack request to a pull request and tracking cost, throughput and quality for each one.

- Control agent cost with hard limits on execution windows and reads, not promptsQuEra's engineering lead reports that AI spending on two projects came to about $3900, and one review agent that kept rereading the project burned roughly 500 million cached input tokens, about $1000.

- Try Opus 5.5 only on the primary agent and DeepSeek Flash on all sub-agentsThe author's team is experimenting this week with a model split: all sub-agents switched to DeepSeek Flash, with Opus 5.5 used only on the primary agent.
- Mine your own session logs to see where weekly limits went, then cut turns and file loadingAfter hitting the weekly limit twice in one week, the author read 2,914 local session files and counted: of 9.5 billion tokens, 96% were cache reads, and 98% of cost landed on Opus 5.5.

- Pick models by token billing: ask mode to explore, strong model to plan, Composer to buildA Cursor workshop explains that billing follows input, output and cache reads and writes, not agent actions.

- Fable 5.2 token usage offsets 20% price cutAddy Osmani reports that Fable 5.2 consumes significantly more tokens than Fable 5.1.
- Rerun token optimizers on real bug-fix tasks: only 9 of 79 configurations survived
- Validate AI investment impact through a seven-step framework
- Run Claude Code on free Kimi K3 through a local LiteLLM translator and NVIDIA NIM
22 more posts to see