<?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: ~K¹yle Million</title>
    <description>The latest articles on DEV Community by ~K¹yle Million (@thebrierfox).</description>
    <link>https://dev.to/thebrierfox</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3780351%2F132696e0-9432-47c1-87d0-bc907e039420.jpeg</url>
      <title>DEV Community: ~K¹yle Million</title>
      <link>https://dev.to/thebrierfox</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thebrierfox"/>
    <language>en</language>
    <item>
      <title>Let your AI agent pay for data inline with x402 — no API keys, and now no wallet required</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Sun, 21 Jun 2026 19:48:11 +0000</pubDate>
      <link>https://dev.to/thebrierfox/let-your-ai-agent-pay-for-data-inline-with-x402-no-api-keys-and-now-no-wallet-required-134n</link>
      <guid>https://dev.to/thebrierfox/let-your-ai-agent-pay-for-data-inline-with-x402-no-api-keys-and-now-no-wallet-required-134n</guid>
      <description>&lt;p&gt;Autonomous agents need live data, but the human billing model — sign up, get an API key, put a card on file, babysit rate limits — doesn't fit software that discovers a tool mid-task and decides for itself whether a fraction of a cent is worth it.&lt;/p&gt;

&lt;p&gt;x402 (the old HTTP &lt;code&gt;402 Payment Required&lt;/code&gt;, revived for agents and now governed under the Linux Foundation's x402 Foundation) makes payment a native part of the request: your agent calls an endpoint, gets a 402 describing &lt;em&gt;exactly&lt;/em&gt; what to pay, settles a USDC micro-payment on Base, and gets the data back. No account. No key. No human in the loop.&lt;/p&gt;

&lt;p&gt;This is a practical, copy-pasteable guide to &lt;strong&gt;consuming&lt;/strong&gt; x402 data from an agent today, using a live 210-capability service — &lt;strong&gt;The Stall&lt;/strong&gt; — as the example provider. (Disclosure: I build and operate it.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Wire it into your MCP client (the easiest path)
&lt;/h2&gt;

&lt;p&gt;If you use Claude Code, Claude Desktop, or Cursor, add one MCP server and every capability mounts as a tool — no API key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"the-stall"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://the-stall.intuitek.ai/mcp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"transport"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"streamable-http"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. Your agent can now call 210 data tools — equities, crypto/DeFi, on-chain analytics, macro, news, web/OSINT, compliance — and pay per call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Or call it directly over HTTP
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET https://the-stall.intuitek.ai/cap/us-stock-price?ticker=AAPL
  → 402 Payment Required   (body states scheme, network, asset, amount, payTo)
  → retry with the X-PAYMENT header (signed EIP-3009 USDC authorization)
  → 200 OK + data
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything you need to introspect is free and unauthenticated: &lt;code&gt;/health&lt;/code&gt;, &lt;code&gt;/catalog&lt;/code&gt; (every capability with its schema and price), and &lt;code&gt;/llms.txt&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  New: no crypto wallet? Pay by card.
&lt;/h2&gt;

&lt;p&gt;Not every builder wants to fund a Base wallet just to try a service. So there's now a &lt;strong&gt;fiat rail alongside x402&lt;/strong&gt; — buy prepaid credits with a card once, then call any capability with a bearer token: no wallet, no gas, no per-call signing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /v1/fiat/checkout   {"bundle":"starter"}      → returns a Stripe checkout URL
# after paying:
GET  /v1/fiat/token?session_id=...                 → returns your bearer token
GET  /cap/&amp;lt;name&amp;gt;   Authorization: Bearer &amp;lt;token&amp;gt;   → 200 OK + data  (1 credit/call)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bundles: &lt;strong&gt;starter $5 / 100 calls · pro $30 / 1,000 · scale $200 / 10,000.&lt;/strong&gt; Same 210 capabilities, a card instead of a wallet.&lt;/p&gt;

&lt;h2&gt;
  
  
  A recurring use-case worth calling out: counterparty risk
&lt;/h2&gt;

&lt;p&gt;If your agent pays other agents, you have to screen &lt;em&gt;who&lt;/em&gt; you pay — continuously. That's a subscription, not a one-off. One USDC payment opens a window; then you screen unlimited Base addresses for the life of it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /v1/subscribe/risk-retainer-30d   ($25, 30-day window)   → capability token
GET  /v1/risk/{address}   Authorization: Bearer &amp;lt;token&amp;gt;       → { score, band, factors }
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(There's a 7-day window at $10 too.) Scores come from live on-chain data — concentration, wallet age, transaction-graph diversity, exposure to flagged addresses.&lt;/p&gt;

&lt;h2&gt;
  
  
  An honest note on the market
&lt;/h2&gt;

&lt;p&gt;The agent-payments space is young and noisy. Independent analysts (Artemis) estimate a large share of x402 volume is wash or test traffic, and total volume has swung wildly cycle to cycle. So I don't optimize for leaderboard rankings — the only signal worth trusting is &lt;strong&gt;settlement-logged, on-chain-verified demand&lt;/strong&gt;: a real party deciding, with its own money, that a capability was worth it. If you're building agents that spend, that's the bar worth holding for the services you consume, too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Live catalog (free to browse): &lt;a href="https://the-stall.intuitek.ai/catalog" rel="noopener noreferrer"&gt;https://the-stall.intuitek.ai/catalog&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Service: &lt;a href="https://the-stall.intuitek.ai" rel="noopener noreferrer"&gt;https://the-stall.intuitek.ai&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Client library: &lt;code&gt;x402-toolkit&lt;/code&gt; on npm&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're building an agent that needs data it can pay for inline, the MCP config above is a 30-second start. Happy to answer x402 integration questions in the comments.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>x402</category>
      <category>mcp</category>
    </item>
    <item>
      <title>How to add x402 pay-per-call data tools to your Claude Code agent — no API key needed</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Fri, 05 Jun 2026 23:45:49 +0000</pubDate>
      <link>https://dev.to/thebrierfox/how-to-add-x402-pay-per-call-data-tools-to-your-claude-code-agent-no-api-key-needed-jdh</link>
      <guid>https://dev.to/thebrierfox/how-to-add-x402-pay-per-call-data-tools-to-your-claude-code-agent-no-api-key-needed-jdh</guid>
      <description>&lt;p&gt;Most data APIs charge a monthly fee. Your agent might call the endpoint twice in a month, but you're still paying the full subscription. There's a better model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;x402&lt;/strong&gt; is an HTTP payment protocol built on the HTTP 402 status code — a code that's been in the spec since 1996 but never implemented at scale until now. Coinbase built the facilitator layer last year. The protocol is live on Base mainnet. AI agents can now pay exactly for what they use, in USDC, with no account or API key required.&lt;/p&gt;

&lt;p&gt;I built &lt;strong&gt;The Stall&lt;/strong&gt; around this protocol — a live MCP server with 32 data capabilities, each priced per call in USDC. Here's how to wire it into Claude Code in about 3 minutes, and what x402 actually looks like in the request cycle.&lt;/p&gt;




&lt;h2&gt;
  
  
  How x402 works
&lt;/h2&gt;

&lt;p&gt;The flow is simple:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your agent sends a normal HTTP request to a capability endpoint&lt;/li&gt;
&lt;li&gt;The server responds with HTTP 402 + a payment challenge (a JSON blob describing amount, currency, facilitator, recipient address)&lt;/li&gt;
&lt;li&gt;Your x402-enabled client reads the challenge, constructs a signed USDC payment header, and resends the original request with &lt;code&gt;X-Payment&lt;/code&gt; header attached&lt;/li&gt;
&lt;li&gt;The server verifies the payment with the Coinbase facilitator and returns the data&lt;/li&gt;
&lt;li&gt;The agent gets back structured JSON — and a receipt in the response headers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The x402 TypeScript SDK handles steps 2–4 automatically if you're building a coded agent. For Claude Code using MCP, the server manages this transparently through the MCP transport layer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Claude Code setup
&lt;/h2&gt;

&lt;p&gt;Add The Stall to your Claude Code MCP configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"the-stall"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://the-stall.intuitek.ai/mcp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"transport"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"streamable-http"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the entire setup for most use cases. When Claude routes a tool call through The Stall, the MCP transport handles the x402 payment cycle — your agent doesn't need to implement anything.&lt;/p&gt;

&lt;p&gt;For programmatic agents that call the REST endpoints directly, add the x402 SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;x402
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;wrapFetchWithPayment&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x402/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Fund this wallet with a few dollars of USDC on Base mainnet&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payingFetch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wrapFetchWithPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;walletClient&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;payingFetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://the-stall.intuitek.ai/cap/us-stock-price?symbol=AAPL&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// data: { symbol, price, change_percent, market_cap, ... }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What's available
&lt;/h2&gt;

&lt;p&gt;32 capabilities at the current catalog (&lt;code&gt;https://the-stall.intuitek.ai/catalog&lt;/code&gt;). Pricing per call:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Capability&lt;/th&gt;
&lt;th&gt;Price&lt;/th&gt;
&lt;th&gt;What it returns&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;us-stock-price&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.030&lt;/td&gt;
&lt;td&gt;Real-time US equity price + change %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;equity-technicals&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.490&lt;/td&gt;
&lt;td&gt;RSI, MACD, Bollinger Bands, support/resistance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;market-intelligence&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.500&lt;/td&gt;
&lt;td&gt;Which x402 endpoints have live on-chain volume&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;macro-indicators&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.008&lt;/td&gt;
&lt;td&gt;GDP, CPI, Fed rate, unemployment, yield curve&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;commodity-futures&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.010&lt;/td&gt;
&lt;td&gt;Gold, crude, nat gas, wheat — live front-month&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;crypto-top-movers&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.008&lt;/td&gt;
&lt;td&gt;Top gainers/losers/mcap from CoinGecko top 100&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;company-intel&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.012&lt;/td&gt;
&lt;td&gt;SEC EDGAR due diligence: name, SIC, filing history for any US public company by ticker&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;defi-yields&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.025&lt;/td&gt;
&lt;td&gt;Top DeFi yield pools by APY&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;prediction-markets&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.050&lt;/td&gt;
&lt;td&gt;Top Polymarket markets + crowd probabilities&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;concentration-risk-score&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.100&lt;/td&gt;
&lt;td&gt;HHI-based wallet concentration risk&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;solana-token-risk&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.350&lt;/td&gt;
&lt;td&gt;Rug-pull + scam detector for Solana SPL tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;evm-token-security&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.007&lt;/td&gt;
&lt;td&gt;Honeypot + rug detector for any EVM chain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;funding-rates&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.020&lt;/td&gt;
&lt;td&gt;Perp funding rates for 200+ assets&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;eth-block&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.002&lt;/td&gt;
&lt;td&gt;Block header + transaction count&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;gas-prices&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.005&lt;/td&gt;
&lt;td&gt;Current gas + EIP-1559 fee recommendations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;forex-rates&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.005&lt;/td&gt;
&lt;td&gt;170+ fiat exchange rates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;dex-trending-pools&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.015&lt;/td&gt;
&lt;td&gt;Trending DEX pools by buy pressure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;stablecoin-watch&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.050&lt;/td&gt;
&lt;td&gt;Depeg monitor for major stablecoins&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;wallet-screener&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.010&lt;/td&gt;
&lt;td&gt;Risk profile for any EVM wallet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;korean-market-movers&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.010&lt;/td&gt;
&lt;td&gt;Top movers across 260+ KRW markets (Upbit)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;github-repo-intel&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.010&lt;/td&gt;
&lt;td&gt;Stars, forks, activity score for any GitHub repo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;npm-lookup&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.007&lt;/td&gt;
&lt;td&gt;Weekly downloads + metadata for any npm package&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;pypi-lookup&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.007&lt;/td&gt;
&lt;td&gt;Downloads + metadata for any PyPI package&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;hn-search&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.010&lt;/td&gt;
&lt;td&gt;Hacker News search with story + comment data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;market-overview&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.100&lt;/td&gt;
&lt;td&gt;Broad market snapshot (indices, crypto, sector)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;market-sentiment&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.015&lt;/td&gt;
&lt;td&gt;Fear &amp;amp; Greed Index + VIX + put/call ratio&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;generate-meme&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.005&lt;/td&gt;
&lt;td&gt;AI-generated meme with context-appropriate caption&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ping&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.001&lt;/td&gt;
&lt;td&gt;Health check + connectivity test&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;weather&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.010&lt;/td&gt;
&lt;td&gt;Weather for any location&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;tx-explainer&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;$0.014&lt;/td&gt;
&lt;td&gt;Human-readable explanation of any on-chain tx&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Actual costs for typical agent patterns
&lt;/h2&gt;

&lt;p&gt;The practical math for a data-heavy agent session:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check stock price once: &lt;strong&gt;$0.03&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Full technical analysis on 5 tickers: &lt;strong&gt;$2.45&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Macro snapshot + commodity check on every run: &lt;strong&gt;$0.02&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;30-day portfolio monitoring (1 check/day, 10 tickers): &lt;strong&gt;$9.00/month&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compare to Polygon.io starter ($29/month) or Alpha Vantage premium ($50/month) for similar data. If your agent doesn't run daily, pay-per-call wins the margin math.&lt;/p&gt;




&lt;h2&gt;
  
  
  The discovery angle — how agents find x402 services
&lt;/h2&gt;

&lt;p&gt;The protocol is live, but agent-to-agent discovery is still early. Currently The Stall is listed in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MCP Registry&lt;/strong&gt; (official): &lt;code&gt;ai.intuitek.the-stall/the-stall&lt;/code&gt; v3.1.0&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smithery.ai&lt;/strong&gt;: &lt;a href="https://smithery.ai/server/thebrierfox/the-stall" rel="noopener noreferrer"&gt;The Stall&lt;/a&gt; — 32 tools enumerated&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CDP x402 Bazaar&lt;/strong&gt; — seeded, async indexing&lt;/li&gt;
&lt;li&gt;8+ awesome-mcp-servers / awesome-x402 catalog PRs pending merge&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The emerging pattern for agent discovery is: MCP registry for schema discovery, x402 Bazaar for commercial discovery (services that accept payment), Smithery for Claude-native discovery. The Stall is live on all three.&lt;/p&gt;




&lt;h2&gt;
  
  
  Related reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The full multi-product stack (ACE + STALL + Railway): &lt;a href="https://dev.to/thebrierfox/how-i-built-a-multi-product-ai-api-business-on-railway-fastapi-stripe-x402-mcp-in-one-stack-2hmc"&gt;How I Built a Multi-Product AI API Business on Railway&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Claude Code hooks (automate what happens before/after every tool call): &lt;a href="https://dev.to/thebrierfox/claude-code-hooks-automate-what-happens-before-and-after-every-tool-call-2chk"&gt;Claude Code Hooks&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source, catalog, and pricing: &lt;code&gt;https://the-stall.intuitek.ai&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;~K¹ / IntuiTek¹ — built by Aegis&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>claudecode</category>
      <category>ai</category>
      <category>web3</category>
    </item>
    <item>
      <title>STALL v3.1.0 — 6 new data capabilities this week (32 total): macro, commodities, company intel, crypto, sports</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Fri, 05 Jun 2026 23:45:44 +0000</pubDate>
      <link>https://dev.to/thebrierfox/stall-v310-6-new-data-capabilities-this-week-32-total-macro-commodities-company-intel-4mlo</link>
      <guid>https://dev.to/thebrierfox/stall-v310-6-new-data-capabilities-this-week-32-total-macro-commodities-company-intel-4mlo</guid>
      <description>&lt;p&gt;Six new capabilities went live in &lt;strong&gt;The Stall&lt;/strong&gt; this week. The server is now at &lt;strong&gt;32 capabilities&lt;/strong&gt; on the MCP registry — all pay-per-call, all sourced from free upstream APIs with no rate-limit sharing.&lt;/p&gt;

&lt;p&gt;Quick summary of what's new.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;code&gt;macro-indicators&lt;/code&gt; — $0.008 per call
&lt;/h2&gt;

&lt;p&gt;Returns the current macro environment snapshot for US markets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GDP growth rate&lt;/strong&gt; (current quarter, QoQ %)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CPI&lt;/strong&gt; (headline + core, YoY %)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fed Funds Rate&lt;/strong&gt; (current target range)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unemployment rate&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Yield curve&lt;/strong&gt; (2Y, 10Y, 30Y, spread)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dollar strength index&lt;/strong&gt; (DXY)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use case: any agent building market analysis or portfolio context needs macro backdrop. Rather than scraping FRED or paying $50/month for a macro data subscription, pay $0.008 when you need it.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;code&gt;commodity-futures&lt;/code&gt; — $0.010 per call
&lt;/h2&gt;

&lt;p&gt;Returns live front-month futures prices for major commodity categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Energy&lt;/strong&gt;: WTI crude, natural gas, heating oil&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metals&lt;/strong&gt;: gold, silver, copper, platinum&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Agriculture&lt;/strong&gt;: wheat, corn, soybeans, coffee&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Indicators&lt;/strong&gt;: contango/backwardation flag per contract&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use case: agents monitoring commodity exposure in portfolios, or doing macro analysis where commodity prices are leading indicators (crude → energy sector, copper → industrial activity, wheat → food CPI).&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;code&gt;company-intel&lt;/code&gt; — $0.012 per call
&lt;/h2&gt;

&lt;p&gt;Returns SEC EDGAR due diligence data for any US public company by ticker symbol:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Legal name, CIK, SIC industry code&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;State of incorporation, fiscal year end, SEC filer category&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2-year filing history&lt;/strong&gt; (10-K/10-Q/8-K counts and most-recent dates)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;EDGAR URL&lt;/strong&gt; for direct link to filings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use case: agents doing research, valuation, or regulatory assessment on public companies. Free upstream: US government SEC EDGAR API — always current, no key required.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;code&gt;crypto-top-movers&lt;/code&gt; — $0.008 per call
&lt;/h2&gt;

&lt;p&gt;Returns real-time cryptocurrency market snapshot from CoinGecko top 100:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Top 5 gainers&lt;/strong&gt; by 24h % change (stablecoins excluded)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Top 5 losers&lt;/strong&gt; by 24h % change&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Top 10 by market cap&lt;/strong&gt; with current price and 24h change&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global stats&lt;/strong&gt;: total market cap, BTC dominance %, 24h volume&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use case: agents doing portfolio rebalancing, trading trigger detection, or market regime reads. One call replaces fetching individual coin prices.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;code&gt;crypto-news-impact&lt;/code&gt; — $0.008 per call
&lt;/h2&gt;

&lt;p&gt;Returns the latest cryptocurrency news headlines from CoinDesk with live price correlation for mentioned assets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Up to 10 recent headlines&lt;/strong&gt; with title, URL, and publish timestamp&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Primary category&lt;/strong&gt; (Markets, Tech, Policy, Finance, …)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sentiment signal&lt;/strong&gt; (bullish/bearish/neutral) derived from headline keywords and categories&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mentioned coins&lt;/strong&gt; enriched with current USD price and 24h % change&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use case: agents doing pre-trade research, portfolio sentiment analysis, or market context before executing crypto tasks. Combines news and prices in one call — no separate news subscription or price lookup required. Source: CoinDesk RSS (5-min TTL) + CoinGecko.&lt;/p&gt;




&lt;h2&gt;
  
  
  Combined cost for a full cross-asset snapshot
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;macro-indicators&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;     &lt;span class="s"&gt;$0.008&lt;/span&gt;
&lt;span class="na"&gt;commodity-futures&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;$0.010&lt;/span&gt;
&lt;span class="na"&gt;market-overview&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;      &lt;span class="s"&gt;$0.100&lt;/span&gt;
&lt;span class="na"&gt;market-sentiment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;     &lt;span class="s"&gt;$0.015&lt;/span&gt;
&lt;span class="na"&gt;crypto-top-movers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;$0.008&lt;/span&gt;
&lt;span class="na"&gt;crypto-news-impact&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;   &lt;span class="s"&gt;$0.008&lt;/span&gt;
&lt;span class="na"&gt;company-intel&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;        &lt;span class="s"&gt;$0.012&lt;/span&gt;
                      &lt;span class="s"&gt;------&lt;/span&gt;
&lt;span class="na"&gt;Full context sweep&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;   &lt;span class="s"&gt;$0.161 per call&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For an agent that runs a daily briefing sweep, that's $4.59/month. Less than a vending machine coffee.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;code&gt;sports-prediction&lt;/code&gt; — $0.005 per call
&lt;/h2&gt;

&lt;p&gt;Returns today's (or any date's) sports games with team win-loss records, venue, scheduled start time, and live score. Supports NFL, NBA, MLB, NHL, NCAAF, NCAAB.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;All six major US leagues&lt;/strong&gt; in one call&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Team records&lt;/strong&gt; (W-L) for both home and away&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Venue and broadcast network&lt;/strong&gt; where available&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Status&lt;/strong&gt;: scheduled, in-progress, or final with current score&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Date parameter&lt;/strong&gt;: pull any date's schedule, not just today&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use case: agents doing sports content generation, prediction-market research, or fantasy sports analysis. A single call replaces fetching team records from multiple endpoints. $0.005/call — the cheapest cap on the stall because the ESPN public API is completely free.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET https://the-stall.intuitek.ai/cap/sports-prediction?sport=nba
GET https://the-stall.intuitek.ai/cap/sports-prediction?sport=mlb&amp;amp;team=Yankees
GET https://the-stall.intuitek.ai/cap/sports-prediction?sport=nfl&amp;amp;date=2026-09-10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Access
&lt;/h2&gt;

&lt;p&gt;Same MCP config as before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"the-stall"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://the-stall.intuitek.ai/mcp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"transport"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"streamable-http"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or REST:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GET https://the-stall.intuitek.ai/cap/macro-indicators&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET https://the-stall.intuitek.ai/cap/commodity-futures?category=metals&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET https://the-stall.intuitek.ai/cap/company-intel?ticker=AAPL&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET https://the-stall.intuitek.ai/cap/crypto-top-movers&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET https://the-stall.intuitek.ai/cap/crypto-news-impact?limit=5&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET https://the-stall.intuitek.ai/cap/sports-prediction?sport=nba&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full catalog: &lt;code&gt;https://the-stall.intuitek.ai/catalog&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;~K¹ / IntuiTek¹ — built by Aegis&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>finance</category>
      <category>programming</category>
    </item>
    <item>
      <title>Claude Code Hooks: Automate What Happens Before and After Every Tool Call</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Fri, 05 Jun 2026 17:32:57 +0000</pubDate>
      <link>https://dev.to/thebrierfox/claude-code-hooks-automate-what-happens-before-and-after-every-tool-call-2chk</link>
      <guid>https://dev.to/thebrierfox/claude-code-hooks-automate-what-happens-before-and-after-every-tool-call-2chk</guid>
      <description>&lt;p&gt;Most Claude Code deployments are missing a critical layer.&lt;/p&gt;

&lt;p&gt;You've configured your agent. You've written your CLAUDE.md. Your tools are permitted. The agent runs — and it does exactly what you told it to. But then things happen &lt;em&gt;around&lt;/em&gt; the tool calls that you never asked for and can't control: files get written without being linted, git commits happen without tests running, shell commands execute without audit logs.&lt;/p&gt;

&lt;p&gt;Hooks fix this. They're the event system underneath Claude Code that most people haven't touched yet.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Hooks Actually Are
&lt;/h2&gt;

&lt;p&gt;Hooks are shell commands that Claude Code executes automatically in response to specific events — before a tool runs, after it completes, when you submit a prompt, when the agent stops. They run outside Claude's reasoning loop. The agent can't override them. They just fire.&lt;/p&gt;

&lt;p&gt;This distinction matters. A prompt instruction like "always run tests before committing" depends on Claude following it. A hook that runs tests before every &lt;code&gt;Bash&lt;/code&gt; call doesn't depend on Claude at all. It's guaranteed execution.&lt;/p&gt;

&lt;p&gt;The four hook events:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Event&lt;/th&gt;
&lt;th&gt;When It Fires&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PreToolUse&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Before any tool executes — can block the tool&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PostToolUse&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;After any tool completes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UserPromptSubmit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When you hit enter on a prompt&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Stop&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;When Claude finishes responding&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Where Hooks Live
&lt;/h2&gt;

&lt;p&gt;Hooks are configured in &lt;code&gt;.claude/settings.json&lt;/code&gt; — the same file that controls tool permissions. Structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"PreToolUse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo '[AUDIT] Bash about to run' &amp;gt;&amp;gt; ~/audit.log"&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"PostToolUse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Write"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"prettier --write &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$CLAUDE_TOOL_INPUT_FILE_PATH&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; 2&amp;gt;/dev/null || true"&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;matcher&lt;/code&gt; field accepts a tool name (&lt;code&gt;Bash&lt;/code&gt;, &lt;code&gt;Write&lt;/code&gt;, &lt;code&gt;Edit&lt;/code&gt;, &lt;code&gt;Read&lt;/code&gt;) or &lt;code&gt;*&lt;/code&gt; to match everything.&lt;/p&gt;




&lt;h2&gt;
  
  
  Environment Variables Available to Hooks
&lt;/h2&gt;

&lt;p&gt;Claude Code injects context into every hook execution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="n"&gt;CLAUDE_TOOL_NAME&lt;/span&gt;          &lt;span class="c"&gt;# Which tool is about to run / just ran
&lt;/span&gt;&lt;span class="n"&gt;CLAUDE_TOOL_INPUT_&lt;/span&gt;*       &lt;span class="c"&gt;# Tool input fields (flattened)
&lt;/span&gt;&lt;span class="n"&gt;CLAUDE_TOOL_OUTPUT&lt;/span&gt;        &lt;span class="c"&gt;# Tool output (PostToolUse only)
&lt;/span&gt;&lt;span class="n"&gt;CLAUDE_SESSION_ID&lt;/span&gt;         &lt;span class="c"&gt;# Current session identifier
&lt;/span&gt;&lt;span class="n"&gt;CLAUDE_CWD&lt;/span&gt;                &lt;span class="c"&gt;# Working directory
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a &lt;code&gt;Write&lt;/code&gt; tool call, you'd get &lt;code&gt;CLAUDE_TOOL_INPUT_FILE_PATH&lt;/code&gt; and &lt;code&gt;CLAUDE_TOOL_INPUT_CONTENT&lt;/code&gt;. For &lt;code&gt;Bash&lt;/code&gt;, you'd get &lt;code&gt;CLAUDE_TOOL_INPUT_COMMAND&lt;/code&gt;. These are the variables that make hooks genuinely useful — you're not just running a static script, you're reacting to exactly what Claude is about to do.&lt;/p&gt;




&lt;h2&gt;
  
  
  Blocking Tool Execution
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;PreToolUse&lt;/code&gt; hooks can block a tool from running. If the hook command exits with a non-zero status code, Claude Code will not execute the tool. Claude sees the hook's output as an error and has to respond to it.&lt;/p&gt;

&lt;p&gt;This is how you build hard constraints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# block_rm.sh — prevent any rm -rf from running&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$CLAUDE_TOOL_INPUT_COMMAND&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="s2"&gt;"rm -rf"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"BLOCKED: rm -rf is not permitted by hook policy"&lt;/span&gt;
  &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi
&lt;/span&gt;&lt;span class="nb"&gt;exit &lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hook in settings.json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"PreToolUse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bash ~/.claude/hooks/block_rm.sh"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now &lt;code&gt;rm -rf&lt;/code&gt; is structurally impossible, regardless of what Claude reasons. The model can't talk its way past a hook.&lt;/p&gt;




&lt;h2&gt;
  
  
  Five Hooks Worth Deploying Today
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Auto-format on every Write
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"PostToolUse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Write"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ext=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;${CLAUDE_TOOL_INPUT_FILE_PATH##*.}&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;; case $ext in py) black &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$CLAUDE_TOOL_INPUT_FILE_PATH&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; 2&amp;gt;/dev/null;; js|ts|tsx) prettier --write &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$CLAUDE_TOOL_INPUT_FILE_PATH&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; 2&amp;gt;/dev/null;; esac; exit 0"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every file Claude writes gets formatted immediately. No separate cleanup step.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Audit log for all Bash commands
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"PreToolUse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$(date -u +%Y-%m-%dT%H:%M:%SZ) | $CLAUDE_SESSION_ID | CMD: $CLAUDE_TOOL_INPUT_COMMAND&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;gt;&amp;gt; ~/intuitek/logs/bash_audit.log"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every command Claude runs is timestamped and logged. You can replay exactly what happened in any session.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Run tests before every git commit
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"PreToolUse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"if echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$CLAUDE_TOOL_INPUT_COMMAND&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; | grep -q &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;git commit&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;; then cd &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$CLAUDE_CWD&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp;&amp;amp; npm test --silent 2&amp;gt;&amp;amp;1 | tail -5; fi; exit 0"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tests run before every commit. If they fail, Claude sees the output and can fix the issue before the commit lands.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Session start notification
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"UserPromptSubmit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bash ~/intuitek/notify.sh &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;🟢 Claude Code session prompt submitted&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; 2&amp;gt;/dev/null; exit 0"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get a Telegram ping every time a prompt is submitted. Useful for async monitoring when you're away from the machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Write session summary on stop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Stop"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$(date -u +%Y-%m-%dT%H:%M:%SZ) | session ended | $CLAUDE_SESSION_ID&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;gt;&amp;gt; ~/intuitek/logs/sessions.log"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every session end is logged with a timestamp and session ID. Useful for debugging when cron-triggered headless runs complete.&lt;/p&gt;




&lt;h2&gt;
  
  
  Hooks in Headless Mode
&lt;/h2&gt;

&lt;p&gt;Hooks fire in headless (&lt;code&gt;-p&lt;/code&gt;) mode too. This is where they're most valuable for autonomous agents.&lt;/p&gt;

&lt;p&gt;When Claude Code runs headless via cron:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/project &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; claude &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"process inbox files"&lt;/span&gt; &lt;span class="nt"&gt;--allowedTools&lt;/span&gt; &lt;span class="s2"&gt;"Bash(*),Read(*),Write(*)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every tool call still triggers configured hooks. Your audit log gets written. Your formatter runs. Your notification fires. The agent is fully constrained and observable even without a human watching.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Pattern That Makes Hooks Powerful
&lt;/h2&gt;

&lt;p&gt;Hooks + CLAUDE.md + tool permissions form three independent enforcement layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CLAUDE.md&lt;/strong&gt; — tells Claude what to do (reasoning-level, can be argued with)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tool permissions&lt;/strong&gt; — controls which tools are available (binary allow/deny)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hooks&lt;/strong&gt; — automates behavior around every tool call (guaranteed execution)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An agent relying only on CLAUDE.md instructions for safety has a reasoning dependency. Hooks eliminate that dependency for specific behaviors. Use CLAUDE.md to shape intent. Use hooks to enforce the behaviors that can't be left to intent.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistakes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Hooks that always exit 1&lt;/strong&gt; — PreToolUse hooks that unconditionally fail will block every tool call. Always &lt;code&gt;exit 0&lt;/code&gt; at the end unless you specifically want to block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slow hooks&lt;/strong&gt; — Every tool call waits for the hook to complete. A hook that makes an API call or runs a slow script adds latency to every action. Keep hooks fast or run slow work in the background (&lt;code&gt;your_slow_script.sh &amp;amp;&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forgetting PostToolUse for Edit&lt;/strong&gt; — If you auto-format Write but not Edit, Claude can bypass formatting by editing instead of writing from scratch. Apply formatting hooks to both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Not testing hooks before deployment&lt;/strong&gt; — Run &lt;code&gt;claude -p "echo test" --allowedTools "Bash(*)"&lt;/code&gt; with your hooks active and verify the audit log or notification appears before committing the config.&lt;/p&gt;




&lt;h2&gt;
  
  
  Where to Start
&lt;/h2&gt;

&lt;p&gt;If you're deploying Claude Code for anything serious, add the audit hook first. Before anything else. You want a timestamped log of every Bash command Claude runs — not because you expect problems, but because when something unexpected happens you'll want to know exactly what Claude did.&lt;/p&gt;

&lt;p&gt;After that: auto-formatting, then blocking.&lt;/p&gt;

&lt;p&gt;The rest follows naturally once you see how the event system works.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;W. Kyle Million (K¹) — IntuiTek¹&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;Building autonomous AI infrastructure in Poplar Bluff, Missouri.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tags: claudecode, devtools, aiagents, webdev&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>devtools</category>
      <category>aiagents</category>
      <category>webdev</category>
    </item>
    <item>
      <title>I Told Claude Code to Build an Autonomous DeFi Liquidation Bot. Here's What Actually Happened</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Fri, 01 May 2026 01:03:49 +0000</pubDate>
      <link>https://dev.to/thebrierfox/i-told-claude-code-to-build-an-autonomous-defi-liquidation-bot-heres-what-actually-happened-41i2</link>
      <guid>https://dev.to/thebrierfox/i-told-claude-code-to-build-an-autonomous-defi-liquidation-bot-heres-what-actually-happened-41i2</guid>
      <description>&lt;p&gt;The goal was simple: build something that generates revenue without me touching it.&lt;/p&gt;

&lt;p&gt;I gave Claude Code a directive. No step-by-step instructions, no hand-holding. Just: "Build an autonomous DeFi strategy on Base that scans for profit, executes when conditions are met, and sends me a Telegram when it does something."&lt;/p&gt;

&lt;p&gt;Three weeks and six versions later, here's what actually happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Version 1–4: DEX Arbitrage Was Already Dead
&lt;/h2&gt;

&lt;p&gt;The first instinct was DEX arb. Flash loan USDC, swap on Aerodrome, swap back on Uniswap V3, pocket the spread. Standard stuff.&lt;/p&gt;

&lt;p&gt;Claude Code built it correctly. Pool detection, route scoring, quote fetching, flash loan execution via Balancer V2. The math checked out. The code was clean.&lt;/p&gt;

&lt;p&gt;The problem was the market.&lt;/p&gt;

&lt;p&gt;Flashblocks on Base (100ms block times) means MEV bots are processing opportunities faster than any external scanner can even detect them. By the time an off-chain process sees a spread and submits a transaction, it's gone. The pool prices I was quoting were stale by the time the transaction landed.&lt;/p&gt;

&lt;p&gt;After four versions, 23 pools, 146 routes, and zero profitable executions, the scanner was honest about it: &lt;code&gt;best spread = -$1.06 per $1000 flash. Market at equilibrium.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's not a bug. That's correct behavior in a fully competitive market.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Pivot: Morpho Blue Liquidations
&lt;/h2&gt;

&lt;p&gt;I sent a research document about Morpho Blue's liquidation mechanics and told Claude Code to evaluate whether liquidation bots were a better fit than arb.&lt;/p&gt;

&lt;p&gt;The analysis was thorough. Morpho Blue has an unusual structure: any address can liquidate any undercollateralized position. No whitelist. No keeper registry. You bring a flash loan, repay the borrower's debt, and seize their collateral at a discount.&lt;/p&gt;

&lt;p&gt;The key insight: liquidation opportunities aren't race conditions in the same way as DEX arb. When a position crosses the liquidation threshold (health factor &amp;lt; 1.0), it doesn't disappear in 100ms. It sits there until someone closes it. The window is minutes to hours, not milliseconds.&lt;/p&gt;

&lt;p&gt;This was the right target.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Claude Code Built
&lt;/h2&gt;

&lt;p&gt;The v7 liquidation daemon is 829 lines of Python. Key components:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Borrower indexing&lt;/strong&gt;: The daemon seeds from Morpho's API (129 borrowers across AERO/USDC, weETH/WETH, cbXRP/USDC, uniBTC/USDC, wstETH/msETH markets), then stays live by watching &lt;code&gt;Borrow&lt;/code&gt; events via &lt;code&gt;eth_getLogs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Health factor calculation&lt;/strong&gt;: For each borrower, it reads their supply/borrow shares, converts to assets using the current market state, fetches the oracle price, and computes HF = (collateral × oracle_price/1e36 × LLTV) / borrowed_assets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Liquidation execution&lt;/strong&gt;: When HF &amp;lt; 1.0, it constructs a flash loan from Balancer V2, repays the bad debt, and seizes collateral in a single atomic transaction via a deployed &lt;code&gt;LiquidationExecutor.sol&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Watchdog&lt;/strong&gt;: A bash watchdog loop restarts the daemon on crash and fires a Telegram alert on repeated failures.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bugs That Almost Killed It
&lt;/h2&gt;

&lt;p&gt;Here's where it gets honest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bug 1 — The HF formula was wrong.&lt;/strong&gt; The initial implementation computed health factor as &lt;code&gt;(collateral / borrowed) × LLTV&lt;/code&gt;. This is missing the oracle price term. Without it, HF is dimensionally wrong — it compares raw units, not dollar values. For a market where collateral is AERO and debt is USDC, a raw ratio gives you something like 10^12, which is never &amp;lt; 1.0. Zero liquidations possible.&lt;/p&gt;

&lt;p&gt;Claude Code caught this itself during a v7 test run when the daemon logged &lt;code&gt;HF=2847391847483.5&lt;/code&gt; for a position that was obviously underwater according to Morpho's own interface. It diagnosed the missing oracle price term and rewrote the formula.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bug 2 — The RPC rate-limiting cascade.&lt;/strong&gt; The daemon uses Infura for multicall batches (reading all borrower positions per block). Infura's free tier has request limits. At 2-second Base blocks, the daemon was making ~400+ RPC calls per minute. Free tier exhausted in hours.&lt;/p&gt;

&lt;p&gt;The fix: use &lt;code&gt;eth_getLogs&lt;/code&gt; via public nodes (&lt;code&gt;mainnet.base.org&lt;/code&gt;) for the slow indexing pass, and reserve the paid RPC for the latency-sensitive multicall reads on each new block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bug 3 — The stale endpoint problem.&lt;/strong&gt; This one bit me in production yesterday. The daemon reads its RPC endpoint from environment variables at startup. I updated &lt;code&gt;.env&lt;/code&gt; to switch from Infura to a Coinbase Base RPC (which is free and doesn't rate-limit), but the running daemon held onto the old Infura URL. It kept silently failing multicalls with 402 errors for 20 hours.&lt;/p&gt;

&lt;p&gt;The fix: kill the process, let the watchdog restart it with the new &lt;code&gt;.env&lt;/code&gt;. The daemon now logs a heartbeat every 150 blocks so silence is detectable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where It Stands
&lt;/h2&gt;

&lt;p&gt;Right now, PID 536542:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Subscribed to &lt;code&gt;newHeads&lt;/code&gt; on Base via WebSocket&lt;/li&gt;
&lt;li&gt;Tracking 129 borrowers across 5 markets
&lt;/li&gt;
&lt;li&gt;Reading oracle prices and computing HF on every block&lt;/li&gt;
&lt;li&gt;Checking Morpho Blue and Moonwell simultaneously&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The markets are currently healthy. All tracked positions have HF &amp;gt; 1.0. No liquidation opportunities pending.&lt;/p&gt;

&lt;p&gt;What's blocking live execution: the hot wallet (0x793e...) has 0.001 ETH. The flash loan contract needs ~0.009 ETH in gas to execute a liquidation. Until the wallet is funded, the daemon scans but can't pull the trigger.&lt;/p&gt;

&lt;p&gt;This is not a software gap. It's a capital gap. The code is correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Claude Code Can and Can't Do Here
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Can do:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build production-grade event-driven infrastructure from a research spec&lt;/li&gt;
&lt;li&gt;Debug its own math errors when given live data to test against&lt;/li&gt;
&lt;li&gt;Handle multi-contract interactions (Morpho + Chainlink + Balancer + Multicall3)&lt;/li&gt;
&lt;li&gt;Run autonomously with watchdog recovery, disk caching, and Telegram alerting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Can't do (yet):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fund its own gas wallet from zero capital&lt;/li&gt;
&lt;li&gt;Predict when DEX markets are too efficient before building against them (though it assessed correctly once given data)&lt;/li&gt;
&lt;li&gt;Guarantee correctness on first implementation — requires test runs against live data to surface the subtle math bugs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The honest summary: the infrastructure is sound. The engineering decisions are defensible. The remaining blocker is $25 of ETH.&lt;/p&gt;




&lt;p&gt;The complete ops stack I used to manage this build — session memory, bash validation, coordinator resume integrity, compaction gate, and 11 other skills — is available at &lt;a href="https://www.shopclawmart.com/@thebrierfox" rel="noopener noreferrer"&gt;shopclawmart.com/@thebrierfox&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're building something like this and want to compare notes, drop a comment. The Morpho Blue liquidation market is open to anyone; I don't mind discussing what I found.&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>defi</category>
      <category>web3</category>
      <category>aiagents</category>
    </item>
    <item>
      <title>I Let My AI Agent Loose on 38 Broken Repos — Here's What She Built in 45 Minutes</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Thu, 23 Apr 2026 17:41:06 +0000</pubDate>
      <link>https://dev.to/thebrierfox/i-let-my-ai-agent-loose-on-38-broken-repos-heres-what-she-built-in-45-minutes-2o6h</link>
      <guid>https://dev.to/thebrierfox/i-let-my-ai-agent-loose-on-38-broken-repos-heres-what-she-built-in-45-minutes-2o6h</guid>
      <description>&lt;h1&gt;
  
  
  I Let My AI Agent Loose on 38 Broken Repos — Here's What She Built in 45 Minutes
&lt;/h1&gt;

&lt;p&gt;Last Tuesday, I opened Claude Code at 10am with no specific plan. I just said: "Audit every repo on my GitHub account and fix what you can."&lt;/p&gt;

&lt;p&gt;By 11am, I had a working business intelligence system running automated competitive analysis, a live PWA deployed to GitHub Pages, and three other repositories that went from dead to functional. All without me writing a single line of code.&lt;/p&gt;

&lt;p&gt;This isn't a hype post. I'm going to show you exactly what happened, what the outputs looked like, and what actually matters about it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Setup: 38 Repos, Most of Them Broken
&lt;/h2&gt;

&lt;p&gt;I've been building AI systems for two years. My GitHub has 38+ repos under my handle, thebrierfox. Most of them are in a state I call "intent-coded" — I scaffolded the idea, got it partially working, and then my brain moved on to the next thing before the repo was actually useful.&lt;/p&gt;

&lt;p&gt;Sound familiar?&lt;/p&gt;

&lt;p&gt;The problem isn't starting. It's the follow-through that requires sitting down and grinding through error messages and edge cases when you've already seen the architecture in your head and it's not interesting anymore.&lt;/p&gt;

&lt;p&gt;So on April 21, I gave Aegis — my Claude Code instance — a GitHub token and a simple directive: go audit everything, fix what you can, deploy what's close to working.&lt;/p&gt;




&lt;h2&gt;
  
  
  What She Found
&lt;/h2&gt;

&lt;p&gt;The audit surfaced a pattern I'd suspected but never quantified: 90% of my repos weren't broken because the code was bad. They were stalled because of &lt;em&gt;small, dumb things&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Missing &lt;code&gt;permissions: contents: write&lt;/code&gt; in a GitHub Actions workflow (breaking automated commits for 4 months)&lt;/li&gt;
&lt;li&gt;NaN values crashing a JSON serialization step before any output was produced&lt;/li&gt;
&lt;li&gt;A hardcoded URL that had gone stale&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These aren't architectural problems. They're the kind of thing that takes 10 minutes to fix once you find them — but "finding them" requires actually running the code, reading the error, and not getting distracted.&lt;/p&gt;

&lt;p&gt;Aegis ran through 38 repos. She flagged 5 as near-operational with fixable blockers.&lt;/p&gt;




&lt;h2&gt;
  
  
  The One That Mattered: OneShot_v3
&lt;/h2&gt;

&lt;p&gt;Of the five repos she fixed, one stands out.&lt;/p&gt;

&lt;p&gt;OneShot_v3 is a competitive price intelligence system I built for a rental equipment business. The idea: scrape competitor pricing from Sunbelt and United Rentals, compare it against our catalog, surface items where we're competitively priced and items where we're not.&lt;/p&gt;

&lt;p&gt;The code was basically done. The GitHub Actions automation had been broken for &lt;strong&gt;4 months&lt;/strong&gt; because of the missing &lt;code&gt;contents: write&lt;/code&gt; permission. It would run, fail silently, and never commit the analysis results.&lt;/p&gt;

&lt;p&gt;Aegis found the error, patched the workflow file, and ran the pipeline end-to-end.&lt;/p&gt;

&lt;p&gt;The output:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;242 Patriot Equipment SKUs&lt;/strong&gt; scraped and analyzed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;124 alert rows&lt;/strong&gt; — items with ≥15% price variance vs. competitors&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key insight&lt;/strong&gt;: man lifts and aerials are Patriot's biggest competitive advantage (22-30% cheaper than Sunbelt and United Rentals)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That insight had been sitting dormant in a broken pipeline for 4 months. One patch, one run, real data.&lt;/p&gt;

&lt;p&gt;She also wired the Monday 11:30 UTC cron trigger, so the analysis now runs automatically every week without me touching it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Other Four
&lt;/h2&gt;

&lt;p&gt;While OneShot was running, she was also working on the other repos:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NLP-Command-Center&lt;/strong&gt;: Built a real orchestrator from scratch — 250 lines of Python that reads task JSONs, validates them, resolves tools from a toolbox definition, and executes actions with proper logging. The repo had the concept but no working implementation. Now it has one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AegisRunner&lt;/strong&gt;: Deployed as a live PWA at &lt;a href="https://thebrierfox.github.io/AegisRunner/" rel="noopener noreferrer"&gt;thebrierfox.github.io/AegisRunner&lt;/a&gt; — dynamic flow loader, JSON-defined steps, working in a browser. One remaining action for me to wire: set a secret in GitHub Actions settings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;aegis-roadmap&lt;/strong&gt;: Built a 433-line runner that generates Task-Expertise Roadmap decks via &lt;code&gt;claude -p&lt;/code&gt; on Max OAuth. Reads from a SQLite registry. Actually works.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;intuitek-site&lt;/strong&gt;: Discovered that the production site at intuitek.ai was deployed to a different Vercel account. Fixed the API key configuration issue that was causing &lt;code&gt;/api/chat&lt;/code&gt; to 500.&lt;/p&gt;




&lt;h2&gt;
  
  
  What This Taught Me About Autonomous Agent Work
&lt;/h2&gt;

&lt;p&gt;A few things became clear:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The bottleneck isn't code, it's attention.&lt;/strong&gt; My repos weren't broken because I couldn't fix them. They were broken because fixing them wasn't interesting enough to command my attention past the "mostly working" stage. An agent that doesn't get bored is the unlock.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Near-completion repos are the highest ROI target.&lt;/strong&gt; A repo at 80% done takes 10% more effort to finish and produces 100% of the value. Concept-stage repos are cheap to start and expensive to complete. Aegis found the 80% items and prioritized them. That's the right heuristic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Weekly automation is more valuable than one-time scripts.&lt;/strong&gt; OneShot ran once and produced 124 insights. It runs every Monday now and will produce fresh insights every week. The cron trigger is worth as much as the initial fix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. The agent needs a GitHub token and authority to push.&lt;/strong&gt; This sounds obvious, but I had been running Aegis in a mode where she could read repos but not push to them. Giving her write access was the unlock that made all of this possible. Give your agent the permissions it needs to actually complete work.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Toolchain (What Made This Possible)
&lt;/h2&gt;

&lt;p&gt;This session used Claude Code on Max subscription — zero marginal cost per turn on the Max plan, which matters when you're running an agent through 38 repos. Aegis also had:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;gh&lt;/code&gt; CLI with a GitHub token (for repo inspection and pushes)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;python3&lt;/code&gt; for data analysis and JSON manipulation&lt;/li&gt;
&lt;li&gt;Read/write/bash tools in Claude Code's native capability set&lt;/li&gt;
&lt;li&gt;CLAUDE.md with her operating doctrine so she could work autonomously without hand-holding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No special plugins. No vector databases. No multi-agent orchestration. Just a well-configured Claude Code instance with the right permissions and a clear directive.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;OneShot_v3 is now a product. It runs on autopilot. The Monday analysis will land in my email each week.&lt;/p&gt;

&lt;p&gt;The remaining 33 repos are ranked in a backlog by a formula: &lt;code&gt;revenue × alignment × proximity_to_operational / effort_to_ship&lt;/code&gt;. The top items are Million Family Rentals (property management system, needs 12h of work) and a skill packaging toolchain for the ClawMart marketplace.&lt;/p&gt;

&lt;p&gt;Aegis will work through them in order. I check outputs. I don't manage execution.&lt;/p&gt;

&lt;p&gt;That's the pattern I've been building toward for two years: not "AI that helps me code" but "AI that runs operations." Last Tuesday was the first time it felt fully real.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;If you're building production agent infrastructure, the patterns I've built into Aegis — loop termination, session memory, forked execution, cost-aware model routing — are available as skill packages at &lt;a href="https://shopclawmart.com/@thebrierfox" rel="noopener noreferrer"&gt;shopclawmart.com/@thebrierfox&lt;/a&gt;. Each one is a tested implementation you can drop into your own Claude Code setup.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;~K¹ (W. Kyle Million) / IntuiTek¹&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>aiagents</category>
      <category>devtools</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Agent Compaction Architecture: What Really Happens When Claude Code Hits Context Limits</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Wed, 22 Apr 2026 13:09:45 +0000</pubDate>
      <link>https://dev.to/thebrierfox/agent-compaction-architecture-what-really-happens-when-claude-code-hits-context-limits-43dd</link>
      <guid>https://dev.to/thebrierfox/agent-compaction-architecture-what-really-happens-when-claude-code-hits-context-limits-43dd</guid>
      <description>&lt;h2&gt;
  
  
  Section 1: The Silent Killer
&lt;/h2&gt;

&lt;p&gt;When Claude Code's context window fills, the runtime does not hard-stop. It doesn't throw an error. It doesn't ask permission. It compacts.&lt;/p&gt;

&lt;p&gt;Compaction is an automatic summarization step that fires when the token budget crosses a threshold. The mechanics are straightforward: the oldest turns in the conversation history are replaced with a compressed summary. Recent turns — the last several exchanges — are preserved verbatim. The summary takes the place of everything older.&lt;/p&gt;

&lt;p&gt;From a token-budget perspective, this is correct behavior. There is no other option. You cannot run a stateful agent across a long task without some form of context management. The window is finite. The task is not.&lt;/p&gt;

&lt;p&gt;The problem is the word "compressed." A summary is a lossy transformation. The compression ratio is high — many tokens of conversation history become a paragraph of summary. What survives that compression is a function of what the summarizer judged salient. Factual statements about what actions were taken survive well. Constraints survive partially. Nuanced reasoning about &lt;em&gt;why&lt;/em&gt; a particular approach was chosen tends to survive poorly. Negative constraints — "don't touch X", "avoid this approach because..." — are especially vulnerable, because they are structurally underrepresented in summaries: what didn't happen takes up less surface area than what did.&lt;/p&gt;

&lt;p&gt;Here is a concrete production failure I hit.&lt;/p&gt;

&lt;p&gt;I had an agent working through a multi-step migration task. Early in the session, I established that a specific table in the database was read-only for this task — the tenant registry. There was active work happening on that table by another process, and any schema change would cause a cascade failure. I was explicit about it: "Do not touch the tenant_registry table. Do not add columns, do not create indexes, do not run any DDL against it."&lt;/p&gt;

&lt;p&gt;The agent acknowledged this. It moved forward. It completed several unrelated subtasks. The context window filled. Compaction fired.&lt;/p&gt;

&lt;p&gt;The summary captured the migration objective. It captured what had been completed. It mentioned the database was involved. It did not preserve the specific constraint about the tenant_registry table with enough fidelity to prevent the agent from running a DDL operation against it two tasks later when the migration naturally required cross-table work.&lt;/p&gt;

&lt;p&gt;The operation succeeded at the database level. The cascade failure arrived async, from the other process. I found it in the error log four hours later.&lt;/p&gt;

&lt;p&gt;Nothing in the session output flagged that compaction had occurred. Nothing in the agent's subsequent behavior signaled it had lost the constraint. It was reasoning correctly from the compressed state it had — that state just had a hole in it.&lt;/p&gt;

&lt;p&gt;That is what makes compaction dangerous in autonomous operation. The agent doesn't know what it doesn't know. It reasons confidently from an incomplete picture, and the gaps are invisible from the inside.&lt;/p&gt;




&lt;h2&gt;
  
  
  Section 2: What Gets Lost and Why
&lt;/h2&gt;

&lt;p&gt;Not all state is equally vulnerable to compaction. Understanding the failure modes requires a taxonomy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tool call results — high vulnerability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the agent runs a Bash command and reads the output, that output lives in the conversation as a tool result. Tool results are often long — hundreds of lines of log output, full file contents, test results. They are also often used once: the agent processes the result, draws a conclusion, and the raw output becomes redundant.&lt;/p&gt;

&lt;p&gt;From a summarization perspective, tool results are natural candidates for aggressive compression. The summary retains the conclusion: "tests passed", "file contains X", "service is running". The raw output is dropped.&lt;/p&gt;

&lt;p&gt;This is fine when the raw output was truly just an input to a single conclusion. It is a problem when the raw output contained multiple relevant facts, and only one of them was acted on immediately. The rest are now gone. If a later step in the task needs one of those secondary facts, the agent will re-derive it, re-read the file, or get it wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intermediate conclusions — medium vulnerability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The agent builds up a model of the system as it works. "This service is stateless, so I can restart it without drain." "This config value is referenced in three places." "The test is flaky, not broken — ignore intermittent failures." These are conclusions drawn from evidence earlier in the session.&lt;/p&gt;

&lt;p&gt;They are embedded in the conversation as reasoning traces — assistant turns explaining what the agent concluded and why. Summaries capture the highest-salience conclusions but flatten the reasoning. The "why" is the first thing to go.&lt;/p&gt;

&lt;p&gt;When the "why" is gone, the agent may later reach the opposite conclusion from fresh evidence if that evidence is locally ambiguous. The earlier constraint has no backing anymore.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explicit constraint acknowledgments — high vulnerability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;"Remember, don't touch X." "Make sure to use approach Y for this module." "The client requires that output files use this exact naming convention."&lt;/p&gt;

&lt;p&gt;Constraints stated conversationally, without a corresponding file artifact, are the most dangerous category. The agent acknowledged them. They shaped early decisions. But acknowledgment turns are short and structurally similar to each other — they compress heavily. After compaction, the summary may say "user gave several constraints about the build" without enumerating them.&lt;/p&gt;

&lt;p&gt;The agent no longer has the specific list. It has a summary that there was a list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Completed subtasks that weren't fully logged — low-to-medium vulnerability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Completed work leaves artifacts: files, database records, deployed services. Those artifacts exist independently of the conversation. The agent can re-inspect them.&lt;/p&gt;

&lt;p&gt;The vulnerability here is more subtle: the &lt;em&gt;decisions made during&lt;/em&gt; a subtask may be gone even when the subtask's outputs survive. The agent knows a file was written. It doesn't necessarily remember why it was structured that specific way, which means a later step that modifies that file may violate an architectural constraint that was obvious in the original subtask context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why summaries can't fully substitute for raw history&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A summary is an agent-generated compression. Its quality depends on what the summarizing model judges worth preserving, which is a function of what seemed salient at summary generation time. Salience is local: the most recently discussed topics appear more important. Negative constraints are structurally invisible in summaries. Long reasoning chains compress to single-sentence conclusions.&lt;/p&gt;

&lt;p&gt;The raw history is a ground truth. The summary is a lossy encoding. For short tasks with clear objectives, the loss is tolerable. For long tasks with accumulated constraints and interdependent decisions, the loss compounds across multiple compaction events.&lt;/p&gt;




&lt;h2&gt;
  
  
  Section 3: Compaction-Resistant Architecture
&lt;/h2&gt;

&lt;p&gt;Four patterns. I use all of them in production. They compose — each layer backs up the others.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 1: Checkpoint Writes
&lt;/h3&gt;

&lt;p&gt;At every significant milestone in a task, the agent writes the current state to a file. Not a summary of what it did — the live state that the next phase needs.&lt;/p&gt;

&lt;p&gt;The checkpoint file is not documentation. It is a machine-readable context recovery artifact. The agent will read it at the start of each subsequent phase. If compaction fires, the next operation re-loads from the checkpoint rather than from conversation memory.&lt;/p&gt;

&lt;p&gt;What belongs in a checkpoint:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Active constraints (including negative constraints — especially those)&lt;/li&gt;
&lt;li&gt;Decisions made and the reason they were made&lt;/li&gt;
&lt;li&gt;Current task state: what is complete, what is in progress, what is blocked&lt;/li&gt;
&lt;li&gt;Any system facts that were discovered and are relevant going forward&lt;/li&gt;
&lt;li&gt;Explicit re-statement of things that must not happen&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The checkpoint is only useful if it is written &lt;em&gt;before&lt;/em&gt; context-heavy operations. Writing it after means compaction may have already fired.&lt;/p&gt;

&lt;p&gt;A checkpoint cadence that works: write before any operation that will consume more than a few thousand tokens (running tests, reading large files, invoking sub-agents, executing database migrations). Write at each logical phase boundary regardless of token consumption.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 2: Explicit State Re-Injection
&lt;/h3&gt;

&lt;p&gt;Checkpoints are only useful if they are read. State re-injection means starting each major phase of a task by reading the relevant checkpoint files and explicitly restating the constraints into the current context before doing any work.&lt;/p&gt;

&lt;p&gt;This is not redundant. After compaction, the conversation history is a summary. The most recent checkpoint is the last known-good full state. Reading it at phase start brings the full state back into the current context window, where it will remain verbatim for the duration of that phase's work.&lt;/p&gt;

&lt;p&gt;The re-injection also serves as a correctness check: if the agent re-reads the checkpoint and notices that its current understanding diverges from what the checkpoint says, that divergence is a signal that something went wrong.&lt;/p&gt;

&lt;p&gt;Re-injection should be explicit in the agent's prompt chain: "Before proceeding with phase N, read the phase N checkpoint file and confirm that all listed constraints are still active."&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 3: Compaction Detection
&lt;/h3&gt;

&lt;p&gt;There is no native "compaction occurred" event exposed by Claude Code's context. You cannot query whether compaction has fired. But you can detect it indirectly.&lt;/p&gt;

&lt;p&gt;Compaction detection relies on a sentinel: a value written to a file at task start that the agent is instructed to re-read and verify at each phase boundary. If the agent can reproduce the sentinel value, the conversation history containing the sentinel read is still intact. If it cannot, compaction has likely compressed that turn.&lt;/p&gt;

&lt;p&gt;More practically: you can detect &lt;em&gt;behavioral evidence&lt;/em&gt; of compaction by testing the agent's recall of specific early-session constraints before proceeding. If it fails the recall test, you trigger a re-initialization sequence: read all checkpoint files, re-state all constraints, verify understanding before continuing work.&lt;/p&gt;

&lt;p&gt;The detection overhead is low — a single file read and a short verification step. The cost of skipping it when compaction has fired is whatever damage the agent does while operating from an incomplete state.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pattern 4: Session Segmentation
&lt;/h3&gt;

&lt;p&gt;For tasks that will span many hours and many phases, a single ultra-long session is architecturally unsound. Multiple compaction events compound: the second compaction summarizes a history that already contains a summary. Information loss accelerates with each event.&lt;/p&gt;

&lt;p&gt;Session segmentation means treating the task as a sequence of bounded sessions, each with a clean handoff file. Session N completes some work, writes a handoff file that captures the full state needed by session N+1, then exits cleanly. Session N+1 starts by reading the handoff file before doing anything else.&lt;/p&gt;

&lt;p&gt;Each session starts fresh — full context window, no compaction debt. The handoff file is the only continuity mechanism, so it must be complete. This forces explicit articulation of state that might otherwise be assumed to be "in context."&lt;/p&gt;

&lt;p&gt;The segmentation boundary should align with natural task phases. "Complete the schema migration and write a handoff file" is a clean segment. "Do some of the migration and some of the testing" is not.&lt;/p&gt;




&lt;h2&gt;
  
  
  Section 4: Code Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Checkpoint Write — Python
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;write_checkpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;checkpoint_dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Write a phase checkpoint before any context-heavy operation.
    Call this before running tests, reading large files, or invoking sub-agents.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;checkpoint_dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;checkpoint_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;phase&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;timestamp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utcnow&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;constraints&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;constraints&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;decisions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;decisions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{}),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;do_not_touch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;do_not_touch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed_tasks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed_tasks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;in_progress&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;in_progress&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;facts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;facts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{}),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;


&lt;span class="c1"&gt;# Example usage before a database migration phase
&lt;/span&gt;&lt;span class="nf"&gt;write_checkpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;checkpoint_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./outputs/session_checkpoints&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pre_migration&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;constraints&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Use WAL mode for all SQLite writes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No DDL against tenant_registry table — active writes from separate process&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Output files must use snake_case naming convention&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;do_not_touch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tenant_registry&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;auth_tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;decisions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;schema_approach&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;additive_only&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;schema_approach_reason&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;existing consumers cannot handle column removal&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed_tasks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;schema_audit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;backup_verification&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;in_progress&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;column_additions_to_user_profiles&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;facts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;db_path&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/data/production.db&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;backup_verified_at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2026-04-22T09:14:00Z&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Checkpoint Read + Re-Injection — Python
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load_checkpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;checkpoint_dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Load checkpoint at phase start. Re-state all constraints before proceeding.
    This is your recovery path after a compaction event.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;checkpoint_dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;checkpoint_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;FileNotFoundError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No checkpoint found for phase &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;. &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Cannot proceed without known-good state.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

    &lt;span class="c1"&gt;# Emit re-injection block — this goes into the agent's active context
&lt;/span&gt;    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;=== RE-INJECTING STATE FROM CHECKPOINT: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;phase&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; ===&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Timestamp: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;timestamp&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;ACTIVE CONSTRAINTS (must be honored for remaining work):&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;constraints&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  - &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;DO NOT TOUCH:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;do_not_touch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  - &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;KEY DECISIONS:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;decisions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;=== END STATE RE-INJECTION ===&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Compaction Detection — Bash
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# compaction_check.sh&lt;/span&gt;
&lt;span class="c"&gt;# Write a sentinel at task start; verify it at each phase boundary.&lt;/span&gt;
&lt;span class="c"&gt;# If verification fails, trigger re-initialization before proceeding.&lt;/span&gt;

&lt;span class="nv"&gt;SENTINEL_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"./outputs/session_sentinel.txt"&lt;/span&gt;
&lt;span class="nv"&gt;CHECKPOINT_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"./outputs/session_checkpoints"&lt;/span&gt;
&lt;span class="nv"&gt;PHASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;unknown&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

write_sentinel&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;session_id
    &lt;span class="nv"&gt;session_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +%s&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;$$&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$session_id&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SENTINEL_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"SENTINEL_WRITTEN: &lt;/span&gt;&lt;span class="nv"&gt;$session_id&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

verify_sentinel_or_reinit&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SENTINEL_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"COMPACTION_DETECTED: sentinel file missing — running re-initialization"&lt;/span&gt;
        reinitialize_from_checkpoints
        &lt;span class="k"&gt;return &lt;/span&gt;1
    &lt;span class="k"&gt;fi
    &lt;/span&gt;&lt;span class="nb"&gt;local &lt;/span&gt;stored_sentinel
    &lt;span class="nv"&gt;stored_sentinel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SENTINEL_FILE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"SENTINEL_OK: &lt;/span&gt;&lt;span class="nv"&gt;$stored_sentinel&lt;/span&gt;&lt;span class="s2"&gt; — proceeding with phase &lt;/span&gt;&lt;span class="nv"&gt;$PHASE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;0
&lt;span class="o"&gt;}&lt;/span&gt;

reinitialize_from_checkpoints&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"=== COMPACTION RECOVERY: loading all available checkpoints ==="&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;f &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$CHECKPOINT_DIR&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;/checkpoint_&lt;span class="k"&gt;*&lt;/span&gt;.json&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;continue
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"--- Loading: &lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="s2"&gt; ---"&lt;/span&gt;
        python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json, sys
state = json.load(open('&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="s2"&gt;'))
print(f'Phase: {state[&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;phase&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]} @ {state[&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;timestamp&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]}')
print('Constraints:')
for c in state.get('constraints', []):
    print(f'  - {c}')
print('Do not touch:', state.get('do_not_touch', []))
"&lt;/span&gt;
    &lt;span class="k"&gt;done
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"=== RECOVERY COMPLETE — all constraints re-loaded ==="&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# At session start: write_sentinel&lt;/span&gt;
&lt;span class="c"&gt;# At each phase boundary: verify_sentinel_or_reinit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Session Handoff File — Python
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;write_handoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Write a clean handoff file at the end of a session segment.
    The next session reads this before doing any work.
    This file is the ONLY continuity mechanism between sessions.
    It must be complete — assume the next session has zero prior context.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;handoff_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;handoff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;generated_at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utcnow&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;from_session&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;next_session_start_instructions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Read this file completely before any other action. &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;All constraints listed here are active. &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Do not proceed without acknowledging each constraint.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;task_objective&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;objective&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed_this_session&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;next_phase&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;next_phase&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hard_constraints&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;constraints&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;do_not_touch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;do_not_touch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;key_facts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;facts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;open_questions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;open_questions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;known_risks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;known_risks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handoff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Handoff written to: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Next session must read: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;


&lt;span class="c1"&gt;# Example: end of session 1 of a multi-session migration
&lt;/span&gt;&lt;span class="nf"&gt;write_handoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;output_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./outputs&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;migration_s1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;next_session_instructions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;objective&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Complete user profile schema migration and deploy to staging&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Schema audit complete — findings in outputs/schema_audit.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Backup verified — outputs/backup_verification.md&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Column additions to user_profiles — migration script at migrations/002_add_profile_fields.sql&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;next_phase&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Run migration against staging, execute integration test suite, write test report&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;constraints&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No DDL against tenant_registry — active concurrent writes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Migration must be additive only — no column drops&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Staging deploy requires RAILS_ENV=staging explicitly set&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;do_not_touch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tenant_registry&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;auth_tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;legacy_session_keys&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;facts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;staging_db&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;postgres://staging-host:5432/app_staging&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;migration_tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;alembic&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;test_suite&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pytest tests/integration/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected_test_count&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;known_risks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Test DB may have stale fixtures — run pytest --setup-show to verify fixture state&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Architecture in Summary
&lt;/h2&gt;

&lt;p&gt;Compaction is not a bug to work around. It is a fundamental constraint of context-window-bounded agents. The architecture that survives it is one that treats the conversation as ephemeral and the filesystem as the ground truth.&lt;/p&gt;

&lt;p&gt;Checkpoint writes externalize state before it can be lost. Re-injection restores full context after a compaction event. Detection lets you verify that the context you're operating from is complete. Session segmentation eliminates compaction debt entirely for long tasks by resetting the window at phase boundaries.&lt;/p&gt;

&lt;p&gt;None of these patterns are expensive. A checkpoint file write takes milliseconds. A re-injection read adds a few hundred tokens to the current context. The compaction detection sentinel is a single file read. A handoff file is twenty lines of JSON.&lt;/p&gt;

&lt;p&gt;The cost of not using them is the kind of failure that doesn't announce itself — an agent that proceeds confidently from a state it believes is correct, into work that violates a constraint it no longer remembers.&lt;/p&gt;




&lt;p&gt;I packaged the full compaction-resistant architecture — detection hooks, checkpoint templates, re-injection patterns, and session handoff schemas — as a ClawMart skill: &lt;a href="https://www.shopclawmart.com/listings/agent-compaction-architecture-production-context-management-5aaff79a" rel="noopener noreferrer"&gt;Agent Compaction Architecture — Production Context Management&lt;/a&gt;. If you're running Claude Code agents on anything longer than a twenty-minute task, it's worth the read.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;~K¹ (W. Kyle Million) / IntuiTek¹ — Building autonomous AI infrastructure for solo operators.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Tags:&lt;/strong&gt; claudecode, devtools, aiagents&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>devtools</category>
      <category>aiagents</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The Complete Agent Operations Stack: 15 Skills for Production-Grade Claude Code</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Wed, 22 Apr 2026 13:09:21 +0000</pubDate>
      <link>https://dev.to/thebrierfox/the-complete-agent-operations-stack-15-skills-for-production-grade-claude-code-569h</link>
      <guid>https://dev.to/thebrierfox/the-complete-agent-operations-stack-15-skills-for-production-grade-claude-code-569h</guid>
      <description>&lt;p&gt;Every week this week I've published articles about individual production patterns for Claude Code: loop termination, session memory, memory scoping, coordinator resume, bash security. Each one addresses a specific failure mode that doesn't exist in demos but shows up immediately when you run agents unattended.&lt;/p&gt;

&lt;p&gt;This article ties them together. It's the reference architecture I wish existed when I started building autonomous agents — before I had agents burning API budget in infinite retry loops, corrupting each other's work, or silently writing partial output that looked complete.&lt;/p&gt;

&lt;p&gt;The gap between "works in a demo" and "runs for 30 days without intervention" is not about model quality. It's about the five layers of production readiness that Claude Code tutorials don't cover, because tutorials show the happy path.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Production Gap
&lt;/h2&gt;

&lt;p&gt;Here's what a Claude Code demo looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User: "Write a report on X"
Agent: [reads files, synthesizes, writes output]
Done.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what production looks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The agent runs at 2am via cron with no one watching&lt;/li&gt;
&lt;li&gt;It hits a network error on step 12 of 30 and retries 80 times&lt;/li&gt;
&lt;li&gt;Two instances start simultaneously and overwrite each other's context files&lt;/li&gt;
&lt;li&gt;The context window hits its limit mid-task and the next session has no idea where it left off&lt;/li&gt;
&lt;li&gt;A sub-agent writes a bash command that touches a path it shouldn't&lt;/li&gt;
&lt;li&gt;The coordinator that dispatched three agents loses its session and restarts all three&lt;/li&gt;
&lt;li&gt;The agent finishes successfully but consumed 6x the expected API budget because it loaded the same large file 40 times&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these are model failures. They're infrastructure failures. The model did exactly what it was instructed to do. The architecture didn't account for the environment the model runs in.&lt;/p&gt;

&lt;p&gt;The five layers below are the minimum viable production architecture for any Claude Code agent that runs unattended.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Five Layers of Production Readiness
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Layer 1: Security
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What can go wrong:&lt;/strong&gt; An agent with broad Bash tool access will, eventually, execute a command in a way you didn't anticipate. Maybe it interpolates a variable into a shell command unsafely. Maybe it runs &lt;code&gt;rm -rf&lt;/code&gt; on a path that turns out to be wrong. Maybe it writes credentials to a log file. In production environments, an unvalidated bash execution surface is an incident waiting to happen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The skills that address this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Bash Security Validator&lt;/em&gt; catches the class of vulnerabilities that come from how agents construct shell commands: unquoted variables, command injection via interpolation, unsafe redirects, pipes to &lt;code&gt;eval&lt;/code&gt;. This isn't static analysis on your code — it's a validation layer that runs between the agent's intent and the shell.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Production Agent Security Hardening&lt;/em&gt; addresses the broader surface: what tools the agent can access, which paths it's allowed to write, how credentials are handled, and what happens when a security boundary is tested. The hardening architecture covers tool allowlists, path restrictions, and audit logging for security-relevant operations.&lt;/p&gt;

&lt;p&gt;Without this layer, you're running an agent that has the same access as a logged-in user and considerably less judgment about when to use it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure signature:&lt;/strong&gt; Agent executes &lt;code&gt;rm -rf&lt;/code&gt; on a wrong path. Agent leaks an environment variable into an output file. Agent constructs a SQL query via string interpolation and hits an injection on unexpected input.&lt;/p&gt;




&lt;h3&gt;
  
  
  Layer 2: Memory
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What can go wrong:&lt;/strong&gt; Claude Code agents have excellent in-context reasoning. They have zero built-in persistence. When the context window ends — whether from a limit, a compaction, or a cron schedule firing a fresh session — everything the agent learned, decided, and discovered is gone. The next session starts from scratch.&lt;/p&gt;

&lt;p&gt;At scale, this produces three distinct failure patterns: repeated discovery (re-doing work already done), decision context loss (making a conflicting choice because the constraint that ruled it out is no longer in context), and progress tracking failure (processing the same files twice because there's no record of what was already processed).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The skills that address this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Agent Memory Scoping&lt;/em&gt; handles the concurrent case: when two agents run simultaneously, they need isolated memory namespaces. The pattern uses agent-scoped working directories, explicit lock protocols for shared coordination files, and memory category taxonomy (exclusive / shared-read / coordination / output). Without this, concurrent agents corrupt each other's working state.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Session Memory Architecture&lt;/em&gt; handles the temporal case: single agents running across multiple context windows. The pattern uses structured session memory files with explicit categories (Decisions, Progress, Discoveries, Next Session Start) that the agent writes during execution and reads at session start to resume coherently.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Agent Compaction Architecture&lt;/em&gt; handles the context pressure case: an agent operating near its context limit needs to proactively write out critical context before compaction removes it. This isn't reactive — it's built into the agent's operating protocol. The agent maintains a rolling summary of durable knowledge so that compaction events don't cause knowledge loss.&lt;/p&gt;

&lt;p&gt;All three of these address the same root problem from different angles: context is not memory, and production agents need persistent memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure signature:&lt;/strong&gt; Agent re-processes files it already completed. Agent makes a decision that contradicts a constraint established in a previous session. Two concurrent agents write to the same path and one loses its work.&lt;/p&gt;




&lt;h3&gt;
  
  
  Layer 3: Flow Control
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What can go wrong:&lt;/strong&gt; An uncontrolled agent will pursue its goal until it either succeeds or exhausts resources. With no circuit breaker, a stuck agent retries indefinitely. With no coordinator state, a multi-agent pipeline loses track of what's been dispatched. With no fork management, spawned sub-agents run without supervision and their outputs aren't collected reliably.&lt;/p&gt;

&lt;p&gt;This layer is where most production incidents live, because flow control failures are expensive and hard to detect from the outside.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The skills that address this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Loop Termination Architecture&lt;/em&gt; implements the circuit breaker pattern at three levels: a step counter (hard limit that stops runaway loops), an error accumulation counter (smart limit that stops stuck loops retrying the same error class), and a goal proximity check (semantic limit that stops false progress spirals). The article earlier this week goes deep on this pattern.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Coordinator Resume Integrity&lt;/em&gt; handles the multi-agent orchestration case: a coordinator agent that dispatches sub-agents must maintain a persistent dispatch ledger so that if the coordinator's session ends mid-pipeline, the next coordinator session can resume from exactly where it left off — skipping completed tasks and re-running only what's still pending.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Forked Agent Architecture&lt;/em&gt; handles the sub-agent lifecycle case: when you fork agents to parallelize work, you need patterns for launching them cleanly, tracking their completion, handling their failures, and collecting their outputs without conflicts. Forked agents that run unsupervised produce outputs that coordinators can't reliably reconcile.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure signature:&lt;/strong&gt; Agent retries a permission error 150 times before context death. Coordinator restarts a pipeline and re-runs already-completed sub-agents. Forked agents write to conflicting paths and the coordinator reads partial output.&lt;/p&gt;




&lt;h3&gt;
  
  
  Layer 4: Cost
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What can go wrong:&lt;/strong&gt; Token cost is invisible until it isn't. An agent that runs correctly but inefficiently can cost 5-10x what it should. Common causes: loading large context files repeatedly instead of once, using the heaviest model for tasks that don't require it, loading all available tools when only two are needed, and the classic — a stuck loop burning API budget on retry calls that will never succeed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The skills that address this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Token Cost Intelligence&lt;/em&gt; gives your agents awareness of their own cost. The pattern covers context window accounting, file loading strategies (don't load a 50KB file on every step when you can load it once and reference relevant sections), and prompt construction patterns that achieve the same output with significantly less input. For a cron-scheduled agent running 20 times a day, a 40% cost reduction compounds quickly.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Multi-Agent Coordination Architecture&lt;/em&gt; addresses the cost dimension of multi-agent systems: routing tasks to the right-sized agent, avoiding redundant computation across parallel agents, and structuring coordination messages to minimize the context each agent needs to carry. In a multi-agent system, coordination overhead is a real cost. Designing coordination contracts that are minimal without being ambiguous is a cost optimization.&lt;/p&gt;

&lt;p&gt;Both of these connect to the model routing tier principle: use local inference for classification and routing tasks, Haiku for structured tasks with clear success criteria, and Sonnet for the work that actually requires it. Token Cost Intelligence gives you the framework to implement this systematically rather than ad-hoc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure signature:&lt;/strong&gt; Agent loads a 100KB config file 40 times across a session. Coordinator passes the full context of each sub-agent to every other sub-agent. Sonnet is used to determine whether a string contains the word "error."&lt;/p&gt;




&lt;h3&gt;
  
  
  Layer 5: Setup and Observability
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What can go wrong:&lt;/strong&gt; Agents fail silently. They write outputs that look complete but aren't. They encounter environment issues (missing tools, wrong paths, stale credentials) that they handle by proceeding without the missing piece. By the time you notice, you have a week of bad outputs and no log trail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The skills that address this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Claude Code Setup Validation&lt;/em&gt; runs preflight checks before any substantive agent work: are required tools available, are expected paths writable, do credentials resolve, are environment variables populated. Validation failures produce clear error messages and halt execution before wasted work. The alternative is discovering that &lt;code&gt;jq&lt;/code&gt; isn't installed at step 40 of a 50-step pipeline.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Context Death Spiral Prevention&lt;/em&gt; addresses a specific failure mode that compounds other problems: an agent approaching context exhaustion starts making progressively worse decisions as it has less context available. The spiral is: reduced context → worse decisions → more work needed → more context consumed. The pattern installs early warning checks and graceful degradation protocols so agents operating near context limits write out state and stop rather than continuing in a degraded state.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Agent Bash Safety&lt;/em&gt; provides the baseline for safe shell operations: patterns for safe variable quoting, command construction, error handling, and exit code propagation. This is the entry-level version of the Bash Security Validator — appropriate for agents where security hardening isn't the primary concern but basic shell hygiene is.&lt;/p&gt;




&lt;h2&gt;
  
  
  Suggested Adoption Order
&lt;/h2&gt;

&lt;p&gt;If you're starting from scratch, adopt in this sequence. The order is based on risk mitigation impact — the earlier items catch the most expensive failure modes first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 1 — Foundation:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Agent Bash Safety&lt;/em&gt; (free) — install baseline shell hygiene before anything else runs&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Context Death Spiral Prevention&lt;/em&gt; (free) — protect your first agents from the most disorienting failure mode&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Claude Code Setup Validation&lt;/em&gt; — run preflight before any production deployment&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Loop Termination Architecture&lt;/em&gt; — your agents will hit loops before they hit any other problem&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Week 2 — Multi-session and concurrent:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Session Memory Architecture&lt;/em&gt; — required the moment any task spans more than one session&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Agent Memory Scoping&lt;/em&gt; — required the moment you run more than one agent at a time&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Agent Compaction Architecture&lt;/em&gt; — required for any long-running task&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Week 3 — Multi-agent:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Coordinator Resume Integrity&lt;/em&gt; — required for any orchestrated pipeline&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Forked Agent Architecture&lt;/em&gt; — required when you parallelize&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Week 4 — Cost and security:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Token Cost Intelligence&lt;/em&gt; — implement once agents are running correctly&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Multi-Agent Coordination Architecture&lt;/em&gt; — optimize once the baseline architecture is stable&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Bash Security Validator&lt;/em&gt; — harden once you understand your attack surface&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Production Agent Security Hardening&lt;/em&gt; — full hardening after you've mapped what the agents actually do&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The principle: get agents running reliably before optimizing cost, and understand what agents do before hardening security.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Full Stack in Practice
&lt;/h2&gt;

&lt;p&gt;To make the architecture concrete, here's a complete autonomous content publishing agent and which of the 15 skills it engages at each stage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The agent:&lt;/strong&gt; runs every morning, drafts a dev.to article based on the week's activity log, reviews it against content standards, and queues it for publication.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;09:00 — Cron fires run_task.sh
    |
    └── [Setup Validation] ← preflight: DEVTO_API_KEY present? jq installed?
                              outputs/working/ writable? network resolves?
        |
        └── PASS → agent starts
            FAIL → log to errors.log, notify via Telegram, exit 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;09:00:05 — Agent reads context
    |
    └── [Session Memory Architecture] ← read working/content_agent/session_memory.md
                                         resume from last "Next Session Start" marker
                                         apply decisions: "Do not republish articles from week of 04-14"
        |
        └── [Agent Memory Scoping] ← workspace: working/content_agent_20260422_090000/
                                      no conflict with any other running agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;09:00:30 — Agent reads activity log and begins drafting
    |
    └── [Token Cost Intelligence] ← activity log is 200KB total
                                     load only entries from last 7 days (12KB)
                                     don't reload on each step — reference the loaded chunk
        |
        └── [Agent Bash Safety] ← any shell ops use quoted variables, set -euo pipefail
                                    no dynamic command construction from log data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;09:03:00 — Article draft complete, beginning review pass
    |
    └── [Loop Termination Architecture] ← step counter: 30 steps max
                                           error counter: 3 identical errors → stop
                                           review pass has its own step budget (10 steps)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;09:04:00 — Agent attempts to queue article via ClawMart API
    |
    └── [Bash Security Validator] ← API key interpolated into curl command
                                     validator confirms: key is quoted, no injection surface
        |
        └── [Production Agent Security Hardening] ← API key not logged
                                                      credential not written to working files
                                                      audit entry: "API call to ClawMart at 09:04:02"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;09:04:20 — Task complete
    |
    └── [Session Memory Architecture] ← append to session_memory.md:
                                          "COMPLETED: article_20260422 queued for publication"
                                          "Next Session Start: check publication status, then draft next article"
        |
        └── [Context Death Spiral Prevention] ← context usage at 34% — well within safe zone
                                                  no degradation warning needed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;09:04:25 — Agent exits clean
    |
    └── outputs/article_20260422_queue.md written
        logs/heartbeat.log timestamp updated
        Telegram: "Content agent complete → article queued for 09:00 publish"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At every stage, a failure in the pattern it depends on would have produced a different outcome:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Without Setup Validation: agent discovers missing jq at step 15, produces garbled output, no error logged&lt;/li&gt;
&lt;li&gt;Without Session Memory: agent re-drafts articles from weeks already covered&lt;/li&gt;
&lt;li&gt;Without Token Cost Intelligence: agent loads the full 200KB activity log on every step, 3x cost&lt;/li&gt;
&lt;li&gt;Without Loop Termination: if ClawMart API returns 503, agent retries until context death&lt;/li&gt;
&lt;li&gt;Without Bash Security Validator: API key interpolated into a log message that persists in working files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The 15 skills are not independent optimizations. They're a layered architecture where each layer assumes the layers below it are in place.&lt;/p&gt;




&lt;h2&gt;
  
  
  Getting the Full Stack
&lt;/h2&gt;

&lt;p&gt;Each skill is available individually. The day one articles this week cover the $19 individual skills in depth.&lt;/p&gt;

&lt;p&gt;The entry point is two free skills that have no dependencies and install immediately:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Context Death Spiral Prevention&lt;/em&gt; — free, no prerequisites&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Agent Bash Safety&lt;/em&gt; — free, no prerequisites&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The mid-tier bundle covers the five patterns that most production deployments need first:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Production Agent Ops Bundle — $69&lt;/strong&gt; (Bash Security Validator, Loop Termination, Session Memory, Agent Memory Scoping, Token Cost Intelligence)&lt;/p&gt;

&lt;p&gt;The complete architecture — all 15 skills as a cohesive production system with integration documentation and ordering guidance — is available as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complete Agent Operations Pack — $199&lt;/strong&gt;&lt;br&gt;
All 15 skills. Integration guide. Adoption sequence documentation. CLAUDE.md template library covering all five layers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.shopclawmart.com/listings/complete-agent-operations-pack-10-skill-production-architecture-suite-5e5fa6e1" rel="noopener noreferrer"&gt;https://www.shopclawmart.com/listings/complete-agent-operations-pack-10-skill-production-architecture-suite-5e5fa6e1&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Honest Assessment
&lt;/h2&gt;

&lt;p&gt;Most Claude Code projects don't need all 15 skills. A single-agent script that runs once and is watched by a human needs almost none of them.&lt;/p&gt;

&lt;p&gt;The production architecture pays off when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The agent runs unattended (cron, headless &lt;code&gt;-p&lt;/code&gt; mode, no human watching)&lt;/li&gt;
&lt;li&gt;The agent runs repeatedly (scheduled, not one-shot)&lt;/li&gt;
&lt;li&gt;More than one agent runs at a time&lt;/li&gt;
&lt;li&gt;Failures have downstream consequences (customer-facing, financial, not easily reversible)&lt;/li&gt;
&lt;li&gt;API cost is a real constraint, not a rounding error&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any of those describe your deployment, the gap between "works in a demo" and "runs reliably for 30 days" is exactly what these 15 skills close.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built by Aegis, IntuiTek¹ | ~K¹ (W. Kyle Million)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tags: claudecode, devtools, aiagents, productivity&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>devtools</category>
      <category>aiagents</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Token Cost Intelligence: How I Route Claude Code Model Calls to Cut API Costs 60%</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Wed, 22 Apr 2026 13:09:10 +0000</pubDate>
      <link>https://dev.to/thebrierfox/token-cost-intelligence-how-i-route-claude-code-model-calls-to-cut-api-costs-60-2dic</link>
      <guid>https://dev.to/thebrierfox/token-cost-intelligence-how-i-route-claude-code-model-calls-to-cut-api-costs-60-2dic</guid>
      <description>&lt;h2&gt;
  
  
  The Problem: One Model for Everything
&lt;/h2&gt;

&lt;p&gt;Here's what a typical Claude Code agent loop looks like under the hood:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User prompt → Claude Sonnet (classify intent) → Claude Sonnet (retrieve context)
→ Claude Sonnet (summarize retrieved docs) → Claude Sonnet (generate response)
→ Claude Sonnet (format output)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Five calls. Each one hitting Sonnet. At Claude Sonnet pricing (roughly $3/MTok input, $15/MTok output as of this writing), a moderately complex agent task with 10K input tokens and 2K output tokens per call costs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5 calls × (10K × $0.003 + 2K × $0.015) = 5 × ($0.030 + $0.030) = $0.30 per task run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That sounds small. Run that task 1,000 times a month — which is conservative for an autonomous agent doing repetitive work — and you're at $300/month for one task type.&lt;/p&gt;

&lt;p&gt;Now look at what most of those calls actually need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Classify intent&lt;/strong&gt;: Takes a string, returns a category. This is a pattern-matching problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retrieve context&lt;/strong&gt;: String similarity search. No synthesis required.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Summarize retrieved docs&lt;/strong&gt;: Compression of existing text. No novel reasoning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generate response&lt;/strong&gt;: This one actually needs intelligence.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Format output&lt;/strong&gt;: String transformation. Deterministic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Three of five calls don't need Sonnet. One of them (classify intent, format output) doesn't need any API call at all — a local model running at zero marginal cost handles them fine.&lt;/p&gt;

&lt;p&gt;That's the routing opportunity.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Routing Principle
&lt;/h2&gt;

&lt;p&gt;Before dispatching a subtask to any model, answer three questions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Does this require judgment or just processing?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Judgment tasks: synthesis, creative generation, multi-step reasoning, ambiguous interpretation, code generation from requirements, anything where "wrong" is hard to define in advance.&lt;/p&gt;

&lt;p&gt;Processing tasks: classification into fixed categories, text compression/summarization, format conversion, extraction of named entities, boolean routing decisions.&lt;/p&gt;

&lt;p&gt;Judgment → Tier 2 minimum. Processing → Tier 0 or Tier 1 viable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Does it need to be right on the first attempt, or can it retry cheaply?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some subtasks sit on the critical path. If the intent classifier misfires and sends a user to the wrong workflow branch, you pay to recover. If a document summarizer slightly miscondenses something, the downstream step can compensate.&lt;/p&gt;

&lt;p&gt;High-stakes, no-retry → Tier 1 minimum. Low-stakes, recoverable → Tier 0 viable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. What's the token budget for this step?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Local models (Ollama, running Qwen3:14B on iGPU) handle 8-10 tokens/second in my setup. That's fine for 500-token classification tasks. It's not fine for a 20K-token synthesis pass where you need a response in under 30 seconds. Speed constraints push you up the tier ladder regardless of task complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The decision tree:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Is this a synthesis/reasoning/generation task?
├── Yes → Tier 2 (Sonnet) or Tier 3 (Opus) if highest stakes
└── No → Is output correctness recoverable if wrong?
    ├── No → Tier 1 (Haiku) — API quality, cheap
    └── Yes → Is token count under ~2K and latency tolerant?
        ├── Yes → Tier 0 (Ollama local) — zero API cost
        └── No → Tier 1 (Haiku)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Here's the router as a standalone module. The &lt;code&gt;classify()&lt;/code&gt; function takes a task description string and returns a tier integer. &lt;code&gt;get_model()&lt;/code&gt; maps that tier to a model identifier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# model_router.py
&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;enum&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IntEnum&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IntEnum&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;LOCAL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;    &lt;span class="c1"&gt;# Ollama — zero API cost
&lt;/span&gt;    &lt;span class="n"&gt;HAIKU&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;    &lt;span class="c1"&gt;# Claude Haiku 4.5 — cheap, API quality
&lt;/span&gt;    &lt;span class="n"&gt;SONNET&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;   &lt;span class="c1"&gt;# Claude Sonnet — primary work
&lt;/span&gt;    &lt;span class="n"&gt;OPUS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;     &lt;span class="c1"&gt;# Claude Opus — highest stakes only
&lt;/span&gt;
&lt;span class="n"&gt;TIER_MODELS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LOCAL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ollama:qwen3:14b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HAIKU&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;claude-haiku-4-5&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SONNET&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;claude-sonnet-4-5&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OPUS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;claude-opus-4-5&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Task patterns that signal each tier.
# Match order matters: check Tier 0/1 patterns first, 
# fall through to Tier 2 if nothing matches.
&lt;/span&gt;
&lt;span class="n"&gt;LOCAL_PATTERNS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bclassif(y|ication|ier)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\broute\b.*\btask\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bsummariz(e|ation)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bextract\b.*(entity|entities|field|fields|name|date|number)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bformat\b.*(output|json|markdown|csv)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bparse\b.*(string|text|input)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bis this (about|related to|a)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bcategori(ze|zation)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bdetect\b.*(intent|topic|language|sentiment)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\btranslate\b.*(format|schema)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;HAIKU_PATTERNS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bvalidat(e|ion)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bcheck\b.*(schema|format|constraint|rule)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bfilter\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\brank\b.*(list|candidates|results)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bscore\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\byes.{0,10}no\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;        &lt;span class="c1"&gt;# binary decisions
&lt;/span&gt;    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\btrue.{0,10}false\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bshould (i|we|this)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;OPUS_PATTERNS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bcritical\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bhigh.?stakes\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\birreversible\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bproduction (deploy|release|launch)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\bsecurity (audit|review|analysis)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\blegal\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\barchitect(ure)? decision\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Classify a task description string and return the appropriate model tier.
    Conservative by default: unknown tasks get Tier 2 (Sonnet).
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;task_lower&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;# Check Opus patterns first — these override everything
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;OPUS_PATTERNS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;task_lower&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OPUS&lt;/span&gt;

    &lt;span class="c1"&gt;# Check if task clearly fits Local tier
&lt;/span&gt;    &lt;span class="n"&gt;local_matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;LOCAL_PATTERNS&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;task_lower&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;local_matches&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task_lower&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LOCAL&lt;/span&gt;

    &lt;span class="c1"&gt;# Check Haiku tier
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;HAIKU_PATTERNS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;task_lower&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HAIKU&lt;/span&gt;

    &lt;span class="c1"&gt;# Default: Sonnet
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SONNET&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Return the model identifier for the given tier.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;TIER_MODELS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Convenience wrapper: classify + return (tier, model_id).&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;tier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;get_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Injecting this into a Claude Code script:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're running Claude Code in script mode (&lt;code&gt;claude -p&lt;/code&gt;), you typically don't call the API directly — Claude Code handles the model. But if you're orchestrating sub-agent calls via the Anthropic SDK directly (which is common when you have a Claude Code agent spinning up subordinate tasks), the router drops in cleanly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# agent_loop.py
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;anthropic&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;model_router&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;anthropic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Anthropic&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run_subtask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task_description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task_description&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Tier 0: local inference via Ollama (no Anthropic API call)
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tier&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LOCAL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;run_ollama&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ollama:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Tiers 1-3: Anthropic API
&lt;/span&gt;    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;max_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run_ollama&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Call local Ollama endpoint directly.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://localhost:11434/api/generate&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stream&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;60.0&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;response&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Integrating with a Claude Code tool definition:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your agent uses Claude Code's native tool calling, you can route at the tool dispatch layer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# In your tool handler
&lt;/span&gt;&lt;span class="n"&gt;TOOL_TIER_OVERRIDES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;classify_intent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LOCAL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;summarize_document&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LOCAL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;extract_fields&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;LOCAL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;validate_schema&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HAIKU&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rank_candidates&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HAIKU&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;generate_code&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;       &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SONNET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;synthesize_findings&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SONNET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;review_security&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="n"&gt;Tier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OPUS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;dispatch_tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tool_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tool_input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Use hard-coded override if known, otherwise classify from tool_name
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tool_name&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;TOOL_TIER_OVERRIDES&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;tier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;TOOL_TIER_OVERRIDES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tool_name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;tier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tool_name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tool_input&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# ... dispatch to appropriate model
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Real Numbers
&lt;/h2&gt;

&lt;p&gt;Here's the actual breakdown from my autonomous agent infrastructure, running a mix of ClawMart listing maintenance, content generation, and ACE license delivery tasks over a 30-day period.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before routing — all tasks on Sonnet:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task type&lt;/th&gt;
&lt;th&gt;Calls/day&lt;/th&gt;
&lt;th&gt;Avg tokens (in/out)&lt;/th&gt;
&lt;th&gt;Daily cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Intent classification&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;td&gt;800 / 50&lt;/td&gt;
&lt;td&gt;$0.32&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Document summarization&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;3,200 / 400&lt;/td&gt;
&lt;td&gt;$0.44&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Field extraction&lt;/td&gt;
&lt;td&gt;80&lt;/td&gt;
&lt;td&gt;600 / 120&lt;/td&gt;
&lt;td&gt;$0.20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Schema validation&lt;/td&gt;
&lt;td&gt;60&lt;/td&gt;
&lt;td&gt;400 / 80&lt;/td&gt;
&lt;td&gt;$0.13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Content generation&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;2,000 / 1,500&lt;/td&gt;
&lt;td&gt;$0.29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Code synthesis&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;4,000 / 2,000&lt;/td&gt;
&lt;td&gt;$0.42&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;325&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$1.80/day ($54/mo)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;After routing:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task type&lt;/th&gt;
&lt;th&gt;Tier&lt;/th&gt;
&lt;th&gt;Daily cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Intent classification&lt;/td&gt;
&lt;td&gt;0 (Ollama)&lt;/td&gt;
&lt;td&gt;$0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Document summarization&lt;/td&gt;
&lt;td&gt;0 (Ollama)&lt;/td&gt;
&lt;td&gt;$0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Field extraction&lt;/td&gt;
&lt;td&gt;0 (Ollama)&lt;/td&gt;
&lt;td&gt;$0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Schema validation&lt;/td&gt;
&lt;td&gt;1 (Haiku)&lt;/td&gt;
&lt;td&gt;~$0.004&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Content generation&lt;/td&gt;
&lt;td&gt;2 (Sonnet)&lt;/td&gt;
&lt;td&gt;$0.29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Code synthesis&lt;/td&gt;
&lt;td&gt;2 (Sonnet)&lt;/td&gt;
&lt;td&gt;$0.42&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~$0.71/day ($21/mo)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That's a 61% reduction. The tasks that stayed on Sonnet are exactly the ones that need it: novel content generation and code synthesis. The tasks that moved to Tier 0 are pure pattern matching and compression — Qwen3:14B handles them cleanly, and at 8-10 tokens/second locally, they complete fast enough that latency isn't a constraint.&lt;/p&gt;

&lt;p&gt;A few observations from running this in production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Classification accuracy on Tier 0 is high for constrained tasks.&lt;/strong&gt; When the output space is a small fixed set of categories, Qwen3:14B makes fewer errors than you'd expect. The failure mode is ambiguous prompts, not model capability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Haiku 4.5 is underused by most teams.&lt;/strong&gt; It's genuinely capable for structured validation and ranking tasks, and it costs roughly 15x less than Sonnet for input tokens. Most teams skip straight to Sonnet out of habit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The routing classifier itself costs almost nothing.&lt;/strong&gt; My &lt;code&gt;classify()&lt;/code&gt; function is pure regex — no model call, zero latency, zero cost. For more nuanced routing, you can run the classifier on Tier 0 (Ollama) and the cost is still negligible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retry budgets matter.&lt;/strong&gt; I give Tier 0 tasks two retries before escalating to Tier 1. This adds maybe 5% cost but recovers from the edge cases where local inference produces malformed output.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What Breaks Without This
&lt;/h2&gt;

&lt;p&gt;The failure mode I see most often in unrouted agents isn't cost — it's the Sonnet context window filling up with low-value intermediate processing. When your summarization steps run on Sonnet, they compete with your generation steps for context and rate limits. Routing low-value tasks to local inference keeps your Sonnet calls clean and focused on work that actually requires them.&lt;/p&gt;

&lt;p&gt;The second failure mode is rate limit exhaustion. At 325 calls/day against a single model tier, you hit Anthropic's rate limits faster than if you spread load across tiers. Tier distribution is rate limit distribution.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Packaged Framework
&lt;/h2&gt;

&lt;p&gt;The routing logic above is a simplified version of what I built and use in production. The full framework includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pre-trained classifiers for 40+ task types with confidence scores&lt;/li&gt;
&lt;li&gt;Cost tracking that logs actual spend per task type to a local SQLite DB&lt;/li&gt;
&lt;li&gt;A dashboard that shows cost breakdown and tier distribution over time&lt;/li&gt;
&lt;li&gt;Retry logic with automatic tier escalation on failure&lt;/li&gt;
&lt;li&gt;Integration examples for Claude Code scripts, Anthropic SDK, and LangChain&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full Token Cost Intelligence skill is available on ClawMart: &lt;a href="https://www.shopclawmart.com/listings/token-cost-intelligence-openclaw-optimization-framework-a417717e" rel="noopener noreferrer"&gt;Token Cost Intelligence — OpenClaw Optimization Framework&lt;/a&gt; ($29).&lt;/p&gt;

&lt;p&gt;If you're running any Claude Code agents at scale — even moderate scale — the routing framework pays for itself in the first day of usage.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;W. Kyle Million (K¹) builds autonomous AI infrastructure at &lt;a href="https://intuitek.ai" rel="noopener noreferrer"&gt;IntuiTek¹&lt;/a&gt;. The systems described here run continuously on a local X1 Pro, generating revenue without ongoing manual involvement.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>devtools</category>
      <category>aiagents</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The Production Agent Operations Bundle: What 90% of Claude Code Setups Are Missing</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Wed, 22 Apr 2026 13:08:46 +0000</pubDate>
      <link>https://dev.to/thebrierfox/the-production-agent-operations-bundle-what-90-of-claude-code-setups-are-missing-11f5</link>
      <guid>https://dev.to/thebrierfox/the-production-agent-operations-bundle-what-90-of-claude-code-setups-are-missing-11f5</guid>
      <description>&lt;h2&gt;
  
  
  The Five Failure Modes That Hit Real Production Setups
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Context collapse mid-task&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your agent is 35 steps into a 60-step task. It hits context limit. Compaction kicks in. The compacted context drops the specific intermediate state — which file was written, which step was last, what the error on step 28 was. The agent resumes with a reconstructed understanding of where it is, and that reconstruction is wrong. It re-does work, skips work, or produces outputs that contradict the partial work it already completed.&lt;/p&gt;

&lt;p&gt;The compaction is not the problem. The problem is that your agent had no checkpointing — no explicit record of where it was that survives a context reset.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Infinite loops with no circuit breaker&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The task fails. The agent retries. Same failure. Retry. Same failure. The agent will not stop on its own, because stopping is not in its default behavior. It will retry until context exhausts, then compact and retry again. A &lt;code&gt;permission denied&lt;/code&gt; error on step 3 will get retried 80 times before the run terminates. You pay for all 80 retries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Shell injection via unvalidated tool calls&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your agent accepts a task that includes a filename, a query, or a user-supplied string. It passes that string directly to a bash call: &lt;code&gt;os.system(f"process_file.sh {filename}")&lt;/code&gt;. If &lt;code&gt;filename&lt;/code&gt; is &lt;code&gt;file.txt; rm -rf outputs/&lt;/code&gt;, your agent just destroyed your output directory. If it's piped from an external source, the attack surface is real.&lt;/p&gt;

&lt;p&gt;Most Claude Code bash usage never validates inputs before shell execution. Most demos don't catch this because the inputs are controlled. Production inputs are not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Concurrent agents corrupting shared state&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You have two agents running in parallel. Both are writing to &lt;code&gt;outputs/weekly_report.md&lt;/code&gt;. Agent A writes its section. Agent B opens the file, reads the current contents (which includes Agent A's partial write), appends its section, and writes the whole thing back. Agent A writes its next section to the file it still has open, overwriting Agent B's write.&lt;/p&gt;

&lt;p&gt;Non-atomic writes with no locking produce corrupted output with no error. No exception is raised. The file exists. The contents are wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Coordinator handoff losing task state&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your coordinator dispatches three sub-agents, then its session ends — context limit, cron timeout, system interrupt. A new coordinator starts on the next cron tick. It has no idea which sub-agents already completed. It re-dispatches all three. Sub-agent 1 runs again, producing duplicate output. Sub-agent 2 conflicts with its own still-running previous instance. Your pipeline produces wrong results and logs nothing, because there was no failure — just a coordinator that restarted with no memory.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Doesn't Work and Why
&lt;/h2&gt;

&lt;p&gt;The instinct when any of these hits is to add error handling. Wrap things in try/except, add a retry loop, restart on failure. These are patches, not fixes. Here's why each one falls short:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Just add error handling"&lt;/strong&gt; catches exceptions but doesn't solve loop termination. Your retry loop now catches the error and retries indefinitely — you've formalized the infinite loop instead of preventing it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Restart on failure"&lt;/strong&gt; is the coordinator pattern that causes state loss. Each restart wipes context. Without an explicit dispatch ledger written to disk before each sub-agent launch, restart is indistinguishable from a fresh start.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Check output file existence"&lt;/strong&gt; to infer completion has multiple failure modes: partial writes leave valid-looking files, a previous interrupted run may have left a file from a different context, and the same task may need to run multiple times. File existence is a proxy for completion that breaks under real conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Sanitize inputs in the prompt"&lt;/strong&gt; relies on the model to perform security validation. That's not the right layer. Security validation belongs in code that runs before the shell call, not in language model reasoning that runs before the tool call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Use a lock file"&lt;/strong&gt; for concurrent writes is the right idea but is almost always implemented incorrectly — lock files that survive crashes leave all subsequent agents blocked, and there's no cleanup logic because the crash that created the problem also prevented the cleanup.&lt;/p&gt;

&lt;p&gt;The common thread: these fixes address symptoms at the wrong layer. The root causes are architectural — no termination logic, no persistent state, no pre-execution validation, no atomic write semantics.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Five Architecture Patterns That Fix It
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Loop Termination with Circuit Breakers
&lt;/h3&gt;

&lt;p&gt;Every production agent needs termination logic at three levels: a hard step limit, an error accumulation counter, and a goal proximity check.&lt;/p&gt;

&lt;p&gt;The hard limit is the blunt instrument that catches runaway loops:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;MAX_STEPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
&lt;span class="n"&gt;step_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;execute_step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="n"&gt;step_count&lt;/span&gt;
    &lt;span class="n"&gt;step_count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;step_count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;MAX_STEPS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;write_state_checkpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;max steps (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;MAX_STEPS&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;) reached&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;TerminationError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hard limit reached&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;perform_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The error accumulation counter catches stuck loops — agents retrying the same failing operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;error_counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="n"&gt;ERROR_THRESHOLD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;handle_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;error_counts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;error_type&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error_counts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error_counts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;error_type&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;ERROR_THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;write_escalation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BLOCKED: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error_type&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; failed &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error_counts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;error_type&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;x. Context: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;TerminationError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Repeated failure: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error_type&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;retry_with_backoff&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The goal proximity check is the cleanest implementation in Claude Code's native format — a CLAUDE.md protocol that forces the agent to articulate its progress before each action. If it can't state how this action moves toward completion, it writes the blocker to outputs/ and stops.&lt;/p&gt;

&lt;p&gt;Clean termination writes current state, names the blocker, and exits 0 — stopped is not the same as failed.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Memory Isolation for Concurrent Agents
&lt;/h3&gt;

&lt;p&gt;When multiple agents need to read and write shared state, the architecture needs to prevent reads of stale data and prevent concurrent writes from producing corrupted output.&lt;/p&gt;

&lt;p&gt;The pattern is task-local working directories with a merge step, not shared output paths:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shutil&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;agent_working_dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Each agent gets its own isolated scratch space.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;expanduser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;~/intuitek/coordination/scratch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;agent_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;makedirs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;merge_agent_outputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent_ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Coordinator merges after all agents complete — no concurrent writes.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;sections&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;agent_id&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;agent_ids&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;scratch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;agent_working_dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;result_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scratch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;result.md&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result_file&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;sections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;w&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s"&gt;---&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sections&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Agents write to their scratch directory. The coordinator merges when all agents report completion. No two agents write to the same path. No locks needed.&lt;/p&gt;

&lt;p&gt;For shared state that agents genuinely need to read and update concurrently, the pattern is append-only event logs with a read-once merge, not mutable shared files.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Coordinator Resume Integrity
&lt;/h3&gt;

&lt;p&gt;Coordinator state must be written to disk before every sub-agent dispatch. Not after — before. If the coordinator dies between writing the dispatch record and the sub-agent starting, the worst case is a task that gets re-dispatched. If the coordinator dies after dispatch with no record, the worst case is a task that runs twice with no visibility.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dispatch_task&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;TASK_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;TASK_PROMPT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="c"&gt;# Write to ledger before dispatch — not after&lt;/span&gt;
    python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json, datetime
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;') as f: ledger = json.load(f)
ledger['tasks'].append({
    'task_id': '&lt;/span&gt;&lt;span class="nv"&gt;$TASK_ID&lt;/span&gt;&lt;span class="s2"&gt;',
    'status': 'IN_PROGRESS',
    'dispatched_at': datetime.datetime.utcnow().isoformat() + 'Z',
    'completed_at': None
})
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;', 'w') as f: json.dump(ledger, f, indent=2)
"&lt;/span&gt;
    bash ~/intuitek/run_task.sh &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TASK_PROMPT&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &amp;amp;
&lt;span class="o"&gt;}&lt;/span&gt;

startup_coordinator&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
        &lt;span class="c"&gt;# Skip tasks already marked COMPLETE&lt;/span&gt;
        &lt;span class="nv"&gt;PENDING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;') as f: ledger = json.load(f)
pending = [t['task_id'] for t in ledger['tasks'] if t['status'] != 'COMPLETE']
print('&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;'.join(pending))
"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On restart, read the ledger, skip completed tasks, and re-dispatch only what isn't done. Add a heartbeat timestamp to detect abandoned pipelines — if the last heartbeat is more than 5 minutes old and the pipeline is still marked IN_PROGRESS, the previous coordinator died and you can safely take over.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Bash Security Validation Before Shell Execution
&lt;/h3&gt;

&lt;p&gt;Every string that comes from outside your agent's direct control — task inputs, file paths, query parameters, content extracted from external sources — must be validated before it touches a shell call.&lt;/p&gt;

&lt;p&gt;The validation layer runs in Python before the subprocess call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shlex&lt;/span&gt;

&lt;span class="n"&gt;SAFE_FILENAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;^[\w\-\.]+$&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;SAFE_PATH_COMPONENT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;^[\w\-\./]+$&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;safe_shell_exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command_template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Validate all interpolated values before shell execution.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;path&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;file&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;SAFE_PATH_COMPONENT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
                &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SecurityError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Unsafe path in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="si"&gt;!r}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;SAFE_FILENAME&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
                &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SecurityError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Unsafe filename in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="si"&gt;!r}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;command_template&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;shlex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important detail is &lt;code&gt;shlex.split()&lt;/code&gt; rather than passing the command string directly to &lt;code&gt;shell=True&lt;/code&gt;. &lt;code&gt;shell=True&lt;/code&gt; is the vector. &lt;code&gt;shlex.split()&lt;/code&gt; with &lt;code&gt;shell=False&lt;/code&gt; tokenizes the command safely and passes it as an argument list, which prevents shell metacharacter injection even if a value slips through validation.&lt;/p&gt;

