[Prompt]
I'd like to run my first agentic loop, and I want to know how it's done properly with Anthropic's own tooling. How do you actually set up a loop in Claude Code (the Ralph loop and the first-party constructs that have come since), and how is usage controlled so it doesn't run away? My example: for my ASR training dataset I record myself reading sentences built around target vocabulary. Isolated sentences got boring, so I've started having a subagent turn a vocabulary set into a short book, story or article, and I'm writing a skill to do that proactively. The next step is a loop: take every vocabulary set that's still only sentences, turn it into a text asset, and keep going until none are left, maybe running in the background over days.

[Response]
Corn: ...and that's what bothers me about the phrase "until it's done." Nobody has ever defined done for a computer and been happy with the result.

Herman: Computers are very literal about it, which is most of the trouble. And it happens to be exactly where Daniel's question lands.

Corn: He wants to run his first agentic loop, and he wants it done the proper way, with Anthropic's own tooling, and with something that stops it eating his whole usage allowance. The setting is his speech recognition training set. He records himself reading sentences built around target vocabulary, and the isolated sentences got boring to read. So a subagent now turns each vocabulary set into a short book or story or article instead, and he's writing a skill so that happens on its own. Next step is the loop: find every set that's still only sentences, make it a text asset, keep going until none are left. Possibly in the background, over days.

Herman: It's a good first loop, and the reason is the ending. Most first loops are "improve the codebase," which has no bottom. His queue has a bottom. You can count it.

Corn: Then count it somewhere before anything runs. "Keep going until none are left" is a sentence I'd like pinned down. Where does the list live?

Herman: Before any command, that's the question. Every loop construct Anthropic ships is just a way of making a session carry on, or start again. What makes a loop finish is the state outside the session. For Daniel that's a manifest file with one entry per vocabulary set, and each entry has a status. Pending, done, failed. Only the loop touches the status field. One set per iteration. Make the asset, check it, flip the flag, commit.

Corn: Why a file? Claude has a memory.

Herman: Claude has a context window, and it fills, or gets restarted, or compacted. Anthropic published guidance on long running agents last November and it's nearly this exact design. A feature list in JSON, every item starting as not passing, and later sessions are only allowed to flip one field. They chose JSON over Markdown because the model is less tempted to rewrite it wholesale.

Corn: A model that rewrites the to-do list. Relatable.

Herman: Geoffrey Huntley, who started the whole Ralph business, did the same thing with a prioritised plan file the agent picks from. One item per pass. And he has this idea he calls backpressure: tests, type checkers, anything that rejects bad work quickly.

Corn: Which for Daniel is what, a spell checker for stories?

Herman: A small script the loop runs before it's allowed to mark a set done. It exits with an error unless the asset exists, is a sensible length, and contains every target word from that vocabulary set. If the loop decides for itself that it's finished, it will be finished a lot.

Corn: A loop grading its own homework.

Herman: And giving itself full marks. So the check is a script, not a feeling. And the commit after each set is the checkpoint. The git log becomes the progress record, and a bad asset is one revert, not an archaeology project.

Corn: What goes in the prompt that each pass gets? Because if I'm the one writing it, my instinct is a paragraph of encouragement.

Herman: Keep it short and boring. Read the manifest. Take the first entry still pending. Run the skill on it. Run the checker. If the checker passes, flip the status and commit. If it fails, add one to the attempts and note why. Then stop, whether or not anything is left. The prompt never says "keep going." Going on is the loop's job, and a prompt that tries to do it as well is how you get one session trying to do the whole queue in a single breath.

Corn: A prompt that ends with "then stop." Optimistic, for a prompt.

Herman: Daniel already has the useful half of the design, the subagent that turns a vocabulary set into a text. The loop only needs to call it, so the skill carries the craft, the story or article, and the loop carries the bookkeeping. If those two get tangled, you can't improve one without breaking the other.

Corn: Tidy. Not sure the order matters, though.

