A Claude Code loop is a prompt that runs again and again, either inside a session (/loop repeats it on a timer and /goal repeats it until a condition holds) or outside it, in a shell script that restarts the agent on every pass.
Five ways to loop Claude Code
| Approach | Next run starts when | Stops when | Best for |
|---|---|---|---|
| /loop | A time interval passes | You cancel it or it expires after seven days. A self-paced loop can also end when Claude decides it is done | Polling a deploy or checking a build during a session |
| /goal | The previous turn finishes | A model confirms the condition is met or judges it impossible | Work with a verifiable end state, such as tests passing |
| Stop hook | The previous turn finishes | Your own script or prompt decides | Deterministic checks that apply to every session in a settings scope |
| Cloud scheduled task | A schedule, an API call or a GitHub event | You pause or delete it | Work that must run while your laptop is closed |
| Ralph shell loop | The last agent process exits | Every story in the task list passes, or the script hits its iteration cap | Long builds where each pass should start with a fresh context |
The first four rows come from the Claude Code docs, read on November 10, 2026. The last row is from my January 23, 2026 post on Ralph.

What makes it a loop
These five are mechanisms for repeating work. In my paid loops guide I treat a loop as the whole system, with a scheduled task as the trigger and /goal as one way to define done inside it. In my episode with Tyler Folkman, the Chief AI Officer at JobNimbus, I asked what makes something a loop. His answer was that looping assumes you learn: any good loop ends with a step where the AI reviews what it did and how to improve it. He also said that in the middle of a loop there is usually a gate, a check that the work was correct, and that this is almost always the most important part. The full conversation is on my site.
I use that as a test. A skill does the work once. A loop fetches its own inputs, does the work, passes a gate and learns from the run.
/loop: repeat on a timer
The /loop command re-runs a prompt on an interval inside an open session. The docs’ example is /loop 5m check if the deployment finished and tell me what happened. If you give a prompt and no interval, Claude chooses the interval each time. The docs list its limits plainly: tasks are session-scoped, so they need an open session, and for scheduling that survives without one the docs point you to cloud scheduled tasks, which run with your laptop closed.
Use /loop for quick polling during a session. It is a poor fit for anything you need to run reliably overnight.
/goal: repeat until a condition holds
The /goal command sets a completion condition, and Claude keeps working toward it without you prompting each step. After each turn, a separate model checks whether the condition holds. If not, Claude starts another turn. The docs recommend a goal for substantial work with a verifiable end state, and only one goal can be active per session.
The docs warn that the evaluator does not run commands or read files itself, so a condition has to be something Claude’s own output can show, such as a test result in the transcript. That is why /goal helps with stopping: a fresh model that did none of the work decides when it is complete. I wrote more about it in How PMs should actually use /goal.
Ralph: a loop outside the agent
Ralph is the loop I covered in my January 23, 2026 update. As I described it there, Geoffrey Huntley invented the system, and the technique is a bash loop that runs a coding agent repeatedly until a task is done:
while :; do cat PROMPT.md | claude-code ; done
That one-line version has no stop condition at all. The full script in my free post takes a maximum number of iterations, for example ./ralph.sh 14, and exits early when the agent prints a completion promise. I gave two reasons for running the loop outside the agent. The agent cannot decide it is done, because only prd.json decides that, and each pass starts fresh, because Ralph throws compaction away entirely. Memory lives in git commits and in two files: progress.txt holds the learnings and prd.json records what is done and what is next. The prompt tells the agent to work on only one task per iteration, which keeps each pass small enough to check.
You can read the full script and prompt in the free Ralph post.
What stops a loop from running forever
Set the limit before you walk away. A fixed-interval /loop ends when you ask Claude to cancel it or after seven days, because recurring tasks expire seven days after creation. Esc stops a self-paced loop while it waits for its next iteration. Esc and Ctrl+C do not stop a fixed-interval loop, so you ask Claude to cancel it. For /goal, the docs say to put a turn or time clause in the condition, such as “or stop after 20 turns”. The Ralph script in my free post takes a maximum number of iterations and prints a message when it hits the cap.
A gate you can build first
A loop is only as good as its gate, and a gate is the part you can build before anything repeats. The closest example in my repo is .claude/scripts/verify_quotes.py, which I run on research files. It finds the double-quoted spans of five or more words in a file and checks that each one appears verbatim in the sources the file cites. It exits 1 if any quote is not found or any cited path is missing. Nothing goes into an outline until it exits 0.
That is a deterministic check on one way the work can be wrong, a quote that is not in the source, which is the kind of gate Tyler described. It is not a loop yet, because nothing learns from a failed run and I start it by hand. I keep it that way on purpose: rule 43 in my CLAUDE.md says no scheduled job or recurring trigger without my explicit yes, and to say what it costs per run. A loop that starts itself is a bigger decision than one I start myself.
Loops for PMs
On the show I told Tyler I run a morning planning loop and asked what else PMs should build. He named two: a customer outreach loop that picks customers from your data, such as Pendo or Amplitude, based on a change in usage, and a project management loop that pulls tickets from Linear or Jira and flags what is at risk. I tested a larger set for PMs in my paid loops guide, and the scheduled tasks guide covers the trigger side.
If you are starting from zero, build the gate first. Write down the check that tells you a run was good and make it a script if you can. Add a learning step only after the first runs behave. A loop with no gate runs on its own mistakes.
My pages on hooks and on how I set up Claude Code cover the enforcement side, and the subagents page covers running several agents at once.
Land a PM Job is my 12-week cohort for PMs who want to build systems like these and win offers. The next cohort starts November 23, 2026. It has 2-3 live sessions a week and six 1:1 coaching sessions, and the coaching team reviews your resume, LinkedIn, GitHub and portfolio live on your real materials. I write about loops at www.news.aakashg.com.
Claude Code loop FAQ
What is a Claude Code loop?
It is a prompt that Claude Code runs repeatedly. Inside a session, /loop repeats a prompt on an interval and /goal repeats turns until a completion condition holds. Outside a session, a shell script can restart the agent on every pass, as in the Ralph technique.
What is the difference between /loop and /goal?
/loop starts the next run when a time interval passes. /goal starts the next turn as soon as the previous one finishes, and a model checks after every turn whether your completion condition holds. Use /loop to poll and /goal to finish a job with a clear end state.
How do I stop a Claude Code loop?
A fixed-interval /loop stops when you ask Claude to cancel it, and it expires after seven days either way. A self-paced /loop stops when you press Esc or when Claude decides the work is done. A /goal clears when a model confirms the condition is met or judges it impossible. You can also run /goal clear, or add a clause such as “or stop after 20 turns”. A shell loop needs a maximum iteration count and a task list that says when everything passes.
Does /loop keep running when I close my laptop?
No. /loop is session-scoped and needs an open session on your machine. The docs list cloud scheduled tasks as the option that runs with your laptop closed.
What is Ralph Wiggum in Claude Code?
Ralph is a technique that runs a coding agent in a bash loop until a task is done. Each pass starts with a fresh context, and the agent keeps its memory in git commits and in two files, a progress file and a task list.