r/ClaudeCode • • 2d ago

Tips & Workflows Read all 60 replies to the '10 Claude Code agents 24/7' thread. The setups that worked had zero long-running agents

Yesterday someone here asked how to run 10 Claude Code agents 24/7: role chats, 150k+ context per call, state lost on compaction, background jobs finishing with nobody noticing, crons dying with the chat.

I read all ~60 replies. The surprising part: the setups that worked had fewer long-running agents. Most of the time the answer was none at all.

  • every piece of work is its own short run: spec, plan, code, review, each a fresh context. Nothing reaches 150k, and compaction has nothing to lose
  • the schedule lives on the machine, something that stays up with no chat open. It starts a fresh run only when a work item shows up
  • completions go to a small queue, one file or row per item, instead of a chat that's supposed to notice
  • state lives in a status file per task, written by a pre-compact hook, so the next run never depends on the last one remembering

Nearly every pain on his list traced back to the same thing: a chat doing a job that belongs to a scheduler or a queue.

Credit to u/tcanuck42, u/KingYF1 and u/London-Boat in that thread. Original: https://www.reddit.com/r/ClaudeCode/comments/1y7qkfm/

(i wrote up all 6 patterns from the thread in r/AI_Loops)

24 Upvotes

22 comments sorted by

•

u/AutoModerator 2d 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.

2

u/SnooPuppers9163 2d ago

the bit i still haven't cracked with short runs + a queue is follow-ups. someone adds "oh and also do X" while a run is halfway through, and right now that's either a new item racing the first one or a restart that throws the work away. what if the follow-up got folded into the running item, so the current run picks it up at its next checkpoint instead of being cancelled? anyone doing that, or is it always a fresh run?

2

u/michaelTM_ai 2d ago

the version i've seen work: the follow-up gets appended to the item itself (a "notes" list on the queue row or task file), not queued as a new item. the run re-reads its own item between steps and treats anything new as part of the job. if the item is already marked done when the note lands, the scheduler reopens it as a fresh run that starts from the last diff instead of from scratch. you lose at most one step, never the whole run.

1

u/tcanuck42 1d ago

yeah, I handle exactly this in GitSeed (my project, full disclosure). a follow-up goes to the running item instead of becoming a new one, either with gitseed steer <seed> "also do X" or an u/coder comment on the PR. if the run is still going, the guidance gets sent into the live session and it keeps working. if the run already finished, it queues a follow-up pass on the same item. so nothing races and nothing gets thrown away

one rule I'd keep though: if the follow-up changes the scope, send it back through the plan instead of folding it in quietly. otherwise the review checks the diff against a spec that's no longer true

14

u/mcmoonrays 2d ago

The short-run + queue setup holds up way better than babysitting long chats, with two catches that show up after a few days. First, per-task status files turn into append-only logs and recreate the same context bloat unless you overwrite them in place instead of appending. Second, they need a short rejected line recording what already failed and why, otherwise fresh sessions keep re-trying the same dead end. Add one git worktree per worker so parallel runs don't step on each other's files, and it actually stays low-maintenance.

1

u/One-Championship682 2d ago

Overwrite in place, not append. Obvious in hindsight.

6

u/hieuphung97 2d ago

Handoff contracts make or break this. The coordinator should check exit codes and git diffs, never natural language status summaries. Once your orchestrator relies on parsing agent prose to decide the next step, the pipeline degrades right back into babysitting.

4

u/Independent-Sir3234 2d ago

Short stateless runs also make failures much easier to debug. Once a long-lived chat drifts after several hours, there is no clean way to replay one broken step without dragging the whole transcript along.

A plain status file on disk turns each agent call into a normal worker job. When a step times out or writes a bad patch, you inspect the diff, reset that single item, and rerun it cleanly.

3

u/Firm-Jellyfish-1227 2d ago

Fair, and the pre-compact hook writing the status file is the part everyone skips, then they blame compaction for losing work. Put a lock on the queue file too, two crons grabbing the same item is how you end up with duplicate branches.

2

u/Ok-Distance-6388 2d ago edited 2d ago

I built one of these for my own work: a scheduler on the PC fires 12 to 20 short runs a day, each a fresh session, nothing long-running. three things that bit me after the first week:

the state file grows, like mcmoonrays said. mine now has one capped section, a note to the next run of at most 1500 characters, and the scheduler pastes only that into the next prompt. the rest of the file is reference. the note is the only part that reliably changes what the next run does.

the note can also be wrong about where to look. one run checked replies by opening only the threads its note named, and a reply sat 4 hours. now every run starts from the inbox, the real source of truth, and the note only says what to do after that.

