r/ClaudeCode • • 25d ago

Built with Claude A polling loop in my server's Claude Code session burned ~100M tokens in one day, so I built a watchdog that wakes Claude only when something changes

I keep a Claude Code session running on a Debian VPS as a resident admin. At one point a polling loop inside that session ate about 100M tokens in a single day, while nothing on the server was wrong.

Atlas is what I built after that. It's a watchdog for one Linux server, stdlib Python and bash on cron and systemd, with no LLM inside. It snapshots what the machine is supposed to look like (services, timers, listening ports, accounts, sudoers, crontabs, packages, setuid binaries, firewall, apt sources, vhosts) and diffs it every 30 minutes. A small daemon follows the journal in real time for SSH logins from unknown IPs, sudo by unexpected users, failed units, OOM kills, and web requests for things like .env or .git.

How Claude Code fits in:

  • The session arms the Monitor tool on session-sensor.sh, which prints one line per state change and nothing in between. A quiet day costs no tokens.
  • On a wake-up Claude reads the alert and probes the real system state. Then it fixes the problem within its mandate (restart a failed unit, free disk), or blesses a change it can explain (atlas.py bless makes the current state the new baseline), or leaves the alert unacknowledged so it escalates to me.
  • Raw logs only go through a quarantined log-reader subagent with read-only tools, because request paths and usernames are text written by strangers.
  • There's an optional taint gate hook on PreToolUse, PostToolUse and UserPromptSubmit. After the session reads an untrusted source, every tool call outside a read-only allowlist is denied until I type a fresh prompt. The hook is plain Python, so no model takes part in that decision.
  • It ships as a plugin: claude plugin marketplace add /opt/atlas/agent, then claude plugin install atlas-resident@atlas.

The alarm path never runs through Claude. If the session is dead, rate limited, or was talked into something by a log line, Atlas mails me anyway. Critical events go straight to me when no resident is alive, and a timer checks every 10 minutes for a dead resident, a silent patrol or an alert nobody acknowledged.

The quickstart goes from a blank Debian/Ubuntu server to a resident session you talk to from the Claude phone app through Remote Control (Pro or Max). Atlas alone is fine on 1 vCPU and 768 MB of RAM; with Claude Code on the same box the guide asks for 4 GB.

I built it with Claude Code, test-first: each change lands as a failing test commit and then the fix. Claude is co-author on 101 of the 194 commits and the suite has about 1,100 tests. MIT licence, signed release tags.

https://github.com/NovaSeth/Atlas

If you run Claude Code unattended on a server, how do you keep it from acting on something it read in a log?

2 Upvotes

7 comments sorted by

•

u/AutoModerator 25d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Se4h 25d ago

Just one thing: it is not some 3h projects, I've spend almost 3 month on this. Thanks to Claude Code it wasn't 5 year project ;)

2

u/michaelTM_ai 25d ago

printing one line per state change and nothing else is the real fix here. a polling loop inside the session pays tokens every tick to learn nothing happened, a dumb cron diff that wakes claude only on change costs zero on a quiet day

3

u/mackstann 25d ago

Yeah I also burned tokens on a Claude polling loop and learned the same lesson. Every turn costs tokens; don't cause a turn to happen in response to nothing.

2

u/Easy-Purple-1659 24d ago

Ran the same shape against ad library pulls, and the two things that broke first were the baseline and the alert fingerprint.

Baseline: only bless after a fetch that actually succeeded. An empty response and a failed one look identical to a naive diff, and one bad API day quietly makes a broken state the new normal. Keep a separate last-good timestamp and refuse to bless while it is stale. Same rule for the first run after a deploy, since a fresh checkout has no baseline and everything looks like a change.

Fingerprint: dedupe alerts on a hash of the changed keys, not on the message text. Add counts and timestamps to the text and the same outage produces a fresh alert every run, which burns exactly the budget you were trying to save. I keep a six hour suppression window per key hash.

One more thing at that cadence: have the monitor write its own heartbeat every time it patrols. A stuck sensor and a quiet server both look like silence, and only one of them is good news.

I would also cap spend per wake, so one incident is one turn. A stuck retry loop ate a day of budget for me once and nothing on the box was wrong.

How did you handle the session blessing a change it does not understand?

1

u/RustyRedEcho 25d ago

the taint gate hook, locking tool calls after reading untrusted logs until a fresh prompt comes in, is such a smart guardrail. never thought about that attack angle for unattended sessions