How to run Claude Code autonomously (overnight, on a backlog)
To run Claude Code autonomously, give it three things: a ranked queue it pulls from, a loop prompt (pull → work → complete → repeat), and hard safety gates that stop money, credentials and publishing for a human. It then clears your backlog unattended — overnight included.
What does running Claude Code autonomously actually require?
Out of the box, Claude Code does one task and waits. To run it autonomously you need four things — and the missing ones are usually why "set it loose" turns into chaos:
- A backlog it can read. The agent needs an unambiguous "what's next?" — one ranked list, not five P0 labels across three tools.
- A loop. A prompt that says: pull the next task, work it, mark it done, repeat — and stop on an empty queue instead of inventing work.
- State, so it doesn't redo or collide. A task it's working on must be marked taken, so a re-run (or a second session) doesn't grab the same thing.
- Safety gates. Reversible work runs free; irreversible actions (money, credentials, publishing, deletes) must stop and wait for you.
Step by step: put Claude Code on a backlog
- Write your work as one ranked queue. Drop the tasks into a single global priority order — the agent will work them top to bottom. (A shared queue like TaskPeace is built for exactly this; you rank once, no statuses to babysit.)
- Connect Claude Code over MCP. One line installs the server so Claude Code can call
get_next_task,complete_taskandflag_needs_human:
See the Claude Code setup guide for the exact steps.curl -fsSL https://taskpeace.com/install.sh | bash - Paste the autopilot prompt. It tells Claude Code to loop — pull → work → complete → repeat — auto-scopes to the project's working directory, stops on an empty queue, and keeps hard gates on money / credentials / publishing. Grab it at taskpeace.com/autopilot-prompt.txt.
- Let it run. Claude Code pulls the top task with full context, does the work in your repo, logs a result on completion, and moves to the next — until the queue is empty, blocked, or it flags something for you.
- Watch it (optional). The live Sessions cockpit shows what the agent is on right now, what's idle, throughput, and real value-per-token.
How do I run Claude Code overnight?
A loop prompt keeps Claude Code working, but a closed terminal window kills the process. To leave it running while you're away, wrap the session so it survives disconnect and the machine staying awake. On macOS:
caffeinate -dimsu claude # keeps the Mac awake on power
# run that inside a tmux session so a closed window doesn't stop it:
tmux new -s agent 'caffeinate -dimsu claude'
# detach with Ctrl-b then d — it keeps running. Re-attach: tmux attach -t agent
The loop pulls and completes tasks until the queue drains, then stops — so an overnight run does real work and ends cleanly rather than spinning.
What should never run unattended?
This is the difference between "autonomous" and "reckless." Autonomy on reversible work (edit, test, commit to a branch, deploy to a preview) is a productivity win. Autonomy on irreversible actions is a liability. TaskPeace's autopilot prompt encodes these gates so an unattended run stays trustworthy.
Frequently asked questions
Can Claude Code run by itself?
Yes — give it a ranked queue to pull from, a loop prompt, and safety gates, and it clears the backlog on its own, stopping when the queue is empty or it hits a gate.
How do I give Claude Code a to-do list it works through?
Put the tasks in a shared priority queue and connect Claude Code over MCP. It calls get_next_task to pull the top task with context, works it, calls complete_task, and repeats.
How do I keep it running overnight?
Launch the session in tmux (survives a closed window) wrapped in caffeinate -dimsu (keeps the Mac awake). The loop ends cleanly on an empty queue.
Won't it waste tokens?
One ranked queue means there's a single, deterministic next task (no wrong-thing work), and leasing stops redo and collisions. The cockpit shows value-per-token so you can see which runs pay off.
Run your backlog free → Run several Claude Code sessions in parallel →