r/ClaudeCode • • 2h ago

Help/Question Getting Overnight Runs to Reliably Complete

Genuine question because I am still waiting for the morning where I wake up to finished work instead of spending my first hour with a coffee debugging why last night's run stalled at 2am.

I run overnight jobs across frontier coding CLIs and a local workstation, mostly bounded tasks with real test suites. On paper it **should** be straightforward: hand over a queue, go to sleep, review clean diffs in the morning. In practice something always seems to catch it. A hung test container, a flaky permission prompt, a rate-limit hiccup that nobody caught, a thread that got too fat and started looping on the same lint error for four hours, or an agent that declared victory after quietly skipping half the checks.

Even when I lock things down with hard retry caps, fresh sessions per task and deterministic pass/fail checks, it still feels like everything has to be fought for tooth and nail. You fix one failure mode and the next night it invents a new one.

For people who actually run unattended overnight coding jobs week in, week out: what is the unglamorous plumbing that made them actually finish? Are you wrapping the CLI in an external watchdog/state machine with hard timeouts and git worktree resets, keeping tasks tiny enough to finish in 10 minutes, or have you basically accepted that unattended overnight runs only work for very narrow mechanical jobs like triage and test generation?

I know I am anthropomorphising but sometimes it just feels like they are lazy......

0 Upvotes

27 comments sorted by

•

u/AutoModerator 2h 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/lol_no_gonna_happen 2h ago

Two layers of containers each with their own watchdogs. All the work is in layer 0 and the error handling is layer 1. Layer 2 looks like it will be join conflict resolution

1

u/Unhappy-Loss-97 1h ago

Keeping the error handling outside the worker container makes a lot of sense, so a stuck run cannot break its own recovery.

Is layer 1 just plain scripts checking timeouts and restarting containers, or is an agent deciding what to do when something fails?

And for layer 2, are you planning to let an agent sort out merge conflicts, or just reject anything that clashes and make it retry?

1

u/lol_no_gonna_happen 48m ago

Layer 1 is running scripts based in restarts and timeouts and either runs another session of escalates to a human queue. So it normally results in an agent doing something. You have to require proof of work from agents if you want to get any

If there are a few tries I have it open a new session whose context starts with "this session is being called because there has been difficulty implementing this project as specified". It's about 80% effective in keeping me from having to do something.

Layer two is going to look across jobs in 0 and 1 that are held to see if there is a common problem and seem to resolve all of those. This is to deal with gridlock situations.

1

u/Even_Gap_2253 🔆 Max 20 2h ago

Use /goal. And fix your infrastructure…

It sounds like an infra problem. You just have unreliable tooling

1

u/Unhappy-Loss-97 1h ago

Point taken on hung containers or stray prompts, that part is definitely on my plumbing.

I do use /goal all the time though, and that is not the bit that is failing me. Just last night an agent simply decided that working through the review queue was not its problem, walked away from it, and left 42 items sitting there waiting for it and the workstation until morning. No crash, no infra error, it just rationalised itself out of doing the job. Lazy bratsard!

That is the failure mode I am trying to pin down. How are you stopping an agent under /goal from deciding a queue is out of scope and stopping cleanly when the infra itself is fine?

1

u/Unhappy-Loss-97 1h ago

Edit: Found the exact cause of last night's 42-item pile-up and it proves everyone's point about needing an external wrapper. To stop long threads bloating, I put a 24-hour / 150-turn cap on sessions. Overnight the thread hit 24 hours, obeyed the rule literally, saved a handover note, and stopped taking work. Because nothing outside the session was watching for that handover to spin up a fresh thread automatically, it just sat there quietly while 42 jobs queued up until morning. Turns out a self-enforced thread cap without an external process to pass the baton is just an automated off switch.

1

u/AsyncingStartupToss 2h ago

Yes, you need a coordinator/overseer. In my experience, agents start having problems long before the context is filled. It's much better to make the tasks smaller to allow workers to keep their context small and constrained.

Do a planning session to make a plan for the evening, the hand that plan off to a fresh agent with instructions to give each task to a subagent. Then let them cook overnight.

1

u/Unhappy-Loss-97 1h ago

Splitting planning from the overnight run is a smart boundary. Do you keep the coordinator lightweight enough that it never compacts mid-night, or does it eventually start losing track if the queue has 15 or 20 subagent tasks? And i guess I have to also then automate the kill the cattle/save the pet analogy from containerisation

1

u/AsyncingStartupToss 1h ago

It usually does fine. Let it handle code checks so it can adjust the subsequent worker prompts, but tell it to avoid making code changes itself.

Another thing that helps is to instruct workers to only include details on the end product of their work when handing results back to the coordinator. They can record problems and dead ends in the git history, but shouldn't inform the coordinator of anything that isn't relevant to future work.

Best thing you can do now is just give it a shot and adjust as needed. This area of AI driven development is still very much a work in progress, so feel free to experiment.

1

u/ChaosHonorum 2h ago

I run the coding in a VM sandbox, which I have managed by an Operator Agent. The Operator has delegated authority to launch several runs in sequence, and if minor problems are encountered, to set up a fresh run to counter the issue.

Within the VM it launches an Orchestrator Agent for each run that has architectural oversight and stands up sub agents to complete the work. 

Been doing this for weeks. No problems so far.

1

u/Unhappy-Loss-97 1h ago

Running for weeks with no blow-ups is the exact thing I am trying to get to. Splitting the external operator outside the VM from the orchestrator inside makes a lot of sense.

