~/guides/OVERNIGHT.md

Guides / Claude Code

Let Claude Code run all night with claude -p, --allowedTools and --max-turns, then just review in the morning

Give Claude Code a task list before bed. claude -p, --allowedTools and --max-turns keep it from stalling or looping; review logs and git diff in the morning.

Normally Claude Code asks you Yes at every step, so the moment you fall asleep it just sits there waiting. This is the full version of my OVERNIGHT reel: three official settings plus a small script that works through a task list all night, so in the morning you only review. Every command and flag was checked against the official Claude Code docs on 2026-11-17.

01What you get: a whole task list done overnight

Reel frame: tasks.txt with ten tasks on the laptop, Claw'd beside it, header Claude Code runs all night
Reel frame: ten tasks before bed, just review in the morning.

When you're done you'll have:

  1. A tasks.txt: one task per line.
  2. An overnight.sh that hands each line to claude -p without stopping to ask you.
  3. A logs/task-N.json record per task, plus one line with the time and exit code.
  4. In the morning, git diff shows what changed; merge only after you check.
Reel frame: a stack of Allow Edit? / Allow Bash? 1. Yes 2. No prompts, sign says keeps asking Yes
Reel frame: it keeps asking Yes; fall asleep and it's stuck.

02Step 1: write one task per line in tasks.txt

Create tasks.txt in your project folder. Each line is one small, clearly worded task, ideally touching only one or two files. This is the list from my reel (first three lines):

tasks.txt (example)
Add a JSDoc comment to src/cart.js and write a small test in test/cart.test.js
Add a JSDoc comment to src/price.js and write a small test in test/price.test.js
Add a JSDoc comment to src/date.js and write a small test in test/date.test.js
Editor view of tasks.txt: ten lines of Add a JSDoc comment to src/….js and write a small test
The real tasks.txt from my reel, ten tasks.

03Step 2: three settings so it never stalls or loops

① claude -p (or --print): no chat session, it exits when done. The docs describe it as running non-interactively, which is what scripts need.

Claude Code docs, headless page: Basic usage with the claude -p "Find and fix the bug in auth.py" example
Official docs: -p runs non-interactively (captured 2026-11-17).

② --allowedTools "Read,Edit,Write": list the tools it may use without asking. Anything not listed that needs approval is denied instead of waiting all night for your Yes.

Docs headless page: Auto-approve tools, the --allowedTools "Bash,Read,Edit" example and text
Official docs: --allowedTools auto-approves the listed tools; other calls needing approval are denied.

③ --max-turns 8: caps how many agentic turns it takes (print mode only; no limit by default). It stops at the cap instead of looping all night.

Docs CLI reference: the --max-turns row, Limit the number of agentic turns (print mode only)
The --max-turns row in the official CLI reference.

04Step 3: one loop runs the whole list

Save this as overnight.sh in your project folder. It reads tasks.txt line by line, runs claude -p once per task, saves the result to logs/task-N.json and prints the time and exit code (0 = success).

overnight.sh (Mac / Linux / Git Bash on Windows)
#!/bin/bash
# overnight.sh: one run per task
mkdir -p logs
n=0
while IFS= read -r task; do
  n=$((n+1))
  claude -p "$task" \
    --allowedTools "Read,Edit,Write" \
    --max-turns 8 \
    --output-format json \
    < /dev/null > "logs/task-$n.json"
  rc=$?
  echo "$(date +%H:%M) task $n exit=$rc"
done < tasks.txt
Editor view of overnight.sh: a while loop running claude -p with --allowedTools, --max-turns 8, --output-format json
The real overnight.sh from the reel.
  1. Make a git branch first: git checkout -b overnight
  2. Before bed, run in a terminal: bash overnight.sh
  3. Keep the computer awake and the laptop plugged in.

05Step 4: in the morning, read the logs and the diff, then merge

Reel frame: tasks.txt with ten tasks, header in the morning just review the logs and the diff
Reel frame: in the morning you just review.
  1. Read each printed line: exit=0 succeeded; for anything else, open that logs/task-N.json to see why.
  2. Run git diff (or git diff main) and go through the changes.
  3. Run your tests once to make sure nothing broke.
  4. Merge back only when it's fine; throw away what you don't like with git restore.

06Good to know

  1. Don't use --dangerously-skip-permissions. The official CLI reference says it equals bypassPermissions: nothing is asked any more, which is the riskiest choice for an unattended night. Allow only the tools you need with --allowedTools.
  2. Run on a git branch or in a worktree and merge only after checking, so you can throw the whole batch away.
  3. This example allows Read, Edit and Write but not Bash, so it can't run commands (tests included). Add specific commands when needed instead of opening all of Bash.
  4. Every task uses your plan's usage or API spend; try two or three tasks first, check the logs, then queue ten.
  5. Flags are as documented on 2026-11-17 and may change; check claude --help before running.

Sources

Related guides