Short answer
Write a task brief that states the outcome, the limits and how the agent will prove it is done, then make the agent keep a progress log and save a checkpoint after each step. Cap its time, spending and access before you leave, so the worst case by morning is unfinished work rather than damage.
Follow-up question What should you check in the morning?
Coding agents and desktop assistants can now keep working for hours: converting a codebase, cleaning a large spreadsheet folder, drafting a long report from many files. Leaving one running overnight is tempting. It also means nobody is there when the agent gets confused, so everything it needs has to be decided before you go to bed.
Three things make an overnight handoff work. A task brief that says what finished looks like. Checkpoints, meaning saved, recoverable states after each piece of work, plus a log in plain words. And caps on time, money and access, so a stuck or misled agent can only waste a night, not cause harm.
Why long tasks go wrong
Anthropic's engineers described two habits they saw when agents worked across many sessions. First, the agent tried to do everything at once, ran out of room in its context window (the amount of text a model can hold in view at one time) halfway through, and left the next session to guess what had happened. Second, a later session would look at the partial work, decide it seemed finished, and stop.
Their fix was simple and borrowed from how human teams hand over shifts. The agent writes a list of everything that must be true at the end, works on one item at a time, records what it did in a progress file, and saves the project after each item. A fresh session reads the log first instead of guessing.
OpenAI's guidance for long-running work in ChatGPT and Codex asks for the same ingredients in the prompt: an outcome, constraints and verification. In the ChatGPT desktop app, Codex CLI and the IDE extension, typing /goal starts Goal mode, where the goal text serves both as the first prompt and as the test for completion.
A worked task brief
Suppose you have 400 product descriptions in a folder of text files and want each rewritten to a house style, with a summary table at the end. Here is a brief for the night.
/goal Rewrite every product description in /catalog/drafts to match /catalog/STYLE.md.
Outcome:
- Each file in /catalog/drafts has a rewritten version in /catalog/rewritten with the same file name.
- /catalog/report.csv lists every file with: done, skipped, or needs-review, and one reason.
Constraints:
- Never edit or delete anything in /catalog/drafts. Write only to /catalog/rewritten and /catalog/report.csv.
- Do not go online. Do not sign in to anything. Do not buy, send or publish anything.
- If a description contains a price, a safety claim or a legal term, copy it unchanged and mark needs-review.
Working method:
- Before starting, create /catalog/PROGRESS.md with the full list of files, all marked "todo".
- Work through files in batches of 20. After each batch, update PROGRESS.md and save a checkpoint.
- If the same error happens three times, stop and write what went wrong in PROGRESS.md.
Done means: every file is in report.csv, and a spot check of 10 random files against STYLE.md passes.Each section has a job. The outcome is a result you can count, not an activity. The constraints name the only folders it may change and rule out everything you would want to approve in person. The working method creates the checkpoints and the log. The last line tells the agent how to check itself, so it can't declare victory early.
Try it: Before your first overnight run, give the same brief a 20-minute version during the day, on a copy of 30 files. Read PROGRESS.md as it updates and fix the brief wherever the agent hesitated.
Caps, checkpoints and logs
| Safeguard | How to set it | What it protects |
|---|---|---|
| Time cap | A stop time in the brief, or a timeout in your scheduler | A loop that runs all night |
| Spend cap | A monthly or daily budget on the account that pays for the model | A surprise bill from retries |
| Step cap | "Stop after three identical errors" | Repeating the same failure |
| Access | A copy of the files, write access to one folder only | Your originals |
| Checkpoints | A git commit or a dated copy after each batch | Losing good work to a later mistake |
| Log | PROGRESS.md in plain words | Not knowing what happened |
Anthropic's guide to building agents also recommends a rule that ends the run, such as a limit on how many rounds the agent may take, and testing in a sandbox, an isolated environment where mistakes stay contained. OpenAI notes that a goal runs under the permission and approval settings you already have, no wider, and pauses when it needs your decision. Plan for that pause. If a question arrives at 1 a.m., the work simply waits until morning.
Two practical points for a local run. Keep the computer awake (the ChatGPT desktop app has a setting to prevent sleep while a task runs), and never leave the agent with saved passwords, payment details or an open session on your bank or email. Nothing in an overnight brief should require them.
What should you check in the morning?
Start with the log, not the output. Open PROGRESS.md and check that it ends cleanly: a final "done" line, or a clear reason for stopping. Then compare the counts. If the folder had 400 files, the report should list 400; a gap usually points to a crash or a batch the agent skipped without saying so.
Next, sample the work yourself. Pick ten files at random, not the first ten, and read them against the style guide. Look closely at everything marked needs-review, since those are the cases you asked to see. If the agent saved checkpoints, you can roll back any batch that went wrong without throwing away the rest.
Finally, check the edges of what it was allowed to do. Confirm the original folder is unchanged, look at the account's usage for the night, and scan for files created outside the permitted folder. Then improve the brief with one rule for each surprise, so the next night needs less checking.
Sources
- Long-running work — OpenAI (ChatGPT Learn documentation), September 11, 2026
- Effective harnesses for long-running agents — Anthropic, November 26, 2025
- Building effective agents — Anthropic, December 19, 2024