The Claude Code While Loop That Runs Passive Income on Autopilot
You wrap a repeatable task as a Claude Code skill, run it headless with the claude -p flag, and place that inside a while-true loop that sleeps between runs, creating an autonomous job that has earned roughly 100 to 200 dollars a week.

I am Madhuranjan Kumar, and the thing I want to argue in this article is going to sound boring, which is exactly why it keeps being underestimated. The most effective AI automation setup for most small-scale income-generating or business-automating tasks is a while loop, a terminal, and a well-defined skill file. Not an orchestration framework with a visual interface and a subscription. Not a multi-agent system with specialized roles and a coordinator. Not a no-code automation platform with a webhook builder and a library of integrations. A while loop and a terminal. Simple enough to debug in five minutes when something goes wrong, reliable enough to leave running overnight without babysitting.
The Orchestration Frameworks Are Solving a Problem You Do Not Have
The AI automation tool market has developed a consensus that automation requires infrastructure: workflow builders, agent frameworks, specialized runtimes, and increasingly complex coordination layers that manage how multiple AI calls relate to each other. Some of that infrastructure is genuinely valuable for complex problems, the kind where several AI models need to collaborate, where outputs from one agent feed structured inputs to another, and where the coordination logic is genuinely complicated.
Most small-scale automation tasks are not complex in that way. Most of them look like this: watch for something, decide whether to act on it, act on it if yes, wait, repeat. That is a while loop. It does not need a coordinator. It does not need a visual workflow builder. It does not need a subscription to an automation platform that charges per-task or per-execution. It needs a loop that runs a defined task and sleeps between runs, and it needs a well-structured skill that defines what the task actually is.
The cost of adopting an orchestration framework for this kind of task is not just the subscription fee, though that matters. The deeper cost is complexity. Every additional layer of infrastructure between your intent and the execution adds a surface where things can go wrong in ways that are hard to diagnose. When a while loop fails, it fails in a terminal you are already looking at and the error is usually immediate and readable. When a cloud orchestration framework fails, the error might be in a dashboard you have to navigate to, logged in a format you have to interpret, triggered by an interaction between components that are each working correctly in isolation. Simplicity is a feature of this setup, not a compromise.

Headless Execution Changes What Claude Is Fundamentally
The piece of the setup that makes everything else possible is the claude -p flag. Most people who use Claude interact with it through a chat interface: open a window, type a message, read the response. That interaction model is valuable for a lot of tasks. It is fundamentally interactive, meaning it requires a human to be present at the keyboard to receive each response and decide what to ask next. Interactive tools cannot run autonomously.
The claude -p flag runs Claude Code headlessly, directly from the terminal, without a chat window. You pass it a prompt or a skill command, it runs, it produces output, and it exits. That is a scriptable, automatable unit of execution. Drop it into a shell script inside a while loop and you have a process that runs that unit of execution on a schedule, indefinitely, without any human in the loop. Claude stops being a conversation partner and becomes a scheduled worker. That is a fundamentally different category of tool.
The practical significance of this is large. Tasks that used to require either a human sitting at a desk or a complex cloud automation setup can now run on a laptop overnight at essentially zero marginal cost beyond the API usage. The barrier to deploying an always-on autonomous agent dropped from requiring a developer and a cloud budget to requiring an afternoon and a terminal. For the kind of task that runs once an hour, or once a day, or even every minute, the compute cost is small and the infrastructure is trivial. What is not trivial is understanding clearly what the task is and encoding it in a way that Claude can execute reliably without human guidance on every run.
This method runs through the official claude -p flag rather than third-party wrappers or workarounds, which means it sits cleanly within the terms of service. As platform rules tighten around automated use, building on official supported patterns is the only approach that remains viable long term. The difference between a sustainable automation and a fragile one is often exactly this distinction, and it matters more as the tools mature and the rules around their use become more clearly defined.