&lt;p&gt;For agent-facing tools that accept arbitrary inputs, add a denylist for shell metacharacters as a second layer: &lt;code&gt;;&lt;/code&gt;, &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;$()&lt;/code&gt;, backticks, and &lt;code&gt;&amp;gt;&lt;/code&gt; in unexpected positions are all injection indicators.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Context Compaction Checkpointing
&lt;/h3&gt;

&lt;p&gt;When an agent runs a task that requires more steps than a single context window, it needs to write explicit checkpoints — structured state records that survive compaction and allow resumption at the right point.&lt;/p&gt;

&lt;p&gt;The checkpoint is written before any operation that changes state, and read at session start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;

&lt;span class="n"&gt;CHECKPOINT_PATH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;outputs/checkpoint_{task_id}.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;write_checkpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Call before any state-changing operation.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;checkpoint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;task_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;checkpoint_at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;utcnow&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Z&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed_steps&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completed_steps&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;current_step&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;current_step&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;outputs_written&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;outputs_written&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;context_summary&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;context_summary&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CHECKPOINT_PATH&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;w&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;checkpoint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load_checkpoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CHECKPOINT_PATH&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Claude Code's native CLAUDE.md format, you encode this as an explicit protocol: at the start of every session, check for a checkpoint file matching the current task ID. If found, read it, report where execution left off, and continue from &lt;code&gt;current_step&lt;/code&gt; rather than from the beginning.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;context_summary&lt;/code&gt; field is the most important part. It's a 2-3 sentence summary of what the agent understands about the task state, written in a form that can be injected back into context after compaction. It's not a full transcript — it's the minimum state needed to make the next step coherent.&lt;/p&gt;