Herman: It might. Corn, you'd have a view on this. Would you rather he got the skill right first, and add the loop after, or build the loop around a rough skill and improve it as he goes?

Corn: Skill first. A loop multiplies whatever you hand it. If the stories are a bit flat, he'll have a very orderly pile of flat stories. I'd run the skill by hand on three sets, read them, then let the loop loose.

Herman: That's my instinct too, and it's cheaper. You're paying for every wrong turn the loop makes at machine speed.

Corn: We've done the philosophy of this already, the Ralph Wiggum episode on feeding a model the same prompt until it works, and the one on loops versus workflows. So skip that. Which constructs does Anthropic actually give him?

Herman: Three, and I'd sort them by what ends them. Ralph ends on a phrase or an iteration cap. The slash loop command ends on a clock. And there's a built in command called slash goal that ends when a judge model says so. Take Ralph first, because it's the famous one. Huntley's original was a bash while loop feeding the same prompt file to Claude forever, fresh context every time. The official version is a plugin, and it's listed in the marketplace as ralph-loop, not under the old Wiggum name.

Corn: Daniel might go looking for the wrong name.

Herman: He might. Install it, and you run slash ralph-loop with your prompt, a max iterations flag, and a completion promise, which is a word the model has to say when it's finished. Under the hood a Stop hook catches the session trying to exit and hands the prompt back. Same session each time, with files and git carrying the progress.

Corn: So the model has to type the password itself.

Herman: Yes, and that's the weak spot for Daniel's case. His manifest already knows whether work remains. Why also ask the model to announce it? The max iterations flag is the useful part. As I understand it the default is no limit, so you set it every time, and it's a counter in the hook, not an opinion.

Corn: And people say the plugin misses the point?

Herman: Huntley does, and others. The bash loop throws the context away each pass, so nothing survives except files. The plugin keeps one long session going. For a queue like his, fresh context per item is arguably better, since the fortieth set has no use for the memory of the first.

Corn: Then why bother with the plugin at all?

Herman: Convenience. You stay inside the session and watch it. But here's the one I'd give airtime to, because Anthropic basically wrote Daniel's prompt into the documentation. Slash goal. You type a completion condition, up to four thousand characters, and after every turn a small fast model, Haiku by default, reads the conversation and decides: met, not yet, or impossible. Under the hood it's a session scoped Stop hook again, and when the condition is met the goal clears. The docs' own example is working through a labelled issue backlog until the queue is empty.

Corn: Until the queue is empty. They've been reading his mail.

Herman: Now the part that matters for usage. You can put a bound inside the condition, something like "or stop after twenty turns." But that's judged by the evaluator from the conversation. It's not a counter.

Corn: A speed limit enforced by someone's opinion of how fast you were going.

Herman: Fair, though there are real stops around it. The status shows turns evaluated and tokens spent. The loop halts if Claude makes no tool calls for several turns in a row. It clears on an authentication failure, an exhausted credit balance, a context overflow or an unavailable model. And on a rate or usage limit it pauses and picks up again when the limit resets, in an interactive session. The evaluator's tokens are billed on top of the work.

Corn: So I want the condition to be checkable. If the judge only reads the conversation, "all vocabulary sets have assets" is a claim, not a fact.

Herman: My guess is you write it as "the last command run printed zero pending entries in the manifest." Make Claude run the counting script in the final turn so the judge has a number to read. The judge only sees what's been said in the conversation, which matters because it can't open the manifest itself...

Hilbert: Hilbert's Lost Property. A beekeeper's hat, bees not included, found in the third floor stairwell, and I have hung it on the coat rack by the fire exit. A brass telescope with no lenses, found behind the vending machine, and I have labelled it as a spare and filed it under stationery. A wedding cake, still in the box, found in the lift, and I have begun eating it.

Hilbert: Owners may collect from reception, provided they bring a stamped envelope and a note from their mother.

Corn: A note from your mother. That's a high bar for a lost telescope.