A Repeatable Task Beats a Grand Vision Every Time
The single most common reason autonomous AI setups fail in practice is that the task is not well enough defined. A grand vision of what the automation should eventually accomplish is not a task. It is a goal. A task is: check this specific URL for new entries since the last run, compare against the list of entries already seen, identify any that meet these specific criteria, and if any qualify, write a concise summary in this specific format and save it to this specific file. That is executable. The grand vision is not.
The skill file is where that specificity lives. A skill in Claude Code is a structured markdown file with a name, a trigger, and a numbered list of ordered steps. Each step is explicit and specific. The steps define the task as a checklist that Claude executes in a fixed order every time the skill is triggered, without interpretation or improvisation. Rigidity is the point. An autonomous task that interprets loosely and improvises is an autonomous task that produces inconsistent results, and inconsistent results from an unattended process are worse than no results because you cannot trust what came back.
The prediction market bug bounty example demonstrates what a well-defined task looks like in practice. The skill does not say find interesting bugs. It says check the active bug bounty program for new qualifying bugs since the last check, compare against the list of bugs already reported, identify any that meet the specific criteria defined in the criteria section, and if any qualify, draft a concise report in the required format and save it to the output file. That specificity is what makes the skill executable autonomously. The result of running that skill on a reliable schedule has been roughly 100 to 200 dollars a week in bug bounty income on and off. That is not a large number in isolation but it is significant as a proof of concept for the pattern: a well-defined task running headlessly in a while loop generates real economic value on a schedule, without requiring human attention on each cycle, at essentially zero infrastructure cost beyond the API usage.
Three Moving Parts Is the Right Number
The complete setup has three components, and keeping it to three is deliberate. A Claude Code skill that defines the task. A data watcher that monitors for new input and logs it to a file. A while loop that runs the skill on a schedule, reading from the watcher's output file to determine whether there is fresh data to act on.
The watcher and the skill are deliberately separate. The watcher is a simple poller that runs on its own schedule and writes new items to a JSON file. The skill reads that JSON file and acts only when new items are present. This separation matters for two reasons. First, efficiency: the skill only runs real AI processing when there is actual new data to process, rather than burning API credits on cycles where nothing has changed. Second, debuggability: when something goes wrong, the separation makes it immediately clear whether the problem is in the data collection or in the processing logic, because each component is independently testable.
The while loop is the simplest part of the whole setup. A while true loop calls claude -p with the skill command, then sleeps for the interval appropriate to the task. For a task that needs to run every minute, sleep 60. For a task that runs once an hour, sleep 3600. For a task that runs once a day, sleep 86400. The loop runs until you stop it, which you do by terminating the terminal process. Nothing more complicated than that is required to create a task that runs on a reliable schedule indefinitely.
The total number of files involved is small. The skill file. The watcher script. The shell script with the while loop. The JSON file where the watcher logs new data. A settings.json file that pre-approves the specific bash commands the skill needs to run. Five files, all of them readable and debuggable by anyone who can open a terminal. That transparency is a feature. When something breaks, and something always eventually breaks, you can diagnose the problem in a few minutes rather than navigating a platform dashboard or reading framework logs.
Pre-Approving Bash Commands Is Not a Detail: It Is the Detail
The configuration step that most people miss on their first attempt is pre-approving the bash commands the skill needs in settings.json. When Claude Code runs headlessly through the claude -p flag, it cannot interactively prompt for permission to run a command. If it encounters a command it has not been told it can run, it stops and waits for approval that is never going to come from an unattended terminal session. The loop stalls. No obvious error message appears. The automation simply stops working until you figure out why nothing is happening.
The fix is simple once you know about it: before running the loop unattended, identify every bash command the skill will need to execute, add each one explicitly to the settings.json allowlist, and run the skill manually once in the foreground to confirm every command clears without prompting. Only after a full manual run completes without any permission prompts is the skill ready to run headlessly in an unattended loop.
This step is worth spending time on carefully because the failure mode is silent. A stalled loop does not announce itself. It simply stops producing output and you might not notice for hours or days if you are not monitoring it. The practice of verifying permissions with a manual foreground run before switching to headless unattended operation is the single most reliable way to prevent the most common failure mode in this entire setup.
A circuit breaker in the loop itself handles the less predictable failures. If the data source goes down, if an API returns an unexpected error, or if the output of one step fails in a way the skill does not expect, the default behavior of an unguarded loop is to fail on every cycle, burning API credits on errors and potentially repeating a bad action many times before you notice. A simple counter that exits the loop after a defined number of consecutive failures is enough to prevent this, and it takes five minutes to add. Build it in from the start rather than adding it after the first bad overnight run.
The $100-to-$200-a-Week Loop and What It Actually Proves
The bug bounty income example is not remarkable because of the dollar amount. One hundred to two hundred dollars a week is a side income, not a business. What it proves is more important than the revenue number: that a while loop running a well-defined skill on a laptop can generate real economic value on a schedule, without requiring human attention on each cycle, at essentially zero infrastructure cost beyond the API usage.
For a med spa, the equivalent is a watcher that polls the booking system for new leads, treatment completions, and same-day cancellations. The skill that runs when new items appear drafts a warm initial response for new leads with available consultation slots, queues a personalized rebooking nudge for clients whose treatment just completed at the time when the treatment effect typically begins to fade, and drafts a same-day offer to the waitlist when a cancellation opens a slot. A staff member reviews anything client-facing before it goes out, because the trust relationship is personal and the review step costs one minute per item.
The loop runs on a laptop in the back office. The bash commands are pre-approved in settings.json so no cycle stalls waiting for a permission prompt. The watcher logs only real events, so the skill does not burn API credits re-running on an empty schedule. The follow-up messages that used to slip through the cracks because the front desk was busy now get drafted automatically and reviewed in batch when a staff member has thirty seconds. The recovered bookings from consistent follow-up add up across a week into revenue that never shows up on a missed-opportunity report because it never went missing.
That is the argument for simplicity. Not that it is elegant, though it is. Not that it is cheap, though it is. The argument is that it works, it is debuggable when it does not, it runs on infrastructure you already have, and it does not require you to commit to a platform that may change its pricing, its API, or its terms of service on a timeline that is not yours to control. A while loop and a terminal are yours. The pattern scales with the quality of the skill, and the quality of the skill improves through iteration with no platform permission required. Build the skill well, define the task precisely, pre-approve the commands, and let it run. The value accumulates while you focus on everything else.
That is exactly what we do at AI DOERS. Book a private 30-minute call with Madhuranjan Kumar and we will map the fastest path to it for your specific business.
Book your call →