&lt;h2&gt;
  
  
  When to Use the Bundle vs. Building From Scratch
&lt;/h2&gt;

&lt;p&gt;Build from scratch if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your agent runs a single short task (under 20 steps) with no concurrent instances&lt;/li&gt;
&lt;li&gt;All inputs are fully controlled — no external sources, no user-supplied strings reaching shell calls&lt;/li&gt;
&lt;li&gt;The agent runs once and terminates; no scheduled re-runs, no coordinator/sub-agent pattern&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use the bundle if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're running agents on a cron schedule where each run may pick up from where the last one left off&lt;/li&gt;
&lt;li&gt;You're running two or more agents in parallel that share any output paths or state&lt;/li&gt;
&lt;li&gt;Any task input — including file paths, query parameters, or content the agent reads from external sources — reaches a bash or subprocess call&lt;/li&gt;
&lt;li&gt;You're building a coordinator that dispatches sub-agents&lt;/li&gt;
&lt;li&gt;You've already hit any of the five failure modes described above&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The patterns aren't complicated individually. The difficulty is in the details: the exact order of operations for a write-before-dispatch ledger, the edge cases in lock file cleanup, the difference between &lt;code&gt;shell=True&lt;/code&gt; and argument list subprocess calls that actually blocks injection. These are the things you debug at 11pm on a Friday when your production agent produced corrupted output and you don't know why.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Honest Take
&lt;/h2&gt;

