claude code

How to run Claude Code on a schedule

To run Claude Code on a schedule, start it in headless mode (claude -p) from something that keeps time: cron, a CI schedule or Anthropic's own scheduled tasks. Give the run a credential that works with nobody signed in, the tools it may use, and a limit on turns and spend. Then decide where its state lives, where a person signs off and where the record is kept. In ConvOps, a schedule creates the task and an executor runs it through the same workflow your team uses attended.

the route

6 sections · 9 min

  1. The options
  2. From cron or CI
  3. What breaks
  4. In ConvOps
  5. Subscription or API key
  6. When cron is enough
01The options

What are the options for running Claude Code on a schedule?

Five shapes, as of November 2026. They differ in where the run lives, what has to stay switched on, and whether a person can sign off part way through.

The /loop command inside a session is the lightest one, and Anthropic's docs are clear about its reach: tasks fire only while Claude Code is running and idle, closing the terminal stops them, and a recurring task expires after seven days. For work that must happen with nobody at a keyboard, the same docs point to cloud scheduled tasks, a GitHub Actions schedule trigger or Desktop scheduled tasks.

Ways to run Claude Code on a schedule.
OptionWhere it runsWhat must stay onSign-off mid-run
/loop in a sessionYour open sessionThe machine and the sessionIn the live session only
cron or a timer with claude -pA machine or server you keepThat machineNo. A call that needs approval is denied
CI schedule (GitHub Actions)Your CI runnersNothing of yoursOnly between jobs
Claude Code cloud scheduled tasks, formerly Routines (research preview)Anthropic cloud or a self-hosted environmentNothing of yours. Smallest interval is one hourNot as a step. The session starts in auto mode where available and asks on an ask rule or after repeated blocks
ConvOps scheduleConvOps Cloud or your own runnersNothing of yours on ConvOps CloudYes. A gate holds the step until an explicit approval is given

sourcesClaude Code docs: run prompts on a scheduleClaude Code docs: scheduled tasks in the cloud (formerly Routines)Claude Code docs: GitHub ActionsClaude Code docs: headless mode

Your sessionmachine and session on
cron or CIa server or runners
A schedule with gateswaits for people
fig 1 Where the run lives decides what must stay on.
02From cron or CI

How do I run Claude Code from cron or CI?

Write the job once as a script, then let cron or a CI schedule start it. Claude Code in headless mode prints its result and exits 0 on success and non-zero on failure, so any scheduler can tell whether the run worked.

The example is a weekly digest of support tickets kept as files in a repository. The same shape fits a Monday pipeline report for sales, a month-end checklist for finance or a stale-page check for a content team.

  1. 1

    Write a prompt that stands alone

    Nobody is there to answer a question, so the prompt names the input, the output and what done looks like. Keep it in a file under version control.

  2. 2

    Give the run a credential

    Use an Anthropic API key in ANTHROPIC_API_KEY, or run claude setup-token once and store the long-lived token it prints as CLAUDE_CODE_OAUTH_TOKEN. Keep either one in a secret store, not in the script or the image.

  3. 3

    Write the run script

    Allow tools by name, deny everything else, and cap turns and spend. The numbers are placeholders to size from your own attended runs.

    #!/usr/bin/env bash
    # weekly-digest.sh: one scheduled Claude Code run
    set -euo pipefail
    cd /srv/support-digest
    
    # The credential comes from your secret store, never from the script.
    claude -p "$(cat prompts/weekly-digest.md)" \
      --allowedTools "Read,Grep,Glob,Write" \
      --permission-mode dontAsk \
      --max-turns 40 \
      --max-budget-usd 5 \
      --output-format json > "runs/$(date +%F).json"
  4. 4

    Schedule it with cron

    This line runs every Monday at 07:00 in the server's time zone. flock stops a slow run from overlapping the next one.

    # m h dom mon dow  command
    0 7 * * 1  flock -n /tmp/weekly-digest.lock /srv/support-digest/weekly-digest.sh
  5. 5

    Or schedule it in CI

    Anthropic's GitHub Action runs a prompt on a cron schedule. GitHub runs scheduled workflows only from the default branch and, in public repositories, disables the schedule after 60 days without repository activity.

    name: Weekly digest
    on:
      schedule:
        - cron: "0 7 * * 1"
    jobs:
      digest:
        runs-on: ubuntu-latest
        permissions:
          contents: read
          id-token: write
        steps:
          - uses: actions/checkout@v6
          - uses: anthropics/claude-code-action@v1
            with:
              anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
              prompt: "Follow prompts/weekly-digest.md and print the digest"
              claude_args: |
                --max-turns 40
                --allowedTools "Read,Grep,Glob"
  6. 6

    Read the result

    With JSON output each run ends with one object that includes the result, the session id and total_cost_usd. In GitHub Actions the result appears in the workflow run log unless the prompt posts it somewhere.

