You want to hand Claude Code a list of tasks, go to bed, and wake up to finished work. This post is for you if you have tried that, or you are about to.
Here is the problem. A run that works once at your desk can fail in quiet ways when it repeats all night. Nobody is watching. You find out in the morning, and the night is gone.
I build a tool that runs coding agents on GitHub repositories, and I run it on its own code day and night. Below are four things that broke for me, what each one cost, and how I fixed it. At the end is a short checklist you can use tonight.
First, how to run it with nobody there
Claude Code can run without you typing. Pass -p and a prompt. The docs for running it from scripts list the flags. Three of them matter at night.
-
--allowedToolssays yes to certain tools ahead of time. -
--permission-prompts nonesays no to anything that would wait for a person. The run keeps going. It does not sit on a question until morning. -
--output-format jsongives you a session ID and a cost estimate you can save.
Here is a small example you can copy. Run it in a spare copy of your repository, not the one you work in.
claude -p "Fix the failing tests" \
--permission-prompts none \
--allowedTools "Read,Edit,Bash(npm test)" \
--output-format json > run-result.json
The run ends with code 0 if it finished and another number if it failed. A script can check that. Code 0 only tells you the run finished. It does not tell you the work is right. That is what your tests are for.
That is enough for one task. The trouble starts when the run repeats all night. Every weak spot gets hit again on each pass.
1. Installing packages ate the whole night
One of my projects was a Node app with no lockfile. A lockfile is the file that lists the exact version of every package. Without it, npm has to work out the full list every time it installs.
I measured it on July 16, 2026. One install made 664 requests to the package registry. I tried the --omit=peer flag and it made 666. With a lockfile and a warm cache, npm ci made zero. It had nothing left to work out.
Through my proxy and cache, the slow install ran for more than 40 minutes and then hit my time limit. So I raised the limit from 20 minutes to 40. The runs then died at 40.1 minutes.
The fix was to commit a lockfile once, before the agent starts work. Now every run uses npm ci.
The lesson is simple. When a step is slow, find out what it is doing before you give it more time.
2. A time limit killed a passing test run 216 times
My runner gave the tests a time limit. It set the limit from how long the tests took last time, with a cap of 30 minutes.
One repository had tests that took about 36 minutes to pass. The cap stopped them at 30. Then the runner saved 30 minutes as the normal time, so the next limit was 30 again. In seven days those tests were killed 216 times. Each time, they needed about six more minutes.
I fixed it in three ways. The limit can now grow up to 45 minutes. If the tests had already printed a full passing result before they were stopped, that counts as a pass. And past 45 minutes, the runner skips the step and asks a person once. It does not start the tests and kill them again.
If your time limit learns from its own results, check what happens when the work is slower than the cap.
3. A run pushed straight to main
On July 1, 2026, one of my runs pushed a change right to main. It skipped branch protection and CI.
The cause was boring. I had started that kind of run with main set as its parent branch. My wrapper script saw that and pushed there.
Now that kind of run gets no parent branch, and automatic merge is forced off for it. It has to open a new branch and a pull request that waits for review.
For your own setup, use a token that cannot push to your main branch, and turn on branch protection. Telling the agent in the prompt to stay off main does not help when the script around it does the pushing.
4. The package cache was up but broken
On October 21, 2026, my own npm cache gave a 500 error for one package for three hours.
My health check only asked one thing, which was whether it could connect. It could, so it said all was well. Each run spent about 30 minutes retrying the install, changed nothing, and ended. After enough of those, the project paused itself for making no changes.
The pause worked, but it blamed the wrong thing. Now the installer reads npm's own error. If the error says the registry is down, and the registry is my cache, it tries once more against the public registry.
A better health check asks for a real package, because that is what every run does.
A checklist for tonight
- Your packages install from a committed lockfile, and you know how long the install takes.
- You can say why each time limit is the number it is. A stopped step logs what it was doing.
- The agent's token cannot push to your main branch. Branch protection is on.
- There is a test that can fail. The run is not allowed to change the test to make it pass.
- Something counts the runs that change nothing and stops after a few in a row.
- An empty or broken answer from the model counts as a failure.
- There is one place to read in the morning. It says what ran, what changed and what stopped.
For me, that one place is GitHub. The first thing I open in the morning is the list of pull requests on my repo that were merged or closed recently. If the newest one is seven hours old or more, I know something got stuck.
Where these fixes live now
All of this is now built into Keelen, the product I make. It runs Claude Code, Codex and other engines on a GitHub repository. It plans a request, writes the code, checks it and opens a pull request. Each run gets its own virtual machine, which is destroyed when the run ends. The GitHub token for a run works on one repository for about an hour.
If you would rather not build the plumbing yourself, it is at keelen.ai. The checklist above works just as well with a shell script and a cron entry.
What has broken for you when you ran a coding agent with nobody watching? Tell me in the comments.
Top comments (1)
a lockfile pins the packages but not the package manager. our runner still had pnpm 9 while the repo asked for 10, so every build it started for two weeks died at pnpm's version check