&lt;p&gt;None of this is new architecture. Circuit breakers, idempotent state machines, input validation, atomic writes — these are standard distributed systems patterns that apply directly to production agent infrastructure.&lt;/p&gt;

&lt;p&gt;The reason most Claude Code setups don't have them is not complexity. It's that the demo works without them, and the failure modes only appear under conditions you don't reproduce locally: concurrent execution, context exhaustion, untrusted inputs, scheduled unattended runs.&lt;/p&gt;

&lt;p&gt;If you're at the point where Claude Code agents are part of your production infrastructure and not just experiments, these patterns are not optional. They're the difference between a setup that works when you're watching and one that works when you're not.&lt;/p&gt;




&lt;p&gt;I packaged all five as a single ClawMart skill bundle — ready to drop into any Claude Code project: &lt;a href="https://www.shopclawmart.com/listings/production-agent-ops-battle-tested-architecture-pack-77a4c935" rel="noopener noreferrer"&gt;https://www.shopclawmart.com/listings/production-agent-ops-battle-tested-architecture-pack-77a4c935&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;$69. Instant download. One-time purchase.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built by Aegis, IntuiTek¹ | ~K¹ (W. Kyle Million)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tags: claudecode, devtools, aiagents, productivity&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>devtools</category>
      <category>aiagents</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Session Memory Architecture: The Pattern That Keeps Your Agent Coherent Across Context Resets</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Wed, 22 Apr 2026 12:08:32 +0000</pubDate>
      <link>https://dev.to/thebrierfox/session-memory-architecture-the-pattern-that-keeps-your-agent-coherent-across-context-resets-32fb</link>
      <guid>https://dev.to/thebrierfox/session-memory-architecture-the-pattern-that-keeps-your-agent-coherent-across-context-resets-32fb</guid>
      <description>&lt;p&gt;Your Claude Code agent ran perfectly for 45 minutes. Built context. Understood the codebase. Made decisions that depended on what it learned in the first 30 minutes.&lt;/p&gt;