sourcesClaude Code docs: headless modeClaude Code docs: authenticationClaude Code docs: GitHub Actions

timercron or CI
credentialapproval
claude -ptools and limits
resultJSON with cost
fig 2 One script, started by a timer.
03What breaks

What breaks when Claude Code runs on a schedule?

Four things, and none of them is the timer. The timer is the solved part. What a scheduled run lacks is everything a person at the keyboard was quietly providing: a login, a memory of last time, a decision at the risky step and a reason to look at the result.

Credentials come first because they fail silently. Anthropic's authentication docs say a stored claude.ai login has an end date and that renewing early matters most for sessions that run unattended. A token from claude setup-token lasts one year, is printed once and is tied to the subscription of the person who created it. When ANTHROPIC_API_KEY is also set, headless mode uses the key, so check which credential a run is really billed to.

What a person at the keyboard was providing.
What breaksWhyWhat you would build
CredentialsA personal login ends, a personal token belongs to one person, and two credentials in one environment hide which one is usedOne credential per purpose in a secret store, with an owner and a renewal date
StateEach headless run starts fresh. A session can be resumed on the machine that stores it, and a fresh CI runner stores noneA place outside the run for what was done, what was decided and what comes next
GatesWith nobody attached, a call that needs approval is denied, so the work stops instead of waitingA step that holds the work and waits for a named person
The recordOutput goes to a log that expires, and the cost of each run sits in its own JSONA run record that outlives the job: outcome, cost, duration and who approved what

sourcesClaude Code docs: authenticationClaude Code docs: headless modeClaude Code docs: GitHub Actions

Credentialsa login that lasts
Statewhat happened last time
Gatesa decision that waits
The recordoutcome and cost
fig 3 What a person at the keyboard was providing.
04In ConvOps

How does ConvOps run Claude Code on a schedule?

ConvOps puts the schedule on the task and keeps the state, the gates and the record outside the run. Each time the schedule fires, it creates a task and an isolated run works that task through its workflow, one pod per run. Attended and unattended are the same workflow, so the process your team already walks in Claude Code is the one the schedule starts.

ConvOps does not sell or host models. Unattended runs can use your Claude subscription or an Anthropic API key. Add either one as a provider connection. Your plan's own limits apply. Isolated runs on ConvOps Cloud are included on paid plans, fair use: heavy use moves to your own runners. The same ConvOps schedule can start OpenCode on a provider key.

  1. 1

    Run the workflow attended first

    Connect Claude Code and walk the workflow yourself a few times. A step that confuses you at the keyboard will confuse a run at night.

  2. 2

    Add a provider connection

    Choose a Claude subscription token or an Anthropic API key. Send it through a one-time link, paste it while signed in, or point ConvOps at Google Secret Manager. ConvOps checks a subscription with one real call per model before a run relies on it.

  3. 3

    Create an executor

    An executor says which agent starts and on which connection. A Claude Code executor links to exactly one connection: the subscription or the key.

  4. 4

    Describe the agent environment

    The environment names the repository, the git access and any secrets the work uses. The subscription token reaches the run as a secret, never as a value in a tool call, a prompt or a log.

  5. 5

    Add the schedule

    Pick a cadence or a repeat rule and a time zone: every few minutes, hourly, daily, weekdays, weekly or monthly. See the next five runs before you save a schedule.

  6. 6

    Read what ran

    ConvOps records the cost, duration, queue wait, tokens, turns and outcome of every run. A schedule that belongs to a program skips a fire while its previous run is still going. A scheduled run that cannot start is logged with the reason, not silently dropped.

