Overnight

Run the project unattended until the task queue is empty or a circuit breaker triggers. Combines Autonomous mode with execution h…

BasharAmso 1 updated 3mo ago
Claude CodeGeneric
View source ↗
# Command: /overnight

> Run the project unattended until the task queue is empty or a circuit breaker triggers. Combines Autonomous mode with execution hardening, auto-learning, and a morning summary.

---

## When to Use

Before stepping away for an extended period (overnight, lunch, etc.) when you have a populated task queue and want the system to make progress without you.

---

## Arguments

- `/overnight` — Run with defaults (50 cycles, 4 hours)
- `/overnight --cycles N` — Override cycle limit (default 50)
- `/overnight --hours N` — Override time limit in hours (default 4)
- `/overnight --pr` — Create a PR with all changes when done

---

## Procedure

### Step 1: Validate Preconditions

Read `.claude/project/STATE.md` and check:

| Check | Condition | If Failed |
|-------|-----------|-----------|
| Task queue | Next Task Queue has >= 1 task | Print: "No tasks queued. Run `/run-project` to generate tasks first." Stop. |
| No blockers | Active Task status is not `Blocked` | Print: "Active task is blocked. Resolve the blocker first." Stop. |
| Git clean | `git status --porcelain` returns empty | Print: "Working tree has uncommitted changes. Commit or stash them first." Stop. |

If any hard check fails, stop and do not proceed.

If there are unprocessed events in EVENTS.md: warn but proceed (events will be processed first, which is correct).

### Step 1.5: Verify CC Permissions

Overnight mode requires broad tool access to run unattended. Check whether permissions are configured:

1. Read `~/.claude/settings.json` (user settings).
2. Check if the `permissions.allow` array includes broad entries for: `Bash`, `Read`, `Edit`, `Write`.
3. **If any are missing or restricted by patterns** (e.g., `Bash(git *)` instead of `Bash`):
   - Print warning:
     ```
     Your Claude Code permissions use granular patterns that will prompt during overnight execution.
     Overnight mode needs broad tool access to run unattended.

     Current: [list restricted tools]
     Recommended: Broad "Bash", "Read", "Edit", "Write" allows with deny/ask guardrails

     Note: This changes your global permissions for all sessions, not just overnight.
     Your deny and ask lists are preserved as safety guardrails.

     Want me to update your permissions for unattended mode?
     ```
   - If user agrees: update `~/.claude/settings.json` to use broad allows while preserving existing deny/ask lists.
   - If user declines: print "Proceeding, but expect permission prompts during execution." Continue (don't block). Do not modify settings.
4. **If already configured:** skip silently.

### Step 2: Configure Overnight Mode

1. Set Current Mode to **Autonomous** in STATE.md (same as `/set-mode auto`).
2. Set `Run Type = Overnight` in STATE.md Run Cycle section.
3. Set `Max Cycles This Run` = 50 (or `--cycles` argument).
4. Set `Time Limit Hours` = 4 (or `--hours` argument) — write to STATE.md Run Cycle as a temporary field.
5. Set `Consecutive Failures = 0` and `Phantom Completions = 0`.
6. Set `Session Started` = current timestamp, `Checkpointed = No`.
7. Set environment variable `BASHI_OVERNIGHT_MODE=true` (enables git guard override for inter-cycle commits).

Record the task count from Next Task Queue for later reporting.

### Step 3: Print Configuration

Overnight Mode Activated

  • Cycle limit: [N] cycles
  • Time limit: [N] hours
  • Tasks in queue: [count]
  • Git verification: Enabled
  • Circuit breakers: Consecutive failures (3), time limit, phantom completions (2)
  • Parallel execution: [Enabled (max N slots) | Disabled] — independent tasks dispatch simultaneously
  • Auto-compaction: Every 8 cycles
  • Auto-learning: Will run at completion
  • CC Permissions: Verified (broad access) | Warning (granular patterns, expect prompts)

Important: This run depends on your Claude Code session staying active.

  • Disable sleep/hibernation, or use a keep-awake tool
  • Do not close the terminal or VS Code window
  • You can check progress anytime by opening STATE.md

Starting unattended execution...


### Step 4: Create Git Marker Commit

Run:
```bash
git commit --allow-empty -m "overnight: starting — [count] tasks queued"

Record the marker commit hash for later use in the morning summary (git diff --stat).

Step 5: Execute

Run the /run-project procedure. The existing run-project loop handles everything:

  • Cycle execution with pre-cycle snapshots
  • Stop condition evaluation (now including circuit breakers, time limit, phantom completions)
  • Git verification after each task (triggered by Run Type = Overnight)
  • Inter-cycle commits (one commit per completed task; for parallel cycles, one commit per successfully merged slot)
  • Auto-compaction every 8 cycles
  • Planning review gate for planning skills
  • State updates

The /run-project loop will continue until a stop condition triggers or cycles are exhausted.

Step 6: On Completion — Auto-Learn

When the run ends (for any reason):

  1. Read STATE.md: Completed Tasks Log (filter tasks with completion timestamp >= Session Started from this run).
  2. Read Failed Approaches table for entries from this run.
  3. Analyze patterns:
    • Which skills succeeded vs failed? Are there common failure reasons?
    • Did the same agent/skill fail repeatedly?
    • Are there reusable insights about the tech stack, architecture, or workflow?
  4. Write lessons to AI-Memory automatically using the analysis procedure from /learn (Steps 1-2) — no user confirmation needed.
  5. Log: "Auto-learning: [N] lessons extracted and saved to AI-Memory."

If no extractable patterns found: log "Auto-learning: no notable patterns this run."

Uses STATE.md data, not conversation history (which may have been compacted during the run).

Step 7: Generate Morning Summary

Write docs/OVERNIGHT_SUMMARY.md:

# Overnight Run Summary

> Generated: [timestamp]
> Duration: [elapsed time from Session Started to now]
> Run Type: Overnight

## Results

| Met

Maintain Overnight?

Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.

[Overnight on getagentictools](https://getagentictools.com/loops/basharamso-command-overnight?ref=badge)