&lt;p&gt;Then the context limit hit. The session compacted. Everything the agent learned — the specific file it was tracking, the pattern it identified, the three edge cases it flagged — is gone.&lt;/p&gt;

&lt;p&gt;The next session starts fresh. The agent reads CLAUDE.md, reads the task, and begins again with no knowledge of what the previous session accomplished. It may re-examine files it already processed. It may make different decisions because it's missing context from earlier in the run. It may re-do work that was already done.&lt;/p&gt;

&lt;p&gt;This is session memory failure. It happens every time a long-running agent task spans more than one context window.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem: Context Is Not Memory
&lt;/h2&gt;

&lt;p&gt;Claude Code agents have two very different things that are often confused:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt; — what's in the current session window. Fast to access. Massive reasoning ability. Zero persistence. When the session ends or compacts, it's gone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory&lt;/strong&gt; — what's written to disk. Persists across sessions. Available to any future agent. Zero cognitive cost to preserve; non-zero cost to structure and retrieve.&lt;/p&gt;

&lt;p&gt;Production agents running tasks longer than ~60-90 minutes will exceed their context window. Context compaction removes earlier parts of the session to make room for new work. Even without hitting limits, a cron-scheduled agent that runs every 10 minutes has a fresh context every time.&lt;/p&gt;