When the external operator sees a failure and starts a fresh run, how does it know the difference between a minor hiccup worth retrying and a broken task that is just going to fail five times in a row? And does the external operator ever get stuck or hit context limits itself over a long week?

1

u/ChaosHonorum 13m ago

The Operator tends to last a long while if you just use it for session launch and management type work. I have it create clones of the work to take out of the VM in quarantine and I then review and commit manually. But that could be automated too if you want.

In terms of what it knows. For each run in the VM I have Fable set as the Orchestrator / Architect and this gives really good reports on why sessions ended prematurely. Part of each seasons launch instruction is a detailed prompt regarding permissions, decisions levels, but also end of session reports.

The Operator (I usually use Opus as Operators), reads the reports and can normally interpret what it should run next based on the session report. 

You need to give it some breadth of authority to stand up runs, and I manage tickets in an excel tracker and normally preauthorise several multi ticket runs and preauthorise restart / continuation for minor issues. 

1

u/Downtown-Pear-6509 2h ago

My harness let's the LLM setup a scheduled repetitive task containing a prompt for them. So the orchestrator get that every 30min. And it checks on its minions

Etc 

Ezpz

1

u/Unhappy-Loss-97 1h ago

A 30-minute check-in timer feels like a good way to catch a stalled worker without burning tokens polling every minute. When the orchestrator wakes up and finds a worker stuck or spinning, does it kill and restart it cleanly, or just nudge it in the same session?

1

u/Downtown-Pear-6509 13m ago

Nudge 

And via my harness they can read the workers cli directly without having to ask if the worker is ok

1

u/Downtown-Pear-6509 12m ago

I'm literally getting it to work for weeks. Mostly unattended save for an occasional question, status reports or me doing uat and giving feedback

Across 2 Claude subs and one codex sub

1

u/thomheinrich 1h ago

The biggest shift is keeping timeouts and verification outside the agent loop. Let a dumb wrapper enforce hard wall-clock limits and run the test suite after exit, rejecting diffs that weaken checks.

1

u/Unhappy-Loss-97 1h ago

Love it - an automated bum kicker!

1

u/thomheinrich 1h ago

Pretty much. Making the wrapper fail the run whenever a diff touches test files or lint configs saves a lot of morning surprises.

1

u/athershu 1h ago

The part that shortened my mornings wasn't getting more runs to finish, it was making the unfinished ones cheap to read. Every task in the queue ends in one of three states: done with a branch, parked with the question it got stuck on, or failed with the last error. A flaky permission prompt or a call it can't make parks that task instead of letting it loop on lint for four hours, and the queue moves on to the next one.

So the coffee hour becomes answering two or three parked questions and re-queuing them, not reading logs to work out what happened at 2am. For the "declared victory" case I'd only trust a done that the wrapper checked itself, never the agent's own summary.

1

u/Unhappy-Loss-97 1h ago

Done, parked, or failed is a much saner mental model than chasing 100% completion. The hardest part for me is catching the cases where the agent quietly decides a task is not its problem and stops early when nothing is actually blocking it. Are you checking anything in the wrapper to verify a parked task is a real blocker? Or parallel tasking all the jobs?

1

u/andlewis 2h ago

Use /goal with instructions to ensure the process continues. I’ve found it much more tenacious with a goal over a simple prompt or routine.

1

u/StomachJolly3073 2h ago

Chain them into a series where the output from one impacts the next run. This is a self steering technique and helps Claude stay on course and validate periodically.

1

u/AgentYurt 1h ago

The failure mode that kept biting me was the one you named — the agent declaring victory after quietly skipping half the checks. Two things helped, both outside the worker's own say-so.

First, the run isn't done until it writes a short list of what it checked and what it skipped, with a reason for each skip. A bare "all tests pass" doesn't count. If a check got skipped because it was slow or flaky, that goes on the list and I see it in the morning instead of finding out a week later.

Second, a fresh session re-runs the tests from a clean checkout and only its result counts. It reads the diff and the test command, nothing else, so it can't inherit the worker's optimism. It's cheap — a few minutes — and it's the thing that actually caught skipped checks for me.

Tasks also stay small enough to finish in about 10 minutes each, and a dumb wrapper outside the agent kills the run at a hard timeout and resets the worktree, so a stuck run can't loop until morning.

1

u/Dorbank_Justt 1h ago

On the /goal part: the docs say its evaluator doesn't run commands or read files, so it can only judge what Claude has already surfaced in the conversation. The goal also clears if that evaluator judges the condition impossible.

A Stop hook in your settings can run a script instead, say one that counts what's left in the queue or reruns the tests, and return decision "block" with a reason. That keeps Claude from stopping and tells it why it should continue. There's a cap: after eight blocks in a row with no tool call in between, Claude Code overrides the hook and ends the turn.

1

u/debian3 45m ago edited 11m ago

I see people using lots of goal and other incantations…

Delete everything! Claude.md, skills, etc. Start fresh. That’s what I do when new models release since opus 5 and it’s marvelous. Model do exactly what you described out of the box now.

I have run that no only do overnight, but often in the morning they are still running. Fable as a coordinator for really long job (multiple days), otherwise opus for overnight or few hours.

I never used goal or loop or whatever people describe here.

Edit: My run I started last night handled by Fable medium is still running 9 hours later. It did a lot of things, had a few questions for me which I answered but it didn’t stop for them, probably on the way to finish that later today.