Night Shift V3
Published by alexandre-mrt in nightshift-setup
What this skill does
Night shift v3: hybrid agent teams + subagents. Uses Claude Code Agent Teams for audit/debugging phases (adversarial review, competing hypotheses) while keeping ralph-loop + playbooks + worktree agents for execution. Experimental — requires CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1. Trigger on 'night shift v3', 'night-shift-v3', 'night mode v3'.
Add Night Shift V3 to your agent
Review the source and files first. When you are ready, copy the prompt instruction or use the CLI command supported by your environment.
Install with a prompt
Paste this into a compatible coding agent:
add this skill "night-shift-v3" from https://github.com/alexandre-mrt/nightshift-setupInstall with the CLI
Run this command in a controlled environment after reviewing the repository:
npx skills add https://github.com/alexandre-mrt/nightshift-setup --skill night-shift-v3Skill instructions
Night Shift v3 — Agent Teams Hybrid
Autonomous work mode for one night (6-8h). Delivers a review-ready PR by morning.
What's new vs v2: uses Claude Code Agent Teams for audit and debugging phases. Teammates challenge each other's findings instead of producing isolated reports.
Requires: CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 in settings.json or environment.
Architecture Overview
┌──────────────────────────────────────────────────────────────┐
│ NIGHT SHIFT v3 │
│ │
│ EXECUTION (unchanged from v2) │
│ ├─ Ralph-loop → fresh context each iteration │
│ ├─ Subagents with worktree isolation (night-coder, etc.) │
│ ├─ Playbooks / execution memory │
│ └─ NIGHT_SHIFT_STATE.md as iteration memory │
│ │
│ AUDIT (NEW — Agent Teams) │
│ ├─ Team lead = orchestrator │
│ ├─ 4 teammates: security, code, readability, research │
│ ├─ Inter-agent messaging: challenge each other's findings │
│ ├─ Shared task list with quality hooks │
│ └─ Converge on consensus before fixes │
│ │
│ DEBUGGING FALLBACK (NEW — Agent Teams) │
│ ├─ Triggers after night-fixer fails 3x │
│ ├─ 3-5 teammates test competing hypotheses │
│ ├─ Adversarial debate to find root cause │
│ └─ Consensus → targeted fix │
└──────────────────────────────────────────────────────────────┘
Step 0: Pre-flight Check
Same as v2. Run the pre-flight questionnaire (AskUserQuestion for each batch). Skip if NIGHT_SHIFT_STATE.md already exists.
Additional v3 check: verify agent teams are enabled:
# Check the feature flag
echo $CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS
If not enabled, warn the user and offer to fall back to /night-shift (v2).
After pre-flight, save NIGHT_SHIFT_ENRICHED_SPEC.md as in v2.
Pre-flight question categories (same as v2)
- Scope boundaries
- Technical decisions
- Edge cases and error handling
- Testing expectations
- UI/UX expectations (if frontend)
- Priorities and tradeoffs
- What NOT to do
MANDATORY: Start the Loop
Same ralph-loop invocation as v2:
Skill(skill: "ralph-loop", args: "Read NIGHT_SHIFT_STATE.md and NIGHT_SHIFT_ENRICHED_SPEC.md. Execute the next pending task using specialized agents. Update state after each task. --max-iterations 100 --completion-promise 'NIGHT_SHIFT_COMPLETE'")
If continuing (state file exists):
Skill(skill: "ralph-loop", args: "Read NIGHT_SHIFT_STATE.md and continue execution. Pick next pending task, spawn agents, validate, update state. --max-iterations 100 --completion-promise 'NIGHT_SHIFT_COMPLETE'")
Loop Architecture (same as v2)
Ralph-loop gives fresh context each iteration. NIGHT_SHIFT_STATE.md is the only memory.
┌─────────────────────────────────────────────┐
│ EACH ITERATION │
│ │
│ 1. Read NIGHT_SHIFT_STATE.md │
│ 2. No state? → First iteration (plan) │
│ Has state? → Pick next pending task │
│ 3. Spawn specialized Agent (worktree) │
│ 4. Merge branch, validate, commit │
│ 5. Update NIGHT_SHIFT_STATE.md │
│ 6. All done? → AUDIT PHASE (Agent Teams) │
│ Not done? → exit → hook re-feeds │
└─────────────────────────────────────────────┘
First Iteration: Plan (same as v2)
If NIGHT_SHIFT_STATE.md does not exist:
- Locate and read spec + enriched spec
- Analyze context — Explore agents in parallel for existing repos, scaffold for new ones
- Documentation research — Context7, one agent per library
- Produce plan →
NIGHT_SHIFT_LOG.md - Initialize state →
NIGHT_SHIFT_STATE.md - Initialize problems log →
NIGHT_SHIFT_PROBLEMS.md - Start first task(s) if time remains
Execution Iterations (same as v2)
Unchanged from v2. Use orchestration by default:
- Read state, pick next task(s)
- Read playbooks from
~/.claude/orchestration/playbooks/ - Spawn agents:
night-coder(worktree),night-tester(worktree),Explore(no isolation) - Merge worktree branches, validate (build + test + lint)
- If validation fails → try
night-fixer(max 3 attempts) - If night-fixer fails 3x → ESCALATE TO AGENT TEAM DEBUGGING (see below)
- Update state, commit checkpoint, exit for next iteration
Agent type selection (same as v2)
| Task type | subagent_type | isolation |
|---|---|---|
| New feature / component | night-coder | worktree |
| Tests for existing code | night-tester | worktree |
| Config / scaffolding | night-coder | none |
| Build/test/lint failure | night-fixer | worktree |
| Research / exploration | Explore | none |
NEW: Agent Team Debugging (replaces "skip after 3 failures")
When night-fixer fails 3 times on the same error, instead of logging + skipping:
Trigger condition
night-fixer attempt 1 → fail
night-fixer attempt 2 → fail
night-fixer attempt 3 → fail
→ ESCALATE to Agent Team Debugging
How it works
-
Create the debugging team — tell Claude to spawn an agent team:
Create an agent team to debug this error. Spawn 3-5 teammates, each investigating a different hypothesis. They should talk to each other to challenge and disprove theories. The error is: <paste full error output> Relevant files: <list files> What was already tried (all failed): - Attempt 1: <what night-fixer tried> - Attempt 2: <what night-fixer tried> - Attempt 3: <what night-fixer tried> Each teammate must propose a DIFFERENT root cause theory. They must actively try to disprove each other's theories. Converge on a consensus fix. -
Teammates investigate in parallel — each tests a different hypothesis
-
Inter-agent debate — they message each other to challenge findings
-
Consensus — the team converges on the root cause
-
Fix — the lead (or a designated teammate) applies the fix
-
Validate — run build + test + lint
-
Clean up — shut down teammates, clean up team resources
Fallback
If the agent team also fails to resolve the error:
- Log to
NIGHT_SHIFT_PROBLEMS.mdwith full context (hypotheses explored, why each failed) - Mark task as
[BLOCKED]with the team's findings - Move to next independent task
State tracking
Add to NIGHT_SHIFT_STATE.md:
### Debug Escalation: <task>
- night-fixer attempts: 3 (all failed)
- Agent team spawned: yes
- Hypotheses tested: <list>
- Resolution: <fixed | blocked>
NEW: Agent Team Audit (replaces parallel isolated reviewers)
What changed from v2
v2: 4 reviewers run in parallel as subagents, each produces an isolated report, orchestrator consolidates.
v3: 4 reviewers run as an Agent Team. They read each other's findings and challenge them in real-time.
When to trigger
When all implementation tasks are marked [x] in NIGHT_SHIFT_STATE.md.
Audit loop cycle (minimum 3 loops)
Each loop:
-
Create the audit team:
Create an agent team to audit this codebase. Spawn 4 teammates: 1. Security reviewer — scan for secrets, injection, auth flaws, input validation, OWASP top 10. Focus on: <changed files> 2. Code quality reviewer — check DRY, type safety, resource leaks, dead code, edge cases. Focus on: <changed files> 3. Readability reviewer — check complexity, naming, patterns, simplification opportunities. Focus on: <changed files> 4. Research reviewer — search docs/internet for known issues with the dependencies used, missing features, production best practices. IMPORTANT: teammates MUST challenge each other's findings. - If security finds a flaw, code quality checks if the pattern exists elsewhere - If readability proposes a refactor, security validates it doesn't open vulnerabilities - If research finds a known issue, all others check if the codebase is affected Rate each finding: critical / high / medium / low. Only report critical and high findings for immediate fixing. -
Team works: teammates investigate, message each other, converge on consensus findings
-
Lead synthesizes: consolidated report with severity ratings, cross-validated by all teammates
-
Fix critical + high issues — spawn
night-fixeragents (worktree) for each fix -
Commit + validate — build + test + lint
-
Clean up team — shut down teammates, clean up resources
-
Start next audit loop — create a NEW team for fresh perspective
Exit condition
A full audit loop returns ZERO critical or high findings across all 4 reviewers.
Minimum 3 loops even if clean — first loop almost always finds issues.
Why Agent Teams are better here
| v2 (subagents) | v3 (agent team) |
|---|---|
| Security finds XSS in file A | Security finds XSS in file A |
| Code reviewer doesn't know about it | Security messages code reviewer: "check if this pattern exists elsewhere" |
| Orchestrator manually cross-references | Code reviewer searches, finds 3 more instances |
| Might miss related issues | Readability reviewer confirms refactoring won't introduce new issues |
Final Steps (same as v2)
After audit loops pass:
- Final validation — full build + test + lint suite
- Visual verification (if frontend) — puppeteer screenshots
- Write summary → append to
NIGHT_SHIFT_LOG.md - Update timestamps in
NIGHT_SHIFT_STATE.md - Create PR via
gh pr create - Signal completion →
<promise>NIGHT_SHIFT_COMPLETE</promise>
Mid-course Re-evaluation (same as v2)
At ~50% task completion: re-read spec, compare vs implementation, adjust plan if needed.
Context Management Rules
Same as v2, plus:
- Agent teams consume significant tokens — only use for audit and debugging, not for regular task execution
- Clean up teams immediately after each audit loop — don't let teammates linger
- Agent team prompts should reference changed files — don't ask them to review the entire repo
Error Recovery (same as v2, plus agent teams)
Same as v2, plus:
- Orphaned agent team? → check for running teammates, shut them down, clean up
- Agent team creation fails? → fall back to v2 parallel subagent audit
- Feature flag not set? → fall back to v2 entirely, warn user
Anti-Hallucination Protocol
Same as v2. See references/anti-hallucination.md. All rules apply:
- Never guess APIs, types, signatures
- Never leave silent traces
- When uncertain: log to
NIGHT_SHIFT_PROBLEMS.mdand move on - Mark uncertain code with
// NIGHT-SHIFT-REVIEW: <reason> - Blocked > Broken
Critical Rules
All v2 rules apply, plus:
- Always clean up agent teams — orphaned teammates waste tokens all night
- Agent teams ONLY for audit and debugging — execution stays with subagents + worktrees
- If agent teams feature is unstable — fall back to v2 behavior, never block on it
- Max 5 teammates per team — beyond this, coordination overhead kills the benefit
- Each audit loop = fresh team — don't reuse a team across loops (stale context)
Files included
- references/anti-hallucination.md
- SKILL.md