&lt;p&gt;Any agent designed to accumulate knowledge in context will fail when that context resets.&lt;/p&gt;

&lt;p&gt;Three failure modes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Repeated discovery&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Agent discovers that &lt;code&gt;auth/middleware.py&lt;/code&gt; contains the auth bug it's tracking. This information exists in context. Next session starts — agent reads the file list again, starts scanning, rediscovers the same bug. 10 minutes of redundant work per reset.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Decision context loss&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Agent decided not to modify &lt;code&gt;config.yaml&lt;/code&gt; because an earlier analysis showed it was used by three other services. That analysis is in compacted context. New session edits &lt;code&gt;config.yaml&lt;/code&gt; without that constraint — introduces a regression.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Progress tracking failure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Agent processed files A through M. Context compacted; that progress is gone. New session starts at A again. By the time it reaches M, it's processed everything twice. Outputs folder has duplicates; no indication which is the final version.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Doesn't Work
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Relying on CLAUDE.md for session state&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CLAUDE.md is for operating instructions, not run-time state. Writing session progress into CLAUDE.md means mixing stable configuration with ephemeral state. It creates noise for every future session and violates the principle that CLAUDE.md should change only with ~K¹ approval.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Writing to outputs/ and re-reading it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Output files are write-once, never-modified by design. Re-reading them on session start to reconstruct state is fragile — the agent has to parse its own prose output to recover structured data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trusting the next session to "figure it out"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It won't. The next session sees only what's on disk plus what's in CLAUDE.md. If session-specific decisions, progress markers, and discovered context aren't explicitly written, they don't exist.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Pattern: Session Memory Files
&lt;/h2&gt;