Herman: The judge can't open the file, so the number goes in the conversation. And that's the supervised answer for Daniel, if he's sitting at the machine. One slash goal, with the empty queue stated as a printed zero, a turn clause as a soft limit, and he watches the status line. Ctrl+C stops it. Run it in a git worktree, so whatever it does happens on an isolated copy and not his main checkout.

Corn: Worktree, fine. What does one pass actually cost? That's the number I'd want before any limit.

Herman: Run one set and look, and remember the subagent spending counts too. Anything the subagent costs counts toward the totals. If the skill hands each set to a subagent with a long brief, the loop's tab is the sum of both.

Corn: So the first number you want isn't a limit, it's a price per set.

Herman: Yes. Multiply it by the queue, and you know what the whole job costs before it starts. Then the limits are there for the day something goes wrong, not as your plan.

Corn: I'd also want permissions sorted before I walked off. A loop that stops at every approval prompt isn't a loop.

Herman: It's a real decision. You can pre-approve the specific commands it needs, like the git commit rule, or use accept edits mode, or in a locked down run the don't ask mode, which denies anything you didn't allow in advance. There's a flag from a recent version that denies instead of waiting. The all-powerful skip permissions option exists, and for a job that writes text files and commits them I'd call it overkill.

Corn: Overkill and a bit alarming. What's the slash loop command doing in all this? It sounds like the one you'd reach for.

Herman: That's the trap. It's the one with the best name for Daniel's request and the wrong shape. Slash loop is a clock. You give it a fixed interval, like every five minutes, and it converts that into a cron job inside the session. Or you give it a prompt with no interval and Claude picks its own delay each time, between one minute and one hour. Or bare slash loop runs a maintenance prompt, or whatever you put in a loop dot md file.

Corn: So it's for waiting on things.

Herman: Polling a deploy, checking a pull request, nudging a stuck build. It's lovely for that. For a queue you want to drain as fast as the work allows, a timer is the wrong tool: it'll wake up, do one set, and sleep for ten minutes with forty sets to go.

Corn: Unless the interval is one minute.

Herman: Then you've built a slower slash goal that expires. It's session scoped, so it needs Claude Code running and idle. Close the terminal and it stops. Self paced loops aren't even restored when you resume a session. Recurring tasks expire thirty days after creation, with a cap of fifty tasks per session.

Corn: Thirty days. The loop outlasts the project.

Herman: And stopping it is odd. For a self paced loop you press Escape on an empty prompt. For a fixed interval one, Escape and Ctrl+C don't work. You have to ask Claude to cancel it.

Corn: You stop it by asking it nicely. Very reassuring.

Herman: There's an environment variable that turns the whole scheduler off, if you're nervous. And a detail that I find lovely, because cron here has jitter. A recurring task can fire late by up to half its interval, capped at thirty minutes, so every five minutes ends up as roughly four minutes forty between runs. Missed fires aren't caught up, either.

Hilbert: Four forty-five. Not forty.

Herman: Forty-five, thank you.

Hilbert: Eighty-three pounds. That is what a loop cost the darts team in March. I pointed it at the league tables, Brendan said it would sort the fixture list, and I went to bed. I did not ask it anything, I closed the lid. Herman, you said nothing survives a fresh pass except the files. The league tables are in a file now. They were in the prompt. Just now I put the budget flag on the machine under the shoe rack in the hall, plugged into the router. Two dollars. It got as far as the Wednesday fixtures and stopped at two dollars and eleven cents, mid-sentence.

Corn: Why the shoe rack?

Hilbert: Draught.

Herman: Eleven cents over. That's the number I'd keep from that. The max budget flag is checked on the client side against an estimate, so it stops when it notices, not when it hits the line. Subagent spend counts toward it, but the stop still overshoots, so you leave headroom.

Corn: Two dollars was never the real limit, then. Two dollars was a suggestion with a margin.

