An overnight coding agent is a timer that pulls a repository, runs the tests and the linter, asks a model for one small scoped change, re-runs the tests, and opens a draft pull request. It never merges. You can rent that loop from Anthropic, run it in GitHub Actions, or own it on your own machine; the review gate is the same in all three.
Part of the Always-on agents series, post 28 of 33.
I will start with the admission. Leo's backend is a production system that posts to real customers' accounts, and I have not pointed an unattended coding agent at it. Not because the models cannot write the code, but because the thing I most want from that codebase at 3am is that nothing changed. What I have run, for weeks, is a different unattended loop: the one that publishes this blog every morning and the one that checks the site afterwards. The rules I learned from those are the rules in this post, applied to code.
The loop itself is not exotic. Pull, test, lint, propose one change, test again, open a draft pull request, stop. The vendors now sell it in three shapes, and I tested the fourth, the one you own, in a fresh container with a throwaway repository.
What you can buy: three hosted routes
| Route | What runs it | Cadence and limits | What it opens |
|---|---|---|---|
| Claude Code scheduled tasks (formerly routines) | Anthropic's cloud, a fresh clone of your GitHub repository each run; research preview on Pro, Max, Team and Enterprise | Schedule (one-hour minimum), an API call, or a GitHub pull request or release event; runs autonomously with no permission prompts | Pushes to a branch prefixed claude/; the docs' own example opens a draft pull request from an alert |
| GitHub Actions on a cron | GitHub's runners, inside your repository's workflow | Five-minute minimum; runs on the latest commit of the default branch; can be delayed at the top of the hour; public repos switch it off after 60 days without activity | Whatever your workflow does; opening a PR needs a token and a step for it |
| OpenAI dots | A cloud computer per dot, inside ChatGPT | An ongoing job rather than a schedule, per the launch example | The launch example monitors customer feedback for recurring requests, scopes small fixes, builds and tests them, and returns pull requests with a video of the change |
| Your own machine (this post) | A systemd timer on a box you control | Any cadence; Persistent=true catches up a missed night | A draft PR via gh, from a token that can open but not merge |
Two things stand out to me across the three hosted options. First, the vendors agree with my rule from the first post: the agent acts and reports, and the report is a pull request, which is the most reviewable artefact software has. Second, only one of them, Claude Code, is explicit that the run happens with no permission prompts at all, and that whatever it does through your GitHub connection appears as you. That is exactly the identity question from the permissions post, and it is why my own version uses a token that is not me.
The loop I would run on my own machine
- Pick one repository and one window. One repo, one branch namespace, one hour a night. The agent does not get the whole organisation and it does not get the day.
- Give it an identity that can open but not merge. A fine-grained GitHub token scoped to that one repository with contents and pull-request write access, stored in a root-only environment file. Branch protection on main requires a human review and does not let that token bypass it. The agent is a contributor, never a maintainer.
- Pull and run the tests first. If the baseline is red, the agent's job that night is to report it, not to fix it. A red baseline is a human's problem.
- Collect lint findings and ask for one change. The model step receives the findings and the failing test, if any, and returns one scoped change with a title and a rationale. One. A pull request with twelve unrelated fixes is not reviewable at 9am.
- Test again, then commit on a dated branch. The branch is named for the night, and the checkout uses -B, so re-running the same night replaces the branch instead of stacking a second one. That is the idempotent rule from my publisher, applied to git.
- Open a draft pull request, and stop. Draft, so nobody is pinged for review at 2:30am, and so a CI run on the branch has time to finish before a human looks. The agent never merges, never force-pushes, never touches main.
- Put it on a timer with catch-up. A systemd timer with Persistent=true. A night the machine was off runs on the next boot, and because nothing was merged, nothing was lost.
The script
This is the version I ran. The model step is a stub that applies the linter's safe autofixes and writes the pull request body a model would have written; swap the rule for a model call and nothing else changes. I kept it that way on purpose, because the point of the post is the loop and its gate, not which model is clever this month.
/srv/agent/nightly.sh#!/usr/bin/env bash
# Nightly PR agent: pull, test, lint, propose one small change, open a DRAFT PR. Never merges.
set -euo pipefail
REPO=/srv/repo; OUT=/srv/agent/out; mkdir -p "$OUT"
cd "$REPO"
git checkout -q main
git pull --ff-only 2>/dev/null || echo "no remote configured; working on the local copy"
BRANCH="agent/nightly-$(date +%F)"
git checkout -q -B "$BRANCH" # -B: the same night re-run replaces the branch
echo "== baseline tests"; /srv/agent/venv/bin/pytest -q 2>&1 | tail -1
echo "== lint findings"; /srv/agent/venv/bin/ruff check . --output-format concise 2>&1 | tail -5 || true
echo "== model step (stub: the only judgement in the loop)"
/srv/agent/venv/bin/python /srv/agent/propose.py
if git diff --quiet; then echo "nothing proposed; cleaning up"; git checkout -q main; git branch -q -D "$BRANCH"; exit 0; fi
echo "== tests after the change"; /srv/agent/venv/bin/pytest -q 2>&1 | tail -1
git add -A && git commit -q -m "nightly: $(cat $OUT/title.txt)" && echo "committed on $BRANCH: $(git rev-parse --short HEAD)"
echo "== PR body"; cat "$OUT/pr-body.md"
echo "== would run (not executed here, no GitHub remote in this test):"
echo "gh pr create --draft --base main --head $BRANCH --title \"$(cat $OUT/title.txt)\" --body-file $OUT/pr-body.md"
# with a remote: git push -u origin "$BRANCH" && gh pr create --draft .../srv/agent/propose.py"""The model step. A real run sends the lint findings and any failing test to a model and asks for
ONE scoped change, a title and a rationale. In my test the 'model' is a rule: apply ruff's safe
autofixes, then write the title and PR body a model would have written. Swap the rule for a model
call and keep everything else."""
import pathlib, subprocess
out = pathlib.Path("/srv/agent/out"); out.mkdir(exist_ok=True)
ruff = "/srv/agent/venv/bin/ruff"
before = subprocess.run([ruff, "check", ".", "--output-format", "concise"], capture_output=True, text=True).stdout
subprocess.run([ruff, "check", ".", "--fix", "-q"], check=False)
after = subprocess.run([ruff, "check", ".", "--output-format", "concise"], capture_output=True, text=True).stdout
fixed = [l for l in before.splitlines() if l not in after.splitlines() and ":" in l]
(out / "title.txt").write_text("apply %d safe lint fixes" % len(fixed) if fixed else "no change")
(out / "pr-body.md").write_text("## What the nightly agent changed\n\n" + "\n".join("- " + l for l in fixed) +
"\n\n## Checks\n\n- tests: run before and after, see the log\n- scope: lint autofixes only, no behaviour change intended\n\n"
"Opened as a DRAFT by the nightly agent. A human reviews, re-runs, and merges or closes.\n")
print("proposed: %s" % (out / "title.txt").read_text())The timer
Two units, the same shape as the Linux core page. A oneshot service and a timer that fires at 02:30 with a random delay, so that if you run this on more than one repository they do not all hit the same minute.
systemd units# /etc/systemd/system/nightly-pr.service
[Unit]
Description=Nightly PR agent (draft PRs only, never merges)
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
User=agent
WorkingDirectory=/srv/agent
EnvironmentFile=/etc/nightly-pr.env # GH_TOKEN for a fine-grained token scoped to ONE repo, root-only file
ExecStart=/srv/agent/nightly.sh
# /etc/systemd/system/nightly-pr.timer
[Unit]
Description=Run the nightly PR agent at 02:30
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true # a night the machine was off runs on the next boot
RandomizedDelaySec=10m
[Install]
WantedBy=timers.targetWhat happened when I ran it
A fresh Ubuntu 24.04 container, a throwaway repository with one function, one test and two lint findings planted in it, and no GitHub remote, so the final gh command is printed rather than executed. Everything else ran as written. This is the log, trimmed only for width.
container loggit version 2.43.0
Python 3.12.3
694ea98 initial
ruff 0.17.1
pytest 9.1.1
################ RUN 1
no remote configured; working on the local copy
== baseline tests
1 passed in 0.00s
== lint findings
app.py:1:12: F401 [*] `sys` imported but unused
app.py:6:5: F841 Local variable `x` is assigned to but never used
test_app.py:1:1: I001 [*] Import block is un-sorted or un-formatted
Found 5 errors.
[*] 4 fixable with `--fix` (1 unsafe fix available with `--fix --unsafe-fixes`).
== model step (stub: the only judgement in the loop)
(ruff explains the one fix it will not apply unattended: the unused variable is an unsafe fix)
proposed: apply 5 safe lint fixes
== tests after the change
1 passed in 0.00s
committed on agent/nightly-2026-10-20: 81c8be8
== PR body
## What the nightly agent changed
- app.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- app.py:1:8: F401 [*] `os` imported but unused
- app.py:1:12: F401 [*] `sys` imported but unused
- app.py:6:5: F841 Local variable `x` is assigned to but never used
- test_app.py:1:1: I001 [*] Import block is un-sorted or un-formatted
## Checks
- tests: run before and after, see the log
- scope: lint autofixes only, no behaviour change intended
Opened as a DRAFT by the nightly agent. A human reviews, re-runs, and merges or closes.
== would run (not executed here, no GitHub remote in this test):
gh pr create --draft --base main --head agent/nightly-2026-10-20 --title "apply 5 safe lint fixes" --body-file /srv/agent/out/pr-body.md
################ RUN 2 (same night again: idempotent?)
no remote configured; working on the local copy
== baseline tests
1 passed in 0.00s
(same five findings, same proposal, same tests as run 1; trimmed)
committed on agent/nightly-2026-10-20: 81c8be8
== PR body
## What the nightly agent changed
- app.py:1:1: I001 [*] Import block is un-sorted or un-formatted
- app.py:1:8: F401 [*] `os` imported but unused
- app.py:1:12: F401 [*] `sys` imported but unused
- app.py:6:5: F841 Local variable `x` is assigned to but never used
- test_app.py:1:1: I001 [*] Import block is un-sorted or un-formatted
## Checks
- tests: run before and after, see the log
- scope: lint autofixes only, no behaviour change intended
Opened as a DRAFT by the nightly agent. A human reviews, re-runs, and merges or closes.
== would run (not executed here, no GitHub remote in this test):
gh pr create --draft --base main --head agent/nightly-2026-10-20 --title "apply 5 safe lint fixes" --body-file /srv/agent/out/pr-body.md
################ git state
81c8be8 nightly: apply 5 safe lint fixes
694ea98 initial
__pycache__/app.cpython-312.pyc | Bin 0 -> 527 bytes
__pycache__/test_app.cpython-312-pytest-9.1.1.pyc | Bin 0 -> 1303 bytes
app.py | 1 -
test_app.py | 2 ++
4 files changed, 2 insertions(+), 1 deletion(-)
################ systemd-analyze verify
units verify cleanThe second run on the same night is the part I care about. It reset the dated branch back to main, found the same five findings, applied the same fixes and produced the same single commit. Run the loop twice and you get one branch with one change on it, not two stacked commits and two pull requests. A stricter version would notice the branch already carries that diff and stop early; mine recomputes it, which is simpler and lands in the same place. That is the whole of the idempotent rule, and it is the difference between an agent you can leave alone and one you have to babysit.
The review gate: three rules I took from publishing
- Idempotent. Same night, same branch, same result. The dated branch and the -B checkout do this for free, and the no-change path in the script deletes the branch rather than leaving an empty one (that path did not fire in my run, because there was always something to fix).
- Catch-up, not pile-up. Persistent=true runs a missed night once, on the next boot. One run, not one per missed night, because the agent reads the repository's current state rather than a queue of what it meant to do.
- Nothing irreversible unattended. A draft PR can be closed with one click. A merge cannot be unmerged without a trace. The token cannot merge, the branch protection would refuse it anyway, and the script does not contain the word.
These are the same three rules my 09:05 publishing job has lived by since the morning it fired into a dead network and lost a day's post. A coding agent has more ways to be wrong than a publisher, which is an argument for the gate, not against the agent.
What I would not let it touch
- Anything under the deploy path: CI configuration, infrastructure files, release scripts. A change there is a change to what runs in production, however small the diff looks.
- Dependency bumps that rewrite a lock file. They look mechanical and they are where supply-chain trouble arrives; I want a human to read the changelog.
- Database migrations. The one place where a scoped, tested change can still be irreversible.
- Secrets, environment files and anything with a token in it. The agent reads from a root-only file and never writes one.
Everything else, the lint fixes, the dead code, the docstring that drifted from the function, the test that should have existed, is fair game, and it is exactly the work that never gets to the top of a human's list. If you want to try it without a machine of your own, the cloud post covers the hosted runtimes, and if you are still deciding whether this job needs a model at all, the if-statement test applies here too: the linter's autofixes did not need one, and I said so in the script.
Sources
- Claude Code docs, Automate work with scheduled tasks (accessed October 20, 2026)
- GitHub Docs, Events that trigger workflows: schedule (accessed October 20, 2026)
- DataCamp, OpenAI dots: always-on agents in ChatGPT, explained (accessed October 20, 2026)
- CBS News, Sam Altman unveils dots, OpenAI's new AI personal agent (accessed October 20, 2026)
Written by Lera Leonteva. The container run is reproduced in full above; the vendor facts are quoted from the linked pages as read on the access date.