Overnight-mode.md A developer published a Claude Code Stop hook that enforces an "overnight mode" for unattended agents: while a marker file at ~/.agents/OVERNIGHT exists, the hook inspects the agent's final message and blocks the turn if it ends with a question, instructing the agent to pick the most reasonable reversible option and keep working. After two blocks in a single session the hook allows the stop, so a genuinely stuck agent can still finish. The setup also includes a skill file and a test procedure using piped JSON payloads and exit codes. Add an "overnight mode" Stop hook to this repository for Claude Code. Goal: when overnight mode is on, an unattended agent must never end its turn by asking a human a question. If its final message asks one, the hook blocks the stop and tells it to pick the most reasonable based on what it knows about the project, task, and my preferences reversible option and keep working. After two blocks in one session it lets the stop through, so a truly stuck agent can still finish. Overnight mode is on only while the file ~/.agents/OVERNIGHT exists. I create it before leaving and delete it in the morning. Steps: 1. Create Tools/hooks/guard overnight questions.py with exactly the script below adjust the wording of MESSAGE only if I ask . 2. Register it in .claude/settings.json under hooks.Stop . Merge into any existing hooks; do not overwrite other entries. Use this entry: {"hooks": {"type": "command", "command": "python3 "${CLAUDE PROJECT DIR}/Tools/hooks/guard overnight questions.py""} } 3. Test it by piping JSON payloads shown below and checking exit codes. Clean up any test marker files afterward, and restore ~/.agents/OVERNIGHT to however it was before. 4. Create the skill .claude/skills/overnight-mode/SKILL.md with the content below. Then add one line to AGENTS.md or CLAUDE.md: "For unattended or overnight work, use the overnight-mode skill." Put the skill where this repo keeps its skills if that isn't .claude/skills/ . 5. Show me the diff. Do not commit unless I say so. Script: python /usr/bin/env python3 import json import re import sys import tempfile from pathlib import Path ​ MAX BLOCKS = 2 TAIL CHARS = 500 CODE FENCE RE = re.compile r" . ? ", re.DOTALL ASK RE = re.compile r"\?|\b should i|shall i|want me to|do you want|would you like|let me know if|whether|which|how |your call \b", re.IGNORECASE, MESSAGE = "Overnight mode: nobody is available, so do not end your turn with a question.\n" "Pick the most reasonable option based on what you know about me and the project/task that is reversible and needs no human, start it now, and keep working. " "Put debatable calls on a morning list in your report.\n" "Stop only when every remaining item truly needs a human irreversible or external . " "Then end with a plain NEEDS INPUT statement listing those items, with no question." ​ ​ def overnight : return Path.home / ".agents" / "OVERNIGHT" .exists ​ ​ def transcript message path : try: lines = Path path .read text encoding="utf-8" .splitlines except OSError, TypeError : return "" for line in reversed lines : try: entry = json.loads line except ValueError: continue message = entry.get "message" or {} if entry.get "type" = "assistant" or message.get "role" = "assistant": continue content = message.get "content" if isinstance content, str : return content text = "\n".join part.get "text", "" for part in content or if part.get "type" == "text" if text.strip : return text return "" ​ ​ def asks question text : tail = CODE FENCE RE.sub "", text or "" .strip -TAIL CHARS: return bool ASK RE.search tail ​ ​ def main : try: payload = json.load sys.stdin except ValueError: return 0 if not overnight : return 0 text = payload.get "last assistant message" or transcript message payload.get "transcript path" counter = Path tempfile.gettempdir / "overnight-stop-guard" / str payload.get "session id", "unknown" if not asks question text : counter.unlink missing ok=True return 0 try: count = int counter.read text + 1 except OSError, ValueError : count = 1 if count MAX BLOCKS: counter.unlink missing ok=True return 0 counter.parent.mkdir parents=True, exist ok=True counter.write text str count print MESSAGE, file=sys.stderr return 2 ​ ​ if name == " main ": sys.exit main Skill: --- name: overnight-mode description: Run unattended work while the human is away; toggles the overnight marker that makes the Stop hook block final questions. Use when asked for overnight, unattended or night-shift work, or at the morning handoff. --- ​ Overnight mode ​ The Stop hook Tools/hooks/guard overnight questions.py blocks any final message that asks a question while ~/.agents/OVERNIGHT exists. This skill owns turning that marker on and off and working inside it. ​ Start ​ 1. Confirm the request is for unattended work. Never turn it on for interactive sessions. 2. Run mkdir -p ~/.agents && touch ~/.agents/OVERNIGHT . 3. Say in one line what you will work on and what you will leave alone. ​ While working ​ - Do not ask questions. Pick the option that is reversible and needs no human, start it, and keep going. - Keep a morning list in your report: every debatable call, what you chose, and how to undo it. - Never do irreversible or external actions push to shared branches, delete data, send messages, spend money unless the request explicitly authorized that exact action. - Stop only when every remaining item truly needs a human. End with a plain NEEDS INPUT: statement listing those items, with no question mark. ​ Morning handoff ​ 1. Run rm -f ~/.agents/OVERNIGHT . 2. Report: what was done and verified, what was not, the morning list, and the NEEDS INPUT items. ​ If the hook blocks you ​ It allows two blocks per session, then lets the stop through. Treat a block as a signal to rewrite the ending as a decision or a NEEDS INPUT statement, not to reword the question Test payloads run with the OVERNIGHT file present; use a fresh session id each time : - {"session id": "t1", "last assistant message": "Done. Should I push?"} → exit 2, message on stderr - the same payload a 2nd time → exit 2; a 3rd time → exit 0 limit reached - {"session id": "t2", "last assistant message": "Done. NEEDS INPUT: approve the release."} → exit 0 - the first payload with ~/.agents/OVERNIGHT removed → exit 0