Herman: A reasonable margin, in his case. Which is why, for the background version of Daniel's job, I'd move to the headless mode: claude with the print flag. Two flags matter there and only there. The max turns flag, which limits agentic turns, and the max budget flag, which stops when estimated spend reaches your amount. Neither applies in an interactive session, and print mode has no default turn limit at all, so if you don't set one, you haven't got one.

Corn: And "background over days" means what in practice? Because he said background, not leave the laptop open.

Herman: Three routes. The first is cloud scheduled tasks, slash schedule, which used to be called routines and is still a research preview. The prompt and the repo run on Anthropic's infrastructure with his laptop shut. Each run starts from a fresh clone of the repository and pushes to a branch with a claude slash prefix by default. The shortest interval is one hour, anything more frequent is rejected, and the runs draw down his subscription usage like any other session. At the limit they're rejected unless overage credits are switched on.

Corn: A fresh clone every time means the manifest has to be in the repo.

Herman: And committed, yes. Which his design already does. If the manifest lives on a disk nobody pushed, the cloud run wakes up and finds an empty queue and politely does nothing. It suits polling less than a queue, but one batch an hour is still a pace.

Corn: So a long queue takes a while.

Herman: Depends how many sets it does per run. The second route is the desktop scheduled task, which needs the machine on but reads local files. The third is the roll your own one: a cron entry on a box he controls, running a small script that calls claude with the print flag once per vocabulary set. Each call gets a fresh context, its own turn limit, its own budget limit. The script reads the exit code, checks the manifest, and stops when the pending count hits zero.

Corn: That's Huntley's bash loop with a leash.

Herman: With a leash on every iteration, and that's the thing I like. Using the JSON output format, each call returns a total cost figure, so the script can keep a running total of its own and quit at a ceiling. Those are estimates, not billing. But a budget per call plus a budget for the night is two layers.

Corn: One catch I'd flag. He lives in subscription land, I assume. Does an unattended loop spend from the same pool?

Herman: The same five hour and weekly allowance as his daytime work, as far as I know. I don't have the current limit numbers I'd trust, so I'll leave them out. The billing story for headless use has moved around. Anthropic planned to split print mode and the SDK onto a separate credit in June, then paused it, and signing in with the plan still means subscription limits. Using a Console API key is a different path, with monthly API credits on some plans. One warning about the cleanest looking option, the bare flag, which skips hooks, skills, plugins and the project memory file, and needs an API key.

Corn: So no Ralph and no slash goal in bare mode.

Herman: Neither one runs, because both are hooks. That's fine for the per item bash loop, where every call is a fresh, tightly scoped job. It would be a surprise for anyone expecting to keep their skill, since the skill Daniel's writing wouldn't load either.

Corn: The skill that turns a vocabulary set into a story. That's the thing the loop is for.

Herman: So not bare. Leave the skills loaded, and pre-approve the narrow tools.

Corn: Cutting room floor, then. Something that didn't fit.

Herman: The Register covered the Ralph technique in January, with a figure about cloning software for roughly ten dollars an hour. A loop with no cap is a meter running.

Corn: Daniel's job is text generation per set. That's cheap per iteration. The risk is a set that keeps failing the check and gets retried all night.

Herman: Then the manifest wants an attempts field. Three failures and the set is marked failed and skipped. It turns a stuck loop into a finished loop with a short list of problems.

Corn: So for Daniel at the machine: slash goal, the empty queue stated as a printed zero, a turn clause, a worktree, pre-approved tools. Walking away for days: a cron driven script on his own box, one set per call, a turn limit and a budget on every call, a running total with a ceiling, the manifest in git, skills left loaded.

Herman: The thing I'd carry into it is the margin. A budget flag is a suggestion with eleven cents of play in it, so set it below what you'd actually mind losing. And run the first handful of sets supervised, with your eyes on the checker.

Corn: Thanks to Hilbert Flumingtop for producing this one. This has been My Weird Prompts.

Herman: Find us at my weird prompts dot com. We'll be back soon.