Claude Code automation: five ways to run it unattended, and what to check first

Last updated: November 13, 2026
TL;DR
Claude Code runs without you in five ways: a script with claude -p, /goal or /loop inside an open session, a scheduled task in the cloud or on your desktop, and GitHub Actions on a repository event. Pick by what has to start each run and whether your machine has to stay on, then answer Anthropic's five questions before you walk away: what done looks like, how the run checks itself, what it may touch, what stops it, and who signs off.
- ๐งพ A script.
claude -pruns once and exits, which is how Claude Code gets into CI jobs, git hooks and shell loops. - ๐ฏ
/goal. Keeps one session working until a condition you set holds, judged by a separate model after every turn. - ๐
/loop. Repeats a prompt on an interval inside an open session, and stops itself after seven days. - โ๏ธ Scheduled tasks. Cloud tasks run with your laptop closed; desktop tasks run on your machine while the app is open.
- ๐ GitHub Actions. Runs Claude Code in a workflow when someone mentions
@claudeor any GitHub event fires.
Five ways to run Claude Code without you
Every method below runs the same agent. What differs is what starts the next run, where it runs, and how long it lasts. This comparison draws on Anthropic's scheduling options table and the pages it links:
| Method | What starts a run | Needs your machine on | Lasts |
|---|---|---|---|
claude -p script | You, cron, a git hook or a CI job | Wherever the script runs | One run, then it exits |
/goal | The previous turn finishing | Yes, with the session open | Until the condition holds or is judged impossible |
/loop | An interval, as short as one minute | Yes, with the session open | Seven days, then it deletes itself |
| Desktop scheduled task | A schedule | Yes, with the app open and the computer awake | Until you delete it |
| Cloud scheduled task | A schedule, an API call or a GitHub event | No | Until you delete it |
| GitHub Actions | A mention of @claude or any GitHub event | No | As long as the workflow file exists |
The split that matters most is the first column. Inside a session, Claude can keep going on its own. What it can't do, in Anthropic's words, is "decide to start, so something has to: you, a timer, or an event like a failed CI check or a new PR" (best practices).
Before any run: Anthropic's five questions
Anthropic's best practices guide has a section called "Let Claude run without you", and it opens with a list worth copying into every task you hand off. Before you leave a task running, answer these for that specific task:
- Does it know what done looks like? A goal condition, a spec file, or a failing test it has to turn green.
- Can it check its own work? The test suite, a
Stophook, or a review step. - What is it allowed to touch? Permission rules,
dontAskmode, the sandbox, a worktree, the one branch it may push to. - What stops it? A cap on turns or on spend, set with the CLI's max-turns and max-budget flags, or a spend limit.
- Where does the result go, and who signs off? A pull request, a comment or a summary, then a person approving the merge, the deploy, or anything else you can't take back.
The reason is simple. While you watch, a missing piece of context costs a message or two. Anthropic's example of the unattended version: in a run started before bed, "nobody tells it, and you find out the next morning that it spent the whole night building on the wrong assumption."
Run Claude Code from a script
claude -p "prompt" runs once and exits. In a script, Anthropic recommends a few more flags:
- The bare flag skips hooks, skills, plugins, MCP servers and
CLAUDE.mdfiles, so the run behaves the same wherever it runs. Anthropic's headless docs call it "the recommended mode for scripted and SDK calls" and say it will become the default for-p. - The allowed-tools flag pre-approves the tools the job needs, and the
dontAskpermission mode refuses anything else that would have prompted. - The max-turns and max-budget flags cap how far one run can go, in turns and in US dollars.
- JSON output format returns one result object to parse.
Anthropic's CLI reference lists the exact spelling of each flag.
Leaving out the bare flag has a cost beyond speed. Without it, a -p session runs the hooks in a project's .claude/settings.json and connects the servers in its .mcp.json, "even in a folder you've never trusted," with no trust dialog. For a script that runs over many repositories, that is a reason to pass in only what the run needs.
Anthropic's own example loops over a list of files, migrating each one and committing, with Claude replying OK or FAIL and a 20-turn cap per file. Its advice is to run three files first, see what goes wrong, fix the prompt, then run the rest.
Keep a session going: /goal and /loop
Both commands keep the current session working between prompts. They differ in what starts the next turn.
/goal runs until a condition holds. You type /goal followed by the condition, such as "all tests in test/auth pass and the lint step is clean", and Claude starts working at once. After each turn, a separate model checks the condition and starts another turn if it isn't met. The goal clears when the condition holds, when the evaluator judges it impossible, or when a turn fails on an error you have to fix (goal docs). Two details decide whether it works:
- The evaluator only reads the conversation. It "doesn't run commands or read files independently," so write a condition Claude's own output can prove, like a test result or a build exit code.
- A goal doesn't change your permission mode. For goal turns to run unattended, set the goal in auto mode. In Manual mode, Claude still stops to ask before tool calls your settings don't allow.
/loop runs on an interval. /loop 15m check CI on this branch, and if it's red pull the failing job's log, fix it and push is Anthropic's example. Each run is another turn in the same session, so it suits short polling jobs, not a long conversation. Recurring tasks "automatically expire 7 days after creation," which bounds how long a forgotten loop can run (scheduled tasks docs).
Run on a schedule: cloud and desktop tasks
For anything that should run with no session open, Claude Code has two kinds of scheduled task.
Cloud scheduled tasks, formerly called routines, run on Anthropic-managed infrastructure "so they keep working when your laptop is closed" (cloud scheduled tasks). A task is a saved prompt, one or more repositories and its connectors, with a schedule, API or GitHub trigger. What to know before you rely on one:
- It is a research preview, and Anthropic says behavior, limits and the API may change.
- It needs a claude.ai login on a Pro, Max, Ultra, Team or Enterprise plan. You create one at claude.ai/code/routines or with
/schedulein the CLI. - It starts from a fresh clone each run, with no access to your local files, and pushes to
claude/-prefixed branches. - It belongs to you. Tasks aren't shared with teammates, runs count against your account's limits, and anything a task does through your GitHub identity appears as you.
- It runs in auto mode by default, and the shortest schedule is one hour.
Desktop scheduled tasks run on your machine with your files and tools, but a local task "only fires while the app is open and your computer is awake" (desktop scheduled tasks). Use them for work that needs something only your machine has.
Choosing between the two, and /loop, gets its own walkthrough in our guide to Claude scheduled tasks.
Run on GitHub events: GitHub Actions
The Claude Code GitHub Action runs Claude Code inside your repository's workflows. Mention @claude in a pull request or issue comment and it can analyze code, make changes and push commits, or you can give it a prompt to run on any GitHub event. The quickest setup is /install-github-app from Claude Code, which installs the GitHub App, adds the secret and opens the workflow pull request. It works only with github.com repositories.
Actions suits work that belongs to the repository rather than to one person. Anyone with write access to the repository can trigger it from an issue or pull request, which is also the default limit on who can: Anthropic's docs say a user without write access needs to be allowed by name.
Which one should you use?
- One batch job you'll watch start: a
claude -pscript, tried on three items first. - One hard task with a clear finish line:
/goalin auto mode, with a condition a test can prove. - Checking something every few minutes while you work:
/loop. - A nightly or weekly job that shouldn't depend on your laptop: a cloud scheduled task.
- A job that needs your local files or tools on a schedule: a desktop scheduled task.
- Work the whole team should be able to trigger from a pull request or issue: GitHub Actions.
What to set up before the first unattended run
Anthropic's warning for cloud tasks applies to every method on this list: "protect main with a GitHub branch rule the task can't bypass," and "watch the first few runs of anything new before trusting it unattended." In practice that means:
- Protect the branches that matter. The run should push to its own branch and open a pull request, never merge.
- Write the permissions down. Allow what the job needs, deny what it must never do. Our Claude Code permissions guide covers the rule syntax, and the sandbox guide covers when to wall off Bash commands too.
- Give it a check it can't skip. A test suite, or a
Stophook that runs one. Our hooks guide shows how. - Cap the run. Turns, budget, or both.
- Route the result to a person. A pull request, a comment or a summary, with a human approving anything you can't undo.
For a team rolling this out, the rules above belong in shared settings rather than one person's machine. Our Claude Code best practices for a team covers where each one lives.
Frequently asked questions
Can Claude Code run without supervision?
Yes. A claude -p script, /goal, /loop, a scheduled task or GitHub Actions can each run it without you prompting each step. Anthropic's advice is to define what done looks like, give the run a check, limit what it can touch, cap its turns or spend, and have a person approve the result.
How do I run Claude Code on a schedule?
Use /loop for short intervals inside an open session, a desktop scheduled task for jobs that need your machine, or a cloud scheduled task to run with your laptop closed. Cloud tasks are a research preview, need a claude.ai login on a paid plan, and run at most once an hour.
What is Claude Code headless mode?
Headless mode is claude -p, which runs one prompt and exits instead of opening an interactive session. Anthropic recommends the bare flag for scripts, so the run skips local hooks, plugins, MCP servers and CLAUDE.md files, plus pre-approved tools and a turn or budget cap.
What is the difference between /goal and /loop?
A goal starts the next turn when the previous one finishes and stops when a separate model confirms your condition holds. A loop starts the next turn on a time interval and expires after seven days. Use /goal for one task with a finish line and /loop for repeated checks.
Do Claude Code scheduled tasks run when my computer is off?
Cloud scheduled tasks do, because they run on Anthropic-managed infrastructure from a fresh clone of your repository. Desktop scheduled tasks and /loop don't: a desktop task fires only while the app is open and the computer is awake, and /loop needs the session to stay open.
Is it safe to let Claude Code run overnight?
It can be, with limits in place. Protect your main branch with a rule the run can't bypass, restrict tools with permission rules or the sandbox, cap turns or spend, and send the result to a pull request a person approves. Watch the first few runs of anything new.
Write down what every run should know
An unattended run can't ask you what you meant. Everything it needs, from which test command proves the work to which folders are off limits, has to be written where it reads before it starts. Our guide to compound engineering for Claude Code shows how to build those written rules up one fix at a time, so each run starts with what the last one learned. If you run several sessions at once while you watch, our guides to Claude Code /batch and agent view cover that side.
Stop guessing. Score your first workflow.
Score one workflow in about five minutes. Nine questions, a grade, and the specific gap holding it back - no call required.
Related Posts

Claude Code MCP servers on a team: add, share and control them
Claude Code MCP servers are added at one of three scopes, shared through a committed .mcp.json, and controlled for a team with managed settings. How each step works, which control pattern fits, and the details that decide whether an allowlist holds.

Claude Code on Amazon Bedrock: when a team should route through AWS
Route Claude Code through Amazon Bedrock when AWS has to process your prompts and code, or your compliance program needs it. What a team gives up on Bedrock, what it gains, and the AWS-billed middle option, Claude Platform on AWS.

Claude Code permissions: allow, ask and deny rules that hold
Claude Code permission rules run in a fixed order, deny, then ask, then allow, and the first match decides. How to write Bash, file and MCP rules that match what you meant, where a path anchors, and where a rule stops protecting you.