# Overnight Coding Agent Checklist With a Preflight Script

A checklist and runnable preflight script for letting a coding agent work unattended: branch, restore point, limits, kill file, secrets, plus a morning review.

Author: Steven Phan
Published: 2026-11-30
Article: https://stevenphan.ca/blog/overnight-unattended-coding-agent-checklist/

Before you leave a coding agent running unattended, make nine things true: the git tree is clean, the agent is on a fresh branch, main cannot be pushed to, the tests pass right now, a budget and time limit exist, no secrets are in the environment or the repo, a kill file path is free, logging works, and you've made a restore point. Then check them with a script instead of your memory, because the one you forget is the one that bites.

This post gives you that script. It's about 200 lines of Python using only the standard library, and a second script for the morning review. We ran both against a throwaway git repo in a sandbox, once in a passing state and once in a deliberately broken one, and the real output is pasted below. No model is involved anywhere: the "overnight session" in our demo is a few plain git commands, so nothing here tells you how any particular agent behaves.

## Quick answer

Run a preflight script that exits with a non-zero code if any of nine checks fails, and make your runner refuse to start unless it passes. The checks are: clean working tree, new branch, main protected or push disabled, tests green at the start, a budget and time limit set, no secret-looking environment variables or file contents, a free kill file path, a writable log, and a git tag at HEAD as a restore point.

In the morning, don't read the whole diff first. Read five summaries: diff size, test files touched, deleted files, new dependencies, and added lines that look like network calls. The second script prints all five against your restore tag. Everything about limits is a check that they're configured, not enforcement. Your runner still has to stop the agent when time or money runs out.

<nav class="toc" aria-label="Table of contents">
<p><strong>On this page</strong></p>
<ol>
<li><a href="#why-an-unattended-run-needs-a-checklist">Why an unattended run needs a checklist</a></li>
<li><a href="#the-nine-checks-and-why-each-one-is-there">The nine checks and why each one is there</a></li>
<li><a href="#the-preflight-script-and-its-config">The preflight script and its config</a></li>
<li><a href="#run-it-on-a-passing-repo">Run it on a passing repo</a></li>
<li><a href="#run-it-on-a-broken-repo">Run it on a broken repo</a></li>
<li><a href="#what-the-script-cant-check">What the script can't check</a></li>
<li><a href="#the-morning-review-five-things-to-read-first">The morning review: five things to read first</a></li>
<li><a href="#download-the-demo">Download the demo</a></li>
<li><a href="#faq">FAQ</a></li>
<li><a href="#where-to-go-next">Where to go next</a></li>
</ol>
</nav>

