Languages: EN RU

Cloud Agents: Web, Routines, and Background Tasks

In previous articles we covered automation via GitHub Actions and GitLab CI/CD — both approaches are tied to your repository's pipeline. But what if a task has nothing to do with pushing to a branch? What if an agent needs to run overnight on a schedule, respond to monitoring alerts, or keep a PR up to date while you're in a meeting — all without an open terminal?

For this, Claude Code offers three distinct background-execution mechanisms. They differ in where the agent runs and how long a task lives.

flowchart TD subgraph CLOUD["☁️ Anthropic Infrastructure"] R["Routines\n(Schedule / API / GitHub)"] end subgraph LOCAL["💻 Your Machine"] D["Desktop scheduled tasks\n(no open session)"] L["/loop\n(inside an open session)"] end subgraph VIEW["👁 Agent View"] AV["claude agents\n(panel of all background sessions)"] end R -->|"creates a session on claude.ai"| AV D -->|"local tasks"| AV L -->|"session tasks"| AV style CLOUD fill:#e8f4f8,stroke:#2196f3 style LOCAL fill:#f0f8e8,stroke:#4caf50 style VIEW fill:#fff8e1,stroke:#ff9800
flowchart TD
    subgraph CLOUD["☁️ Anthropic Infrastructure"]
        R["Routines\n(Schedule / API / GitHub)"] 
    end
    subgraph LOCAL["💻 Your Machine"]
        D["Desktop scheduled tasks\n(no open session)"]
        L["/loop\n(inside an open session)"]
    end
    subgraph VIEW["👁 Agent View"]
        AV["claude agents\n(panel of all background sessions)"]
    end
    R -->|"creates a session on claude.ai"| AV
    D -->|"local tasks"| AV
    L -->|"session tasks"| AV
    style CLOUD fill:#e8f4f8,stroke:#2196f3
    style LOCAL fill:#f0f8e8,stroke:#4caf50
    style VIEW fill:#fff8e1,stroke:#ff9800
Three levels of background work in Claude Code: cloud, local, and session-level /loop

Three Levels of Background Execution

Before diving into the details, it's important to understand how the three mechanisms fundamentally differ:

Routines (cloud)Desktop tasks/loop
Where it runsAnthropic infrastructureYour machineYour machine
Requires an open terminalNoNoYes
Requires the machine to be onNoYesYes
Access to local filesNo (clones the repo)YesYes
Minimum interval1 hour1 minute1 minute
Survives without a sessionYesYesNo (dies after 7 days)

A simple rule: need to work without your machine — use Routines; need local files and your machine is on — use Desktop tasks; quick polling right now while the session is open — use /loop.


Quick recall
Где выполняется routine, и почему это определяет её главное преимущество?

Routines: An Agent That Doesn't Need Your Machine

A routine is a saved Claude Code configuration: a prompt, one or more repositories, and MCP connectors. Everything is packaged once and runs automatically on Anthropic's servers.

Status: Routines are in research preview. The API and limits are subject to change. Available on Pro, Max, Team, and Enterprise plans with Claude Code on the web enabled.

Each time a routine runs, a full Claude Code session is created — with all tools, but without permission prompts. The agent works autonomously: it reads, writes, calls MCP tools, and pushes branches. That's why the prompt needs to be as specific as possible: what to do and how to verify it worked.

Creating a Routine

There are two ways to create a routine: through the web interface at claude.ai/code/routines, or directly from the CLI using /schedule.

The CLI is faster for simple cases:

# Create a routine with a schedule — natural language
/schedule daily PR review at 9am

# One-time run
/schedule in 2 weeks, open a cleanup PR that removes the feature flag

# View the list and manage
/schedule list
/schedule update
/schedule run

/schedule requires authentication via claude.ai (not an API key). If ANTHROPIC_API_KEY is set in the environment, the command will be hidden — remove the key and sign in with claude login.