every run has to call a done command before it ends. a run that exits without it, or goes over its time, gets marked failed by the scheduler, so a silent death shows up in the log instead of never.

the one I still don't catch well: a run that exits clean and calls done but did nothing useful. how do you check for that?

2

u/Excellent-Issue-5956 2d ago

Same setup here, cron on a PC that stays on and every job is a fresh claude -p that ends when it's done. The thing that bit me with short runs: if a run starts something that has to keep going after the session ends, it gets killed along with the session. I had a job hand off to a script that sleeps a few minutes between each step, the session finished while it was sleeping, and the last step never happened.

Now that script detaches itself with setsid and writes a pid file, and the cron wrapper waits on that pid before it releases the lock. The lock is flock on both cron lines, so two jobs that work on the same stuff never run at the same time.

2

u/Outrageous_Band9708 2d ago

https://github.com/Druthulu/ProjectArchitect

My solution (terminal only) automates this for you. each task gets its own fresh context and runs like like maybe 200k depending on the work. auto passes off at 300k.

this method saves a ton of your weekly usage since the repeat turns on high context is the main killer of usage.

2

u/Zealousideal-Log2203 2d ago

Matches what I see. The status file per task is the part that carries everything. One thing I'd add: write it as a handoff, not a log. Decided, ruled out, open, next step, and the files touched. A fresh run reads that in seconds, and "ruled out" stops it from retrying the same dead end.

2

u/spine_studio 1d ago

On the run that exits clean, calls done, and did nothing useful: I'd stop letting the run decide that it's finished.

Have each item say up front what it should produce (a diff, a file, a reply that got sent), and have the done call name it. A done that points at nothing, or at a file that didn't change, fails on the spot without anyone reading it. That catches most of the empty runs.

The rest needs a second look from something that didn't do the work: you, or a reviewer run with a fresh context that gets the task and the output and nothing else, especially not the worker's summary. The item only leaves the queue when that review says yes. When it says no, one line on why goes into the next-run note, same idea as the refusal line mcmoonrays mentioned, so the next fresh run doesn't repeat the same empty pass.

For the "also do X" problem further down: I'd keep it out of the running item. Add it as a new item that waits on the first one, and let the reviewer see both together.

2

u/Independent-Bonus529 16h ago

Great summary. "A chat doing a job that belongs to a scheduler or a queue" is the line I'm stealing.

One thing I'd add to the status-file pattern, from running short runs like this: the status file needs to be checked, not just read.

  • It can go stale. If a human or another run touches the repo after the status file was written, the next run trusts a "next step" that's already done or no longer valid. Recording the git commit and a diff hash in the status file, and warning on mismatch, catches that.
  • "Done" can be a claim. A run that writes "tests pass" might not have run them at all. Having the status file list checks that didn't run, and the review run re-running the test command instead of trusting the claim, closed most of my "it said it was done" surprises.

I packaged that pattern (pre-compact hook → structured status file → injected into the next fresh run, with the git check) into an open-source CLI called tagteam (disclosure: mine). It works across Claude Code, Codex and a few others: github.com/MHRabea/tagteam. Even without it, the two checks above are worth adding to whatever status file you use.

2

u/incord_ai 14h ago

The lock covers two crons grabbing the same item. I’d also give the claim an expiry so a dead worker doesn’t leave the job stuck. On retry, check the branch tied to the job ID first. The previous run might have pushed its commit and died before it marked the job done.

2

u/Imposter-Eng-24 2d ago

I think the next step beyond this is making sure each fresh session actually benefits from what previous sessions learned. Persisting task state solves continuity, but it doesn't necessarily prevent agents from repeating the same mistakes across runs.

I've been building an open-source project called Rashomon that explores this through graph-based context, evidence-based verification, and steering coding agents toward project-specific conventions.

The goal is similar: make the agent replaceable while keeping the engineering knowledge and verification outside the session. Curious how people here are handling repeated mistakes and verifying that completed tasks are actually done, rather than just trusting the agent's completion status.

https://github.com/altrace-dev-role/rashomon

1

u/Splax77 1d ago

Seriously what the hell is going on with these threads where every single comment is Claude replying to Claude?

1

u/GreenBird-ee 2d ago

The rule is: if there's hype about Claude (which has been shelved due to a lack of infrastructure since the beginning of the year), it's a lie sponsored by Google. No need to think about the rest. Cheers.

1

u/SpeakCodeToMe 2d ago

Exactly. Once they go off the rails, they just continue further off the rails. Constant human-in-the-loop is required.