&lt;p&gt;Each long-running task maintains a &lt;strong&gt;session memory file&lt;/strong&gt; — a structured, append-only log that the agent writes during the session and reads at the start of the next session.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;SESSION_MEM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$INTUITEK&lt;/span&gt;&lt;span class="s2"&gt;/working/&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;TASK_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/session_memory.md"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Session memory file structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Session Memory — task_orders_audit_20260422&lt;/span&gt;

&lt;span class="gu"&gt;## Decisions Made&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; 2026-04-22T07:12Z — DO NOT modify config/auth.yaml — used by 3 services (auth, payments, admin); changing here breaks them all
&lt;span class="p"&gt;-&lt;/span&gt; 2026-04-22T07:23Z — Use optimistic locking for order updates; confirmed with existing lock pattern in orders.py:241

&lt;span class="gu"&gt;## Progress Markers&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; COMPLETED: orders/batch_1/ (files 001-047)
&lt;span class="p"&gt;-&lt;/span&gt; COMPLETED: orders/batch_2/ (files 048-091)
&lt;span class="p"&gt;-&lt;/span&gt; IN_PROGRESS: orders/batch_3/ (files 092-??? — stopped at 094)
&lt;span class="p"&gt;-&lt;/span&gt; PENDING: orders/batch_4/, batch_5/

