<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: peter.zeng</title>
    <description>The latest articles on DEV Community by peter.zeng (@peterzeng).</description>
    <link>https://dev.to/peterzeng</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3946166%2F53136b6e-ef27-4794-9d4b-0712ef04fa67.png</url>
      <title>DEV Community: peter.zeng</title>
      <link>https://dev.to/peterzeng</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/peterzeng"/>
    <language>en</language>
    <item>
      <title>4 Hard Lessons on Optimizing AI Coding Agents</title>
      <dc:creator>peter.zeng</dc:creator>
      <pubDate>Fri, 22 May 2026 13:44:14 +0000</pubDate>
      <link>https://dev.to/peterzeng/4-hard-lessons-on-optimizing-ai-coding-agents-4c61</link>
      <guid>https://dev.to/peterzeng/4-hard-lessons-on-optimizing-ai-coding-agents-4c61</guid>
      <description>&lt;h1&gt;
  
  
  4 Hard Lessons on Optimizing AI Coding Agents (Claude Code + Cost)
&lt;/h1&gt;

&lt;p&gt;I've been running Claude Code Cli in production for about months now—building, shipping, and watching the token meter spin. Here's what I wish I knew before I started.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Your Context Strategy Is Everything
&lt;/h2&gt;

&lt;p&gt;The developers getting 10x from Claude Code aren't prompt whisperers. They're &lt;strong&gt;context engineers&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The 2026 consensus is clear: &lt;strong&gt;CLAUDE.md is no longer optional&lt;/strong&gt;. Keep it lean. Ask yourself: "Would removing this line cause the agent to make mistakes?" If not, cut it. No one has time to scroll through 15k tokens of stale docs every session.&lt;/p&gt;

&lt;p&gt;One more &lt;code&gt;.claudeignore&lt;/code&gt; tweak took my sessions from 150k tokens to 60k—a 60% drop. The culprit? Node modules and dist folders. Block them. You can manually feed files when needed.&lt;/p&gt;

&lt;p&gt;The golden rule: &lt;strong&gt;engineer before you prompt.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The /ghost, OODA, and L99 Patterns
&lt;/h2&gt;

&lt;p&gt;Stop talking to Claude Code like it's ChatGPT. It has 40+ tools built in—most people use 3 or 4.&lt;/p&gt;

&lt;p&gt;Four prompt frameworks that actually moved the needle for me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/ghost&lt;/code&gt;&lt;/strong&gt; : Kills the AI filler voice. "It's worth noting that..." disappears. You get clean, direct prose for docs and PRs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;OODA&lt;/code&gt;&lt;/strong&gt; : Forces a concrete decision instead of "it depends." Feed it your constraints (team size, shipping cadence) and demand a plan.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;L99&lt;/code&gt;&lt;/strong&gt; : Unlocks expert depth. Instead of tutorial answers, you get production-ready patterns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;PERSONA&lt;/code&gt;&lt;/strong&gt; : Frames the response through an expert lens. "Senior AWS Solutions Architect with 10 years experience" actually works.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also: &lt;strong&gt;be direct.&lt;/strong&gt; The system prompt explicitly tells Claude Code to be terse. If you write "Hey, could you maybe take a look at..." you're working against the grain. A crisp "Fix this function" is what the agent wants.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Cost Optimization Isn't Magic—It's Math
&lt;/h2&gt;

&lt;p&gt;Let's run the numbers. A 200-call agent session on Opus with growing context can hit 4M input tokens. At $5/M, that's $20 just for input before output. A 20-developer team running 50 sessions daily? $10k+ per month.&lt;/p&gt;

&lt;p&gt;Here's where the real waste hides: &lt;strong&gt;70–85% of your tokens are input tokens.&lt;/strong&gt; And 80% of that input comes from reading project files.&lt;/p&gt;

&lt;p&gt;Three fixes that actually work:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cache your prompts.&lt;/strong&gt; Anthropic and OpenAI offer 90% and 50% discounts on cache hits. That repeated system prompt? Stop paying for it on every turn.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Skill layers slash token spend.&lt;/strong&gt; One team cut consumption from 10.4M to 3.7M tokens—$9.21 to $2.81 per session—by routing context through a reusable Skill layer. Think of it as middleware for tokens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Route by difficulty.&lt;/strong&gt; A classification model routing simple queries to Sonnet (or even Haiku for boilerplate) while reserving Opus for architectural decisions can cut 40–70% of spend with no quality loss.&lt;/p&gt;

&lt;p&gt;Don't let perfect be the enemy of cheap.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Agentic Workflows Beat Scripts
&lt;/h2&gt;

&lt;p&gt;The shift from "scripting" to "orchestration" is real. The teams shipping fastest in 2026 aren't writing prompts—they're designing workflows.&lt;/p&gt;

&lt;p&gt;Two patterns worth stealing:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TDD governance at the prompt level.&lt;/strong&gt; Encode your testing discipline into the agent's loop: write, run, observe errors, fix, repeat. With inference costs 5–10x lower than 2025, this feedback loop is now economically sane for 500-line changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Leave Opus 4.6 habits behind.&lt;/strong&gt; Opus 4.7 treats you differently. The old "fine-grained pair programming" approach backfires. Instead, specify the full task in the first turn—goals, constraints, acceptance criteria—and let the agent work. And stop defaulting to &lt;code&gt;max&lt;/code&gt; effort. &lt;code&gt;xhigh&lt;/code&gt; is the new sweet spot. &lt;code&gt;max&lt;/code&gt; overthinks and slows you down.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Bottom line:&lt;/strong&gt; Engineer your context, use prompt frameworks that drive decisions, route strategically for cost, and design workflows instead of writing scripts. The agents are ready. Your wallet (and your weekend) will thank you.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;For devs working with Chinese LLMs:&lt;/strong&gt; check out &lt;a href="https://cnllm.ai" rel="noopener noreferrer"&gt;cnllm.ai&lt;/a&gt; — An enterprise-grade gateway — replace your base_url with &lt;a href="https://cnllm.ai" rel="noopener noreferrer"&gt;https://cnllm.ai&lt;/a&gt; to seamlessly access all mainstream LLMs, including top global models like GPT, Claude, Gemini and cost-effective Chinese models like DeepSeek, Qwen, GLM, Kimi, Minimax — fully compatible with OpenAI protocol.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>agents</category>
    </item>
  </channel>
</rss>