schedulecadence, time zone
executorone connection
isolated runone pod
gateapproval
recordcost and outcome
fig 4 The schedule creates the task. The run walks the workflow.
05Subscription or API key

Should a scheduled run use a Claude subscription or an API key?

Either works; the difference is who it belongs to and how it is billed. Anthropic's docs describe the long-lived token as a credential for CI pipelines and scripts that authenticates with a Claude subscription, and recommend an API key for a secret shared across repositories because the token is tied to one person. Your plan's own limits apply to subscription use, so read them before you size a schedule.

QuestionSubscription tokenAnthropic API key
Where it comes fromclaude setup-token, printed onceThe Claude Console
Who it belongs toThe person who created itNot tied to one person's subscription
How use is countedAgainst the subscriptionPer token, on the API account
Works in bare modeNoYes
In ConvOpsA provider connectionA provider connection

sourcesClaude Code docs: authenticationClaude Code docs: GitHub Actions

06When cron is enough

When is plain cron enough?

Plain cron is enough when one person owns the job, the run only reads and reports, and a bad run costs a few minutes. A weekly digest that nobody acts on without reading it fits that description. So does a nightly link check.

Move to something with gates and a record when the run changes things other people depend on, when more than one person needs to know what it did, or when the answer to "what did it cost last month" matters. If your team already runs a cluster, running Claude Code unattended on Kubernetes covers the pod, the image and the network rules in detail.

Frequently asked questions

What does it mean to run Claude Code on a schedule?

It means a timer starts Claude Code in headless mode with a saved prompt, and the run finishes with nobody typing. In ConvOps, a schedule on the task creates the work on a cadence and an isolated run walks it through the workflow. The run stops at the gates your team placed and leaves a record of its outcome and cost.

Can Claude Code run on a schedule with my laptop closed?

Yes, if the run lives somewhere other than the laptop. ConvOps runs each scheduled task in an isolated pod on ConvOps Cloud or on your own runners, so no machine of yours has to stay awake. A CI schedule and Anthropic's cloud scheduled tasks also work without your machine, while cron and the /loop command need theirs switched on.

Can a scheduled Claude Code run use a Claude subscription?

Yes. ConvOps accepts a Claude subscription or an Anthropic API key as the provider connection for unattended runs. Anthropic's docs describe a long-lived token, created with claude setup-token, for scripts and CI where a browser login is unavailable. Your plan's own limits apply, and ConvOps checks the subscription with one real call per model before a run relies on it.

How do I stop a scheduled run from overlapping the previous one?

In ConvOps, a schedule that belongs to a program skips a fire while its previous run is still going, and a run that cannot start is logged with the reason. With plain cron, wrap the command in a lock such as flock. In a Kubernetes CronJob, set the concurrency policy to Forbid. In CI, use the concurrency controls your CI system provides.

Where does a scheduled Claude Code run wait for approval?

At a gate on the workflow step, not in the session. A ConvOps gate holds the step until an explicit approval is given, recorded with the account that gave it, so the work waits for hours or days. A plain headless run cannot wait: with nobody attached, a call that needs approval is denied and the run moves on or fails.

Who should run Claude Code on a schedule?

It suits teams with recurring work that follows the same steps each time: a weekly support digest, a month-end reconciliation, a pipeline report or a nightly bug sweep. ConvOps is for the teams among them that want one process and one record for the whole team, with checkpoints where a person, a metric or a report should decide.