The web form exposes more options: model selection, environment configuration, multiple triggers at once, and MCP connectors.

Check yourself
You want to run a routine via the CLI using the `/schedule` command. Why isn't the command showing up in the interface even though you have Claude Code installed and an `ANTHROPIC_API_KEY` set?

Three Types of Triggers

A single routine can combine multiple triggers. For example, a code-review routine can be triggered on a schedule (nightly run), by an API call from a deploy script, and on every opened PR.

Schedule — time-based. Presets: hourly, daily, weekdays, weekly. For a non-standard interval (e.g., "every two hours") you need to set a cron expression via /schedule update in the CLI. The minimum interval is 1 hour. Time is specified in your local timezone.

API — triggered by an HTTP request. Once created, a routine gets a unique endpoint. Any system capable of making a POST request can start the agent:

curl -X POST https://api.anthropic.com/v1/claude_code/routines/trig_01ABCDEFGHJKLM/fire \
  -H "Authorization: Bearer sk-ant-oat01-xxxxx" \
  -H "anthropic-beta: experimental-cc-routine-2026-04-01" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"text": "Sentry alert SEN-4521 fired in prod. Stack trace attached."}'

The response includes a session URL — you can open it immediately and watch what the agent is doing.

{
  "type": "routine_fire",
  "claude_code_session_id": "session_01HJKLMNOPQRSTUVWXYZ",
  "claude_code_session_url": "https://claude.ai/code/session_01HJKLMNOPQRSTUVWXYZ"
}

GitHub — triggered by repository events. Supported events: pull_request (opened, closed, updated, labeled…) and release (created, published, deleted). Filters let you precisely control which PRs trigger the routine: by author, title, base branch, labels, or draft status.

Example: a routine that ports SDK changes to another language fires only on pull_request.closed + is_merged: true + labels: include needs-backport. No unnecessary runs.

Check yourself
A routine is configured with a GitHub trigger on `pull_request.closed`. Dozens of PRs are closed every day. How do you limit runs to only those PRs that were merged and have the `needs-backport` label?

Branches, Connectors, and Environments

Branches. By default, a routine can only push to branches with the claude/ prefix. This prevents accidental writes to main or release. To allow pushes to arbitrary branches, enable "Allow unrestricted branch pushes" in the routine's settings.

Connectors. These are your MCP servers added via claude.ai (not local ones added via claude mcp add — those only live on your machine). When creating a routine, all connectors are enabled by default. Remove any that aren't needed — the agent will only have access to what it actually requires.

Environment. Each routine runs in an isolated cloud environment with configurable: network access (list of allowed domains), environment variables (API keys, tokens), and a setup script (dependency installation, cached between runs). The standard "Default" environment allows package registries, cloud provider APIs, and CDNs — but blocks everything else.

What a "Green" Status Actually Means

An important nuance that's easy to miss: a green status in the run list means the session started and finished without an infrastructure error. It does not guarantee the task in the prompt was completed successfully. A network failure, a missing connector, or a logical error in the task — all of these are only visible inside the session, in the transcript.


Quick recall
Почему routine не запрашивает разрешения на действия, в отличие от интерактивной сессии?

Agent View: The Background Agent Dashboard

When routines or sub-agents are running in parallel, you need to see the full picture. That's what agent view is for — launch it with:

claude agents

This is a single screen showing all background sessions, grouped by state:

  • Needs input — the agent is waiting for your response
  • Working — actively executing a task
  • Completed — finished

At the bottom of the screen is a field for dispatching a new session. Navigate between sessions with the arrow keys; press Enter to enter a session and respond. You don't need N open terminals: open agent view, respond to agents in "Needs input" status, close it.

Each background session is a full conversation with Claude that continues without an open terminal. You can connect at any time: read the transcript, send a clarification, or create a PR from the changes.

Check yourself
You open the agent view and see several sessions with a "Needs input" status. What does this actually mean from the perspective of the agent loop?