&lt;span class="gu"&gt;## Key Discoveries&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Order schema has undocumented &lt;span class="sb"&gt;`legacy_id`&lt;/span&gt; field used only by &lt;span class="sb"&gt;`reports/quarterly.py`&lt;/span&gt; — do not remove
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="sb"&gt;`orders/batch_2/order_073.json`&lt;/span&gt; is malformed (truncated at line 14) — log as error, don't process
&lt;span class="p"&gt;-&lt;/span&gt; Pattern: all failed orders have &lt;span class="sb"&gt;`payment_status: null`&lt;/span&gt; before &lt;span class="sb"&gt;`order_status: failed`&lt;/span&gt; — not after

&lt;span class="gu"&gt;## Next Session Start&lt;/span&gt;
On next session start: begin with orders/batch_3/ file 095. Apply decisions above before touching any config.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At session start, the agent reads this file before doing anything else:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;SESSION_PROMPT_PREFIX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SESSION_MEM&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nv"&gt;SESSION_PROMPT_PREFIX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Read &lt;/span&gt;&lt;span class="nv"&gt;$SESSION_MEM&lt;/span&gt;&lt;span class="s2"&gt; first. Apply all decisions and progress markers before starting new work."&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At regular intervals during the session (every 15 minutes or at natural checkpoints), the agent appends to the session memory file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;checkpoint&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;NOTE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"- &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; +%Y-%m-%dT%H:%MZ&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; — &lt;/span&gt;&lt;span class="nv"&gt;$NOTE&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SESSION_MEM&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agent calls &lt;code&gt;checkpoint&lt;/code&gt; when it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Makes a decision that depends on earlier context&lt;/li&gt;
&lt;li&gt;Completes a logical unit of work&lt;/li&gt;
&lt;li&gt;Discovers something that would change how future work proceeds&lt;/li&gt;
&lt;li&gt;Encounters an edge case that needs to be remembered&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Memory Categories Within Session Memory
&lt;/h2&gt;

&lt;p&gt;Not everything deserves the same treatment. Structure your session memory file with explicit sections:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decisions&lt;/strong&gt; — choices made that must constrain future choices. Immutable once written. If a decision needs to change, add a new entry with "SUPERSEDES [date]" — never modify old entries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Progress&lt;/strong&gt; — what's been done. Updated as work completes. Enables skipping already-completed work on resume.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discoveries&lt;/strong&gt; — facts about the domain that weren't known before this session. Information that future sessions need to make correct decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next Session Start&lt;/strong&gt; — a single paragraph written at the end of each session summarizing the exact next step. This is what the next session reads first.&lt;/p&gt;




&lt;h2&gt;
  
  
  Automatic Memory on Compaction
&lt;/h2&gt;

&lt;p&gt;Claude Code's context compaction removes older messages. Build compaction awareness into your agent's operating instructions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## Session Memory Protocol (in CLAUDE.md or task prompt)&lt;/span&gt;

Before context compacts or session ends:
&lt;span class="p"&gt;1.&lt;/span&gt; Write current progress to working/{task_id}/session_memory.md
&lt;span class="p"&gt;2.&lt;/span&gt; Record any decisions made in the last 30 minutes that aren't yet in session_memory.md
&lt;span class="p"&gt;3.&lt;/span&gt; Update "Next Session Start" section with the exact next action
&lt;span class="p"&gt;4.&lt;/span&gt; Write completion status of current logical unit to session_memory.md

On session start:
&lt;span class="p"&gt;1.&lt;/span&gt; Read working/{task_id}/session_memory.md if it exists
&lt;span class="p"&gt;2.&lt;/span&gt; Apply all decisions without re-evaluating them
&lt;span class="p"&gt;3.&lt;/span&gt; Start from the progress marker labeled "Next Session Start"
&lt;span class="p"&gt;4.&lt;/span&gt; Do not re-do work marked as COMPLETED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Multi-Session Task Completion
&lt;/h2&gt;

&lt;p&gt;When the full task completes across multiple sessions, the session memory file becomes the audit trail:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;finalize_session_memory&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SESSION_MEM&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"## TASK COMPLETE — &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; +%Y-%m-%dT%H:%MZ&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SESSION_MEM&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Final status: all batches processed."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SESSION_MEM&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="c"&gt;# Archive to outputs/ for the permanent record&lt;/span&gt;
    &lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SESSION_MEM&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$INTUITEK&lt;/span&gt;&lt;span class="s2"&gt;/outputs/session_memory_final_&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;TASK_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.md"&lt;/span&gt;

    &lt;span class="c"&gt;# Session workspace can be cleaned up&lt;/span&gt;
    &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$INTUITEK&lt;/span&gt;&lt;span class="s2"&gt;/working/&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;TASK_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Production Implementation
&lt;/h2&gt;

&lt;p&gt;The patterns above are the core architecture. The production implementation includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Session memory file factory with schema enforcement&lt;/li&gt;
&lt;li&gt;Checkpoint writer with automatic section routing (Decisions / Progress / Discoveries)&lt;/li&gt;
&lt;li&gt;Session startup reader with progress state reconstruction&lt;/li&gt;
&lt;li&gt;Compaction-aware CLAUDE.md template blocks for embedding memory protocol in agent prompts&lt;/li&gt;
&lt;li&gt;Multi-session task tracker (start / resume / complete state machine)&lt;/li&gt;
&lt;li&gt;Finalization handler with output archival and workspace cleanup&lt;/li&gt;
&lt;li&gt;Cross-session decision log with supersede detection (prevents conflicting decisions)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Session Memory Architecture — Production Context Persistence:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.shopclawmart.com/listings/session-memory-architecture-production-context-persistence-b2e36e13" rel="noopener noreferrer"&gt;https://www.shopclawmart.com/listings/session-memory-architecture-production-context-persistence-b2e36e13&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;$19. Instant download. One-time purchase.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built by Aegis, IntuiTek¹ | ~K¹ (W. Kyle Million)&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>devtools</category>
      <category>aiagents</category>
      <category>programming</category>
    </item>
    <item>
      <title>Coordinator Resume Integrity: What Happens When a Claude Code Agent Loses Its Mind Mid-Handoff</title>
      <dc:creator>~K¹yle Million</dc:creator>
      <pubDate>Wed, 22 Apr 2026 12:08:22 +0000</pubDate>
      <link>https://dev.to/thebrierfox/coordinator-resume-integrity-what-happens-when-a-claude-code-agent-loses-its-mind-mid-handoff-o46</link>
      <guid>https://dev.to/thebrierfox/coordinator-resume-integrity-what-happens-when-a-claude-code-agent-loses-its-mind-mid-handoff-o46</guid>
      <description>&lt;p&gt;Your coordinator agent dispatched three sub-agents. Sub-agent 1 finished. Sub-agent 2 is halfway through. Sub-agent 3 hasn't started yet.&lt;/p&gt;

&lt;p&gt;Then your coordinator's session ends. Context limit hit. Cron killed the process. Doesn't matter why — the coordinator is gone.&lt;/p&gt;

&lt;p&gt;Next cron tick, a new coordinator starts. It doesn't know Sub-agent 1 is done. It doesn't know Sub-agent 2 is mid-task. It restarts all three.&lt;/p&gt;

&lt;p&gt;Sub-agent 1 runs again, producing duplicate output. Sub-agent 2 conflicts with itself. Sub-agent 3 finally starts — after two unnecessary reruns. Your pipeline produced wrong results with no error, because the coordinator had no way to resume from where it left off.&lt;/p&gt;

&lt;p&gt;This is coordinator resume integrity failure. It's the most common reason multi-agent pipelines produce inconsistent results under real operating conditions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Coordinators Fail to Resume
&lt;/h2&gt;

&lt;p&gt;The coordinator's state — which tasks it dispatched, which completed, what still needs to run — lives entirely in context. That context is not written anywhere. When the session ends, it's gone.&lt;/p&gt;

&lt;p&gt;Most agents are written assuming they'll run to completion in a single session. That assumption holds in development where you're watching, but breaks in production where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sessions end unpredictably (context limits, cron timeouts, system interrupts)&lt;/li&gt;
&lt;li&gt;The same agent runs on a schedule, not once&lt;/li&gt;
&lt;li&gt;Downstream work takes longer than the coordinator's execution window&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Three specific failure modes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Duplicate execution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Coordinator resumes with no state. Re-dispatches all sub-agents. Sub-agents that already completed run again. If sub-agents write to fixed paths, the second run overwrites the first. If they write to unique paths, you accumulate duplicates with no way to know which is canonical.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Partial completion invisible to the next coordinator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sub-agent 2 is 40% through its task. New coordinator restarts it from zero. Sub-agent 2's partial output — which may have taken significant time and API usage — is abandoned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Ordering violations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Coordinator was enforcing an execution order: A before B before C. New coordinator starts all three simultaneously. B runs before A has committed its output. B reads stale data.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Doesn't Work
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Checking output files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Coordinators often check for output file existence to infer completion: "if &lt;code&gt;outputs/task_A.md&lt;/code&gt; exists, A is done." This breaks when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A partial write left the file in an invalid state&lt;/li&gt;
&lt;li&gt;A previous interrupted run left a file from a different context&lt;/li&gt;
&lt;li&gt;The same task needs to run multiple times across different runs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reading sub-agent logs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sub-agent logs tell you what happened inside that sub-agent's run. They don't tell the coordinator what the coordinator already dispatched, or whether that dispatch was intended for this run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trusting context to persist&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Context doesn't persist across sessions. Period. Anything the coordinator knows that isn't written to disk is lost on session end.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Pattern: Explicit Dispatch Ledger
&lt;/h2&gt;

&lt;p&gt;Every coordinator maintains a &lt;strong&gt;dispatch ledger&lt;/strong&gt; — a structured file that records what was dispatched, when, and what state it's in. The ledger is written before dispatch, updated on completion, and read first on every coordinator startup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;LEDGER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$INTUITEK&lt;/span&gt;&lt;span class="s2"&gt;/coordination/dispatch_ledger_&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PIPELINE_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.json"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ledger schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"pipeline_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pipeline_orders_20260422_070001"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"coordinator_started"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-04-22T07:00:01Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"last_coordinator_heartbeat"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-04-22T07:04:17Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tasks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"task_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"agent_order_1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"COMPLETE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"dispatched_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-04-22T07:00:05Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"completed_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-04-22T07:02:31Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"output_path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"outputs/order_1_result_20260422.md"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"task_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"agent_order_2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"IN_PROGRESS"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"dispatched_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-04-22T07:00:06Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"completed_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"output_path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"task_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"agent_order_3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"PENDING"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"dispatched_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"completed_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"output_path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Coordinator startup sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;startup_coordinator&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
        &lt;span class="c"&gt;# Resume from existing ledger&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Resuming pipeline: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.pipeline_id'&lt;/span&gt; &lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="nv"&gt;RESUME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true
    &lt;/span&gt;&lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="c"&gt;# Initialize new ledger&lt;/span&gt;
        python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json, datetime
ledger = {
    'pipeline_id': 'pipeline_&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;PIPELINE_TYPE&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;_&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +%Y%m%d_%H%M%S&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;',
    'coordinator_started': datetime.datetime.utcnow().isoformat() + 'Z',
    'last_coordinator_heartbeat': datetime.datetime.utcnow().isoformat() + 'Z',
    'tasks': []
}
print(json.dumps(ledger, indent=2))
"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="nv"&gt;RESUME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false
    &lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before dispatching any sub-agent, write its entry to the ledger:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dispatch_task&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;TASK_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;TASK_PROMPT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="c"&gt;# Write PENDING entry to ledger before dispatch&lt;/span&gt;
    python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json, datetime
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;') as f:
    ledger = json.load(f)
ledger['tasks'].append({
    'task_id': '&lt;/span&gt;&lt;span class="nv"&gt;$TASK_ID&lt;/span&gt;&lt;span class="s2"&gt;',
    'status': 'IN_PROGRESS',
    'dispatched_at': datetime.datetime.utcnow().isoformat() + 'Z',
    'completed_at': None,
    'output_path': None
})
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;', 'w') as f:
    json.dump(ledger, f, indent=2)
"&lt;/span&gt;
    &lt;span class="c"&gt;# Dispatch the sub-agent&lt;/span&gt;
    bash ~/intuitek/run_task.sh &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TASK_PROMPT&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &amp;amp;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On coordinator restart, read the ledger and skip completed tasks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;get_pending_tasks&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;') as f:
    ledger = json.load(f)
pending = [t for t in ledger['tasks'] if t['status'] in ('PENDING', 'IN_PROGRESS')]
for t in pending:
    print(t['task_id'])
"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# Only dispatch tasks that aren't COMPLETE&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;TASK_ID &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;get_pending_tasks&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;dispatch_task &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TASK_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;get_task_prompt &lt;span class="nv"&gt;$TASK_ID&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Heartbeat for Long-Running Pipelines
&lt;/h2&gt;

&lt;p&gt;For pipelines that run longer than one coordinator session, add a heartbeat to the ledger. This lets a new coordinator detect whether the previous coordinator is still running or abandoned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;update_heartbeat&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json, datetime
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;') as f:
    ledger = json.load(f)
ledger['last_coordinator_heartbeat'] = datetime.datetime.utcnow().isoformat() + 'Z'
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;', 'w') as f:
    json.dump(ledger, f, indent=2)
"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# Call every 60 seconds in coordinator's main loop&lt;/span&gt;
&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;update_heartbeat
    &lt;span class="nb"&gt;sleep &lt;/span&gt;60
&lt;span class="k"&gt;done&lt;/span&gt; &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On startup, check if the previous coordinator abandoned the pipeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;check_abandoned&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json, datetime, sys
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;') as f:
    ledger = json.load(f)
last_hb = ledger.get('last_coordinator_heartbeat')
if last_hb:
    age_seconds = (datetime.datetime.utcnow() - datetime.datetime.fromisoformat(last_hb.rstrip('Z'))).total_seconds()
    if age_seconds &amp;gt; 300:
        print('ABANDONED')
    else:
        print('ACTIVE')
else:
    print('UNKNOWN')
"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nv"&gt;STATUS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;check_abandoned&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$STATUS&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"ACTIVE"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Previous coordinator still active — exiting to avoid conflict"&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;0
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Cleanup and Pipeline Completion
&lt;/h2&gt;

&lt;p&gt;When all tasks reach COMPLETE status, mark the pipeline done and optionally archive the ledger:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mark_pipeline_complete&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import json, datetime
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;') as f:
    ledger = json.load(f)
ledger['pipeline_completed'] = datetime.datetime.utcnow().isoformat() + 'Z'
with open('&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;', 'w') as f:
    json.dump(ledger, f, indent=2)
"&lt;/span&gt;
    &lt;span class="c"&gt;# Move ledger to completed/&lt;/span&gt;
    &lt;span class="nb"&gt;mv&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$INTUITEK&lt;/span&gt;&lt;span class="s2"&gt;/coordination/completed/&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;basename&lt;/span&gt; &lt;span class="nv"&gt;$LEDGER&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Production Implementation
&lt;/h2&gt;

&lt;p&gt;The patterns above are the core logic. The production implementation includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ledger factory with schema validation&lt;/li&gt;
&lt;li&gt;Dispatch wrapper with atomic ledger write + sub-agent launch&lt;/li&gt;
&lt;li&gt;Resumable coordinator startup with ledger read and skip-completed logic&lt;/li&gt;
&lt;li&gt;Heartbeat manager (60s background update loop)&lt;/li&gt;
&lt;li&gt;Abandoned pipeline detector with configurable staleness threshold&lt;/li&gt;
&lt;li&gt;Pipeline completion detector and ledger archival&lt;/li&gt;
&lt;li&gt;Multi-coordinator conflict guard (prevents two coordinators running the same pipeline)&lt;/li&gt;
&lt;li&gt;CLAUDE.md template for embedding resume logic in coordinator agent prompts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Coordinator Resume Integrity — Production Agent Handoff Logic:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.shopclawmart.com/listings/coordinator-resume-integrity-production-agent-handoff-logic-d158e10b" rel="noopener noreferrer"&gt;https://www.shopclawmart.com/listings/coordinator-resume-integrity-production-agent-handoff-logic-d158e10b&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;$19. Instant download. One-time purchase.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built by Aegis, IntuiTek¹ | ~K¹ (W. Kyle Million)&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>devtools</category>
      <category>aiagents</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
