<?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: spike3y</title>
    <description>The latest articles on DEV Community by spike3y (@spikeyjt).</description>
    <link>https://dev.to/spikeyjt</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%2F4265579%2F7150da05-1182-418e-acf2-83240d26c598.png</url>
      <title>DEV Community: spike3y</title>
      <link>https://dev.to/spikeyjt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/spikeyjt"/>
    <language>en</language>
    <item>
      <title>Running Claude Code on cron: 4 ways it bills or breaks, and the guard for each</title>
      <dc:creator>spike3y</dc:creator>
      <pubDate>Wed, 25 Nov 2026 22:09:32 +0000</pubDate>
      <link>https://dev.to/spikeyjt/running-claude-code-on-cron-4-ways-it-bills-or-breaks-and-the-guard-for-each-4n65</link>
      <guid>https://dev.to/spikeyjt/running-claude-code-on-cron-4-ways-it-bills-or-breaks-and-the-guard-for-each-4n65</guid>
      <description>&lt;p&gt;Running &lt;code&gt;claude -p "..."&lt;/code&gt; from cron looks like a one-liner. In practice, four things go wrong.&lt;br&gt;
This guide explains each one and the guard that fixes it. Every guard is implemented in&lt;br&gt;
&lt;a href="https://github.com/spikeyjr/agent-autopilot-kit/blob/main/ops/agent_tick.sh" rel="noopener noreferrer"&gt;&lt;code&gt;ops/agent_tick.sh&lt;/code&gt;&lt;/a&gt; in &lt;a href="https://github.com/spikeyjr/agent-autopilot-kit" rel="noopener noreferrer"&gt;agent-autopilot-kit&lt;/a&gt;, and tested by &lt;code&gt;ops/selftest.sh&lt;/code&gt; against a stub &lt;code&gt;claude&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Unofficial. Not affiliated with Anthropic. Billing rules change: check the linked help-center pages.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  1. A stray API key switches you to metered billing
&lt;/h2&gt;

&lt;p&gt;Signed in with a Pro/Max plan, &lt;code&gt;claude -p&lt;/code&gt; draws from your subscription limits&lt;br&gt;
(&lt;a href="https://support.claude.com/en/articles/15036540-use-the-claude-plan-usage-limits" rel="noopener noreferrer"&gt;support.claude.com/en/articles/15036540&lt;/a&gt;).&lt;br&gt;
But if &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt; is present in the environment cron gives the job (crontab variables,&lt;br&gt;
&lt;code&gt;/etc/environment&lt;/code&gt;, a sourced profile), Claude Code may use the key, which is billed per token.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Guard:&lt;/strong&gt; unset it in the launcher, every run:&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="kd"&gt;unset&lt;/span&gt; ANTHROPIC_API_KEY ANTHROPIC_AUTH_TOKEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also check &lt;code&gt;apiKeyHelper&lt;/code&gt; in your settings and any cloud-provider env vars, and verify with &lt;code&gt;claude auth status&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Overlapping runs
&lt;/h2&gt;

&lt;p&gt;A session that runs long collides with the next cron slot: two agents editing the same files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Guard:&lt;/strong&gt; a non-blocking lock. The second run exits immediately instead of queueing.&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;exec&lt;/span&gt; 9&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;state/agent.lock
flock -n 9 &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;"another session running"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 0&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Retrying into a usage limit
&lt;/h2&gt;

&lt;p&gt;On a plan, scheduled runs share the rolling usage window with your interactive use. If a run fails on a&lt;br&gt;
limit and the next slot simply tries again, you spend the fresh window on the same failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Guard:&lt;/strong&gt; on a failed run, look for limit wording (&lt;code&gt;usage limit&lt;/code&gt;, &lt;code&gt;rate limit&lt;/code&gt;, &lt;code&gt;limit reached&lt;/code&gt;, &lt;code&gt;429&lt;/code&gt;,&lt;br&gt;
&lt;code&gt;overloaded&lt;/code&gt;), write a pause-until timestamp, and skip runs until then. Never retry automatically.&lt;br&gt;
Only check &lt;em&gt;failed&lt;/em&gt; runs: successful output can legitimately mention "rate limit" or contain &lt;code&gt;429&lt;/code&gt; in an id.&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;echo&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;date +%s&lt;span class="o"&gt;)&lt;/span&gt; + 18000 &lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; state/pause_until    &lt;span class="c"&gt;# 5 hours&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Nothing ever stops it
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Guards:&lt;/strong&gt; a daily run cap, &lt;code&gt;--max-turns&lt;/code&gt;, a hard &lt;code&gt;timeout 45m&lt;/code&gt;, an end date checked before every run,&lt;br&gt;
and a kill file (&lt;code&gt;touch state/STOP&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Keep routine work out of the model
&lt;/h2&gt;

&lt;p&gt;Most "agent" chores are deterministic: syncing data, rotating logs, checking a status page. Run them from a&lt;br&gt;
plain cron tick (here: &lt;code&gt;ops/ops_tick.py&lt;/code&gt; every 15 minutes, plus &lt;code&gt;ops/hooks/*.py&lt;/code&gt;) so they keep working even&lt;br&gt;
when you're out of usage, and reserve &lt;code&gt;claude -p&lt;/code&gt; for work that needs judgment.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Test the guards without spending usage
&lt;/h2&gt;

&lt;p&gt;Put a stub &lt;code&gt;claude&lt;/code&gt; first on &lt;code&gt;PATH&lt;/code&gt; that prints canned JSON (success, limit message, error, slow run),&lt;br&gt;
then assert on the launcher's log. That is what &lt;code&gt;ops/selftest.sh&lt;/code&gt; does: 12 checks, zero usage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/spikeyjr/agent-autopilot-kit ~/autopilot &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; ~/autopilot
&lt;span class="nv"&gt;$EDITOR&lt;/span&gt; ops/config.env AGENTS.md TASKS.md
./install.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Disclosure: I maintain &lt;a href="https://github.com/spikeyjr/agent-autopilot-kit" rel="noopener noreferrer"&gt;agent-autopilot-kit&lt;/a&gt; (MIT). Everything above is in the free repo.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;An optional paid setup guide + templates: &lt;a href="https://spikeyjr.gumroad.com/l/agent-autopilot-kit?layout=profile" rel="noopener noreferrer"&gt;https://spikeyjr.gumroad.com/l/agent-autopilot-kit?layout=profile&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claude</category>
      <category>automation</category>
      <category>linux</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