/loop: Polling Right Inside the Session

If routines are "fire and forget," then /loop is "watch the terminal until the task is done." The command repeats a prompt on a schedule within the current session.

# Fixed interval + specific task
/loop 5m check if the deployment finished

# Dynamic interval — Claude picks the pause itself
/loop check CI and address review comments

# Bare /loop — built-in maintenance prompt
/loop

Three Behavioral Modes

Fixed interval (/loop 5m task). Claude converts the interval into a cron expression. Seconds are rounded up to the nearest minute. Non-standard intervals (7m, 90m) are rounded to the nearest supported value — Claude will tell you what it picked.

Dynamic interval (/loop task). Claude decides how long to wait after each iteration: it looks at what it found and picks a pause anywhere from 1 minute to 1 hour. If a build is still in progress — short pause; the PR is quiet and everything is green — longer pause. Sometimes instead of polling it uses the Monitor tool, which streams a process's stdout and reacts to events without spending tokens on idle checks.

Bare /loop. Runs the built-in maintenance prompt: continues unfinished work from the session, tends the PR (reviewer comments, failing CI, conflicts), and runs cleanup passes when there's nothing else to do. A solid way to leave the agent "on duty" for a branch overnight.

loop.md: Your Default Prompt

If bare /loop should do something specific to your project, create a loop.md file:

# .claude/loop.md
Check the `release/next` PR. If CI is red, pull the failing job log,
diagnose, and push a minimal fix. If new review comments have arrived,
address each one and resolve the thread. If everything is green and
quiet, say so in one line.

Search order: .claude/loop.md first (project level), then ~/.claude/loop.md (global). The file is read before each iteration, so you can edit it while /loop is running.

/loop Limitations

  • Tasks live only within the current session. They disappear when you start a new claude session. claude --resume restores unfinished tasks (created within the last 7 days).
  • Tasks don't fire while Claude is busy responding to another request — they wait their turn.
  • No catch-up: if a task didn't fire at its scheduled time (Claude was busy), it fires once as soon as Claude is free.
  • Maximum of 50 tasks per session.

To stop the loop: press Esc during the pause between iterations.


Quick recall
Что происходит с /loop задачей при закрытии Claude Code?

Practical Patterns

Alert triage via API trigger. A monitoring system (Sentry, Datadog, Grafana) calls the routine's endpoint, passing the alert body in the text field. The routine pulls the stack trace, correlates it with recent commits in the repo, and opens a draft PR with a proposed fix. The on-call engineer sees a ready PR instead of a blank terminal.

Nightly backlog cleanup. A schedule trigger runs every weeknight: reads tasks via a Slack/Linear connector, applies labels, and assigns owners. The team wakes up to a triaged backlog.

Keeping a PR tended during a session. You're working on something else but don't want to miss new comments on a PR:

/loop check whether CI passed and address any review comments on PR #247

Claude polls every few minutes, addresses comments, and reports any changes.

One-time reminder. Not through a routine — just natural language within the session:

remind me in 45 minutes to push the release branch

See Also

  • GitHub Actions and Automated Code Review — event-driven automation based on GitHub repository events
  • GitLab CI/CD and Headless Automation — headless mode and CI/CD without a pre-built action
  • Dynamic Workflows and Agent Orchestration — managing multiple agents and distributing subtasks
  • Sub-agents and Context Isolation — isolated agent sessions within a single project
  • Practice: GitHub, Databases, and Web APIs via MCP — MCP connectors you can attach to routines
  • CLAUDE.md and the Memory System — how to pass project context to an agent running in the cloud
  • Headless Mode and CLI Scripting — CLI flags and automation without interactive mode

Sources

  1. Automate work with routines — Claude Code docs
  2. Run prompts on a schedule (/loop) — Claude Code docs
  3. Manage multiple agents with agent view — Claude Code docs