![Original diagram of a left to right pipeline. Step 1 is nine preflight checks: clean working tree, new branch, main protected or push off, tests pass at start, budget and time limit set, no secrets nearby, kill file path free, logging on, and a restore tag at HEAD. Step 2 is a go or no go gate where exit code 0 starts the run and exit code 1 means fix it first. Step 3 is the unattended session, bounded by a time limit and a kill file that the runner has to enforce. Step 4 is the morning review of five summaries against the restore tag: diff size, test files touched, deleted files, new dependencies and network call lines.](https://stevenphan.ca/_astro/overnight-unattended-coding-agent-checklist-flow.DN5LsRLq_Z2kkvF8.webp)

## Why an unattended run needs a checklist

When you sit beside an agent, you are the safety system. Walk away for eight hours and that attention disappears. What's left is whatever you set up before you left.

Several things can go wrong overnight. The agent worked on the wrong branch, so cleanup means untangling your own work from its work. Nothing was saved first, so there's no easy way back. Tests were already failing, so "the suite is red" at 7 a.m. tells you nothing. No limit stopped a loop. A token or password was lying around where the agent could read it. Each is cheap to prevent and expensive to repair.

A preflight that exits with code 1 can block the start. A checklist you only read cannot.

This is the outer fence around a session. It does not decide what individual tool calls are allowed. For that, sort your agent's tools by how much damage they can do, which the post on [read, write and irreversible tool risk classes](https://stevenphan.ca/blog/agent-tool-risk-classes-read-write-irreversible/) covers.

## The nine checks and why each one is there

Here are the checks in the order the script runs them, with the reason for each.

1. **Clean working tree.** If you have uncommitted work, the agent's edits mix with yours and you cannot tell them apart in the morning. The script runs `git status --porcelain` and fails on any output, including untracked files.
2. **New branch.** The agent works on a branch with a prefix you choose (we used `agent/`), which has no commits beyond the base. A fresh branch means the whole night's work is one clean range you can review or throw away.
3. **Main protected, or push disabled.** The strongest protection is on the server, where nobody and nothing can push straight to main. Locally, you can also make pushing impossible for this clone. More on this below.
4. **Tests pass at the start.** If the suite is already red, you cannot use it as a signal. The script runs your test command and requires exit code 0.
5. **Budget and time limit set.** The script checks that your config has a positive money cap and a positive time limit. It cannot enforce them. It makes you write them down, which is half the value.
6. **No secrets nearby.** Two scans: environment variable names that look like credentials, and a few regex patterns over tracked files. Names only, never values.
7. **Kill file path is free.** A kill file is a path your agent runner checks between steps. If the file appears, the runner stops. The preflight confirms the path does not already exist (or the agent would stop instantly) and that you could create it.
8. **Logging is on.** The script appends a line to the log file. If you cannot write the log, you'll have no record of what happened.
9. **Restore point.** A git tag at the current commit, named with a prefix like `pre-agent-`. According to the [git documentation for tags](https://git-scm.com/docs/git-tag) (checked 2026-11-13), a lightweight tag is simply a name for an object, usually a commit, and the docs describe lightweight tags as meant for private or temporary labels. That's exactly what a restore point is.

For how to build the stop mechanism that checks 5 and 7 depend on, see [the kill switch, budget and loop guard post](https://stevenphan.ca/blog/agent-kill-switch-budget-loop-guard/).

## The preflight script and its config

The script reads a small JSON file, `agent-run.json`, from the repo root. This is the config from our demo:

```json
{
  "test_command": "python3 -B -m unittest discover -s tests -q",
  "budget_usd": 5,
  "time_limit_minutes": 240,
  "kill_file": "../STOP-AGENT",
  "log_file": "../agent-logs/session.log",
  "branch_prefix": "agent/",
  "base_branch": "main",
  "env_allowlist": ["PATH"]
}
```

The numbers are placeholders we picked. Choose your own. The kill file and log live one folder above the repo on purpose, so they never show up as untracked files in the tree you just required to be clean.

Each check is a small function that returns a pass flag and a message. Here's the git guard, the check with the most judgment in it:

```python
def check_push_guard(repo, cfg, attested):
    rc, out, _ = git(repo, "remote")
    remotes = out.split()
    if not remotes:
        return True, "no remotes configured, nothing to push to"
    bad = []
    for r in remotes:
        _, url, _ = git(repo, "remote", "get-url", "--push", r)
        if url.upper() not in {"DISABLED", "NO_PUSH"}:
            bad.append(r)
    hook = Path(repo) / ".git" / "hooks" / "pre-push"
    if not bad:
        return True, "push URL disabled on every remote"
    if hook.exists() and os.access(hook, os.X_OK):
        return True, "executable pre-push hook present (read it to confirm it blocks pushes)"
    if attested:
        return True, "you attested that the main branch is protected on the host"
    return False, "remote(s) " + ", ".join(bad) + " can push. Disable push ..."
```

That excerpt is from the file we ran (shortened in the last line). The git manual for [`git remote`](https://git-scm.com/docs/git-remote) (checked 2026-11-13) documents `git remote set-url --push` and `git remote get-url --push`, which is how the script reads the push URL. Setting the push URL to a value that is not a repository is a convention, not something the manual describes as a feature, and the manual notes that push and fetch URLs are expected to refer to the same place. We tried it in the sandbox: after `git remote set-url --push origin DISABLED`, `git push origin HEAD` printed `fatal: 'DISABLED' does not appear to be a git repository`. That's enough to stop an accidental push from that clone, but it's only a local setting. Anything that can run `git remote set-url` can undo it.

The secret scan is deliberately small. These are the patterns, and they are only a first filter:

```python
FILE_PATTERNS = [
    ("private key block", re.compile(r"-----BEGIN [A-Z ]*PRIVATE KEY-----")),
    ("aws style access key id", re.compile(r"\bAKIA[0-9A-Z]{16}\b")),
    ("github style token", re.compile(r"\bgh[pousr]_[A-Za-z0-9]{30,}\b")),
    ("quoted credential assignment", re.compile(
        r"""(api[_-]?key|secret|token|passw(or)?d)\s*[:=]\s*["'][^"'\s]{8,}["']""", re.I)),
]
```

A handful of regexes will miss plenty and will flag some harmless lines. For a real scan, use a dedicated tool. We compared the options in [GitHub secret scanning, Dependabot, TruffleHog and Gitleaks](https://stevenphan.ca/blog/github-secret-scanning-dependabot-trufflehog-gitleaks/). If a scan ever finds something real, follow [what to do if an API key leaks in a GitHub repo](https://stevenphan.ca/blog/what-to-do-if-api-key-leaked-in-github-repo/) before you do anything else. The environment check matters just as much, because anything in the environment your agent inherits can be read by it, printed into a log, or sent somewhere. Start the agent from a clean shell with only the variables it needs.

## Run it on a passing repo

The demo script builds a throwaway repo with one function, one test, an `agent/fix-add-docs` branch, a disabled push URL, and a `pre-agent-demo` tag. We ran the preflight with a cleaned environment (`env -i` plus PATH and HOME), so no stray variables leak in. This is the real output:

```text
[PASS] clean working tree: working tree clean
[PASS] new branch: on new branch 'agent/fix-add-docs'
[PASS] main protected or push off: push URL disabled on every remote
[PASS] tests pass at start: tests pass at start (python3 -B -m unittest discover -s tests -q)
[PASS] budget and time limit: budget 5 and time limit 240 min are set (your runner must enforce them)
[PASS] no secrets nearby: no secret-looking env var names, no pattern hits in tracked files
[PASS] kill file path: kill file path STOP-AGENT is free and its folder is writable
[PASS] logging on: log file session.log is writable
[PASS] restore point: restore point tag at HEAD: pre-agent-demo

9/9 checks passed. OK to start.
exit code: 0
```

Nine checks, nine passes, exit code 0. The kill file and log lines print only the file name, not the full path, so the output is the same on any machine.

## Run it on a broken repo

Next we broke the same repo in eight ways: switched back to `main`, deleted the restore tag, re-enabled pushing, changed the test's expected value so it fails, dropped `budget_usd` from the config, staged a `settings.py` with a fake quoted credential (the value is the plain text `not-a-real-key-0123456789`), created the kill file, and set an environment variable named `DEMO_SERVICE_TOKEN` to the word `placeholder`. Real output:

```text
[FAIL] clean working tree: 3 uncommitted or untracked path(s); commit or stash first
[FAIL] new branch: on 'main'; create a fresh branch first (git switch -c agent/<task>)
[FAIL] main protected or push off: remote(s) origin can push. Disable push (git remote set-url --push origin DISABLED), add a pre-push hook, or enable branch protection on the host and pass --attest-main-protected
[FAIL] tests pass at start: tests failing at start (exit 1): FAILED (failures=1)
[FAIL] budget and time limit: budget_usd missing or not positive
[FAIL] no secrets nearby: secret-looking env var names: DEMO_SERVICE_TOKEN; pattern hits: settings.py:1 (quoted credential assignment)
[FAIL] kill file path: STOP-AGENT already exists; the agent would stop at once. Remove it first
[PASS] logging on: log file session.log is writable
[FAIL] restore point: no tag matching 'pre-agent-*' at HEAD (git tag pre-agent-$(date +%Y%m%d-%H%M))

1/9 checks passed. DO NOT START.
exit code: 1
```

One check passes (logging), eight fail. Two things are worth noticing. The failed secrets check reports the variable name and the `settings.py:1` location but never the value. And the dirty-tree count says 3, because the edited test, the new `settings.py` and the changed config are all uncommitted.

One surprise came up while we built this. In the first version of the demo, the "failing test" check passed even though we'd changed the expected value, because the edit kept the file size the same and Python reused a cached bytecode file. The fix was `python3 -B`. The general lesson: make sure your test command does not trust stale caches.

## What the script can't check

Be honest about the limits so you don't treat a green run as a guarantee.

**It cannot see the server.** [GitHub's documentation on protected branches](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches) (checked 2026-11-13) says branch protection rules define whether collaborators can delete or force push to a branch and can set requirements for pushes, such as passing status checks. It also says each rule disables force pushes and deletion by default. That's the setting you want on main, but a local script cannot verify it, which is why ours accepts an explicit `--attest-main-protected` flag. The flag is you saying "I checked." Other hosts have their own versions, so read your host's docs.

**It cannot enforce anything.** A budget of 5 in a JSON file stops nothing by itself. Your runner has to count spend and stop. A time limit needs a timer that kills the process. The kill file needs code that looks for it between steps. The preflight confirms the settings exist, and the runner has to act on them.

**It cannot prove the agent behaves.** The checks cover the setup, not the work. They don't stop an agent from deleting tests in its own branch, adding a dependency, or making an odd network call. That's what the morning review is for.

**It cannot read your mind about secrets.** Names and patterns catch the obvious cases. They will not catch a password in a sentence, a token in a binary file, or a secret that's already in git history. We checked only tracked files in the working tree, not past commits.

**A restore tag covers less than you think.** It records committed, tracked files in this one repo. It does not protect ignored or untracked files, a local database, other folders, or a deleted `.git` directory. If the agent can reach anything you can't afford to lose, copy it somewhere the agent can't write, or run the agent in a container or disposable VM that only mounts a fresh clone.

**The secret scan skips the usual hiding place.** It reads tracked files only, so an ignored `.env` file or a credentials file in your home folder (cloud CLI logins, SSH keys, an SSH agent or git credential helper that can push) is invisible to it. Use throwaway, least-privilege credentials for the night, never production ones, and note that the demo's `git push` guard doesn't cover a second remote you add later.

**It doesn't limit the network or the bill.** An agent with open internet access can send data out or install packages. Restrict outbound access if your setup allows it, and set a hard spend cap or alert in your model provider's billing settings, because a number in `agent-run.json` caps nothing. Also remember the preflight runs your `test_command`, which executes the repo's code, so don't point it at a repo or config you don't trust.

**It makes no claim about any specific agent tool.** We didn't run a real agent here, and we didn't read any agent product's documentation for this post, so we don't say what any product does when you point it at a repo. Check your own tool's docs for how it handles permissions, working directories and limits.

## The morning review: five things to read first

When you come back, resist opening the full diff first. Read five summaries, each of which can send you to a specific place.

1. **Diff size.** How many files and lines changed, and how many commits. A tiny task that produced a huge diff is a red flag by itself.
2. **Test files touched.** Changes to tests deserve the first real read. An agent that makes a failing test pass by editing the test has changed the question, not found the answer. Read every modified test before you read the code it covers.
3. **Deleted files.** Deletions are easy to miss because they don't show up as green lines. The review lists them by name.
4. **New dependencies.** Look at changes to `requirements.txt`, `package.json`, lock files and similar. A new package is new code you didn't review, and it may also be a new network path.
5. **Network calls.** Added lines that contain `requests.`, `urllib`, `fetch(`, `curl`, a URL, and similar patterns. This is a grep over added lines, so it will miss clever code, but it catches the plain cases cheaply.

We simulated an overnight session in the demo with a plain commit: it added a `requests` import and a function that calls an example URL, changed the expected value in the test from 5 to 4, deleted `agent-run.json`, and added a `requirements.txt`. Then we ran the morning review against the restore tag:

```text
== Diff size ==
4 files changed, 5 insertions(+), 11 deletions(-)
commits: 1

== Deleted files ==
agent-run.json

== Test files touched (read these first) ==
M tests/test_app.py

== Dependency files touched ==
requirements.txt: requests==2.0.0

== Added lines that look like network calls ==
app.py: return requests.get("https://example.invalid/rate").json()
```

Every one of the five planted changes shows up in its own section. The review script reports facts. It doesn't decide whether a change is good or replace reading the code. If you want a way to attach a score to each diff so the riskiest ones surface first, see [reviewable AI diffs with scores](https://stevenphan.ca/blog/reviewable-ai-diffs-with-scores/).

If you read the five summaries and something looks wrong, the restore point is why you tagged. Check out the tag in a new worktree or branch, compare, and keep the good parts. These raw git commands are what the review script wraps, shown here for reference (not run here as written, but the script runs the same underlying commands):

```bash
git diff --shortstat pre-agent-TAG HEAD
git diff --name-status pre-agent-TAG HEAD
git diff -U0 pre-agent-TAG HEAD
```

## Download the demo

[Download the overnight agent preflight demo](https://stevenphan.ca/downloads/overnight-unattended-coding-agent-checklist.zip) and unzip it into a new folder. You need Python 3.10 or newer, git and bash. There's no network access, API key or model involved. Run it like this:

```bash
bash run_demo.sh
```

The zip holds `README.md`, `run_demo.sh`, `make_demo_repo.sh`, `src/preflight.py` and `src/morning_review.py`. We ran the demo from a fresh unzip and got the output shown above. To use the checks on your own project, copy the config, set your own test command and limits, and call the script from whatever launches your agent:

```bash
python3 src/preflight.py --repo /path/to/repo && start-your-agent-here
```

That block wasn't run as written, since `start-your-agent-here` is a placeholder for your own launcher. The `&&` is the point: the agent only starts if the preflight exits with 0.

## FAQ

### What should I check before leaving a coding agent running overnight?

Check nine things (and keep backups, credentials, network and billing in mind, since the script doesn't cover them): a clean git tree, a fresh branch, main protected or push disabled, tests passing at the start, a budget and time limit, no secrets in the environment or repo, a free kill file path, working logs, and a restore tag. The demo script checks all nine and exits with code 1 if any fail.

### How do I stop a coding agent from pushing to main?

The strongest option is branch protection on your host, which GitHub documents as controlling force pushes, deletion and push requirements (checked 2026-11-13). Locally, you can set the push URL of each remote to an invalid value with `git remote set-url --push`, and we confirmed a push then fails. A local setting can be undone, so use the host setting too.

### Does a preflight script enforce the budget and time limit?

No. The script only checks that a positive budget and time limit are written in the config. Your agent runner has to count spend, run a timer and watch for the kill file. The preflight is the gate before the start, and enforcement is a separate job.

### What should I review first in the morning?

Start with five summaries: diff size, test files touched, deleted files, new dependencies, and added lines that look like network calls. Read modified tests before the code they cover. Then use the restore tag to compare or roll back anything you don't trust.

### Is a regex scan enough to keep secrets away from an agent?

No. Our scan uses four simple patterns plus environment variable names, and it only looks at tracked files in the working tree, not git history. It's a quick first filter. Use a dedicated scanner for real coverage and start the agent from a shell that holds only the variables it needs.

### Do the demo results show how a real agent behaves?

No. There's no model in the demo. The overnight session is a set of plain git commands we wrote, so the output only shows what the scripts report for those changes. Real agents and real repos will produce different diffs.

## Where to go next

Build the stop mechanism that the limits and kill file depend on in [the kill switch, budget and loop guard post](https://stevenphan.ca/blog/agent-kill-switch-budget-loop-guard/). Put structural rules in place before the agent writes code with [architecture rules before an agent writes your game](https://stevenphan.ca/blog/architecture-rules-before-agent-writes-game/). Then, when you want the review to be faster, add scores to your diffs with [reviewable AI diffs with scores](https://stevenphan.ca/blog/reviewable-ai-diffs-with-scores/).
