# How to Run Claude Code For Hours Autonomously

Source: https://www.youtube.com/watch?v=o-pMCoVPN_k
Recap page: https://rapidrecap.app/video/o-pMCoVPN_k
Generated: 2025-12-29T14:42:59.331+00:00

---
## Quick Overview

The video demonstrates how to configure Claude Code's agent harness using Ralph Wiggum's plugin and custom hooks to create a fully autonomous workflow that allows Claude to run iterative coding tasks for hours by automatically refeeding test failures and only stopping when a defined completion promise is met or the maximum iteration count is reached.

**Key Points:**
- The video shows how to set up Ralph Wiggum's plugin for Claude Code to enable autonomous, long-running coding tasks using custom hooks.
- Claude Opus 4.5 achieved a benchmark of running autonomously for 4 hours and 59 minutes on specific software engineering tasks.
- The solution involves using Claude Hooks, which are shell commands that fire at specific workflow points (like PreToolUse, PostToolUse, and Stop), similar to Git hooks.
- The critical hook used is the 'Stop' hook, configured to run tests and only exit if tests pass, otherwise it feeds the output back to Claude to continue fixing the code.
- Ralph Wiggum's loop mechanism creates a state file in `.claude/` and repeats the process until a promise is met or max iterations are reached, ensuring determinism.
- The setup allows for complex, multi-step tasks like large refactors or TDD workflows to run unattended, with code staying clean and dangerous operations blocked via the PreToolUse hook.

![Screenshot at 01:03: The slide contrasts the problematic manual loop \(Give task, Claude says done, run tests, paste error back, repeat 3-5 times\) with the fix: running tests automatically after Claude finishes and feeding output back, allowing Claude to keep iterating until the task is complete.](https://ss.rapidrecap.app/screens/o-pMCoVPN_k/00-01-03.jpg)

**Context:** The video details an advanced technique for making Large Language Models (LLMs) like Claude operate more autonomously on complex software engineering tasks, specifically by leveraging the Claude Code plugin system and custom 'hooks'. Hooks are shell commands that execute at defined points in Claude's workflow, allowing for mechanisms like automatic testing and error correction loops, which significantly extends the model's ability to handle long-horizon tasks without manual intervention.

## Detailed Analysis

The presentation begins by showing that newer LLMs like Claude Opus 4.5 can complete long software engineering tasks autonomously for hours, setting a new benchmark. The core of the video explains how to achieve this extended autonomy using Claude Hooks. These hooks are defined as shell commands that fire at specific points in Claude's workflow, analogous to Git hooks. Key hooks discussed are PreToolUse (to block dangerous commands), PostToolUse (for auto-formatting), and Stop (for running tests until they pass). The crucial element for long-running tasks is the Stop hook, which runs tests; if they fail, it feeds the output back to Claude, forcing it to fix the errors and repeat the process, preventing the loop from exiting prematurely. This entire iterative process is managed by Ralph Wiggum's plugin, which creates a state file in `.claude/` to track progress, ensuring that if Claude exits, it can resume exactly where it left off, making the entire workflow deterministic and capable of handling multi-step to-do lists, large refactors, and TDD workflows unattended. The video concludes by showing the configuration file for Ralph's plugin, which stacks these three hooks to create a fully autonomous workflow where code stays clean, dangerous operations are blocked, and tests must pass before stopping.

### LLM Long Task Benchmarks

- Claude Opus 4.5 achieved 4 hours 59 minutes average task completion time
- GPT-4 Turbo is lower on the chart, indicating shorter completion times for similar tasks

### What Are Hooks?

- Shell commands that fire at specific points in Claude's workflow
- Hooks include PreToolUse (block commands), PostToolUse (auto-format), Notification, UserPromptSubmit, Stop (run tests until green), and SubagentStop

### The Problem and The Fix

- The problem is the manual loop of giving tasks, waiting for 'done', running tests, pasting errors, and repeating; the fix is using hooks so Claude keeps going until the task is done autonomously

### How Ralph Loops Works

- 1. Run /ralph-loop 'task'
- 2. Creates state file in .claude/
- 3. Claude works, tries to exit
- 4. Stop hook blocks exit, refeeds prompt
- 5. Repeats until promise or max iterations met
- Best for multi-step to-do lists, large refactors, and long unattended runs

### Stack Multiple Hooks

- Hooks are stackable and usable interchangeably
- PreToolUse blocks dangerous commands, PostToolUse auto-formats, and Stop runs tests until green
- This creates a fully autonomous workflow where code stays clean and tests must pass before stopping

![Screenshot at 00:04: A graph showing the improvement in LLM ability to complete long software engineering tasks over time, with Claude Opus 4.5 achieving the highest task duration completion.](https://ss.rapidrecap.app/screens/o-pMCoVPN_k/00-00-04.jpg)
![Screenshot at 01:03: A slide titled 'The Problem' contrasting the known manual loop \(steps 1-6 on the left\) with the automated fix on the right, where Claude keeps iterating until completion.](https://ss.rapidrecap.app/screens/o-pMCoVPN_k/00-01-03.jpg)
![Screenshot at 02:41: A slide titled 'What Are Hooks?' defining them as shell commands firing at specific points in Claude's workflow, listing hooks like PreToolUse, PostToolUse, and Stop.](https://ss.rapidrecap.app/screens/o-pMCoVPN_k/00-02-41.jpg)
![Screenshot at 03:54: A slide titled 'The Power of Stop Hooks' illustrating the 5-step process of how a Stop hook forces iteration by running tests and refeeding output if failures occur.](https://ss.rapidrecap.app/screens/o-pMCoVPN_k/00-03-54.jpg)
![Screenshot at 06:43: A slide titled 'How Ralph Loops' detailing the 5-step process initiated by running /ralph-loop 'task', which creates a state file and repeats until a promise or max iterations are met.](https://ss.rapidrecap.app/screens/o-pMCoVPN_k/00-06-43.jpg)
