Essay/Claude Code·May 13, 2026

How to Use Claude Code Routines: The Complete Setup Guide

Claude Code Routines are named, reusable scripts that run independently of the desktop app — letting you automate repetitive dev tasks. Here's how to set them up.

Luke Thompson
Luke ThompsonMay 13, 2026 · 6 min read
In this article
How to Use Claude Code Routines: The Complete Setup Guide
Claude Code Routines let you automate tasks at scale—running Claude Code on a schedule, via API, or triggered by webhooks. But the actual setup is different depending on which type you need. This guide walks you through all three, from the UI to production deployment.

What Are Routines? (The Quick Version)

Routines are named, reusable Claude Code scripts that run independently of the Claude Code desktop app. You can:

  • Schedule them to run on a cron schedule (e.g., "every Monday at 9am")
  • Trigger them via API from your own app or service
  • Listen to webhooks from GitHub, Slack, or other platforms to auto-trigger

Unlike one-off code execution, Routines persist, log execution history, and integrate into your broader automation stack.

Setting Up Your First Routine (Scheduled)

The easiest way to start is with a scheduled routine—Claude Code runs your script on autopilot.

  1. Create the routine in Claude Code Desktop

    • Open Claude Code on your machine
    • Click "New Routine"
    • Write your code (or paste an existing script)
    • Give it a clear name: daily_report_generator (not "script1")
  2. Set the schedule

    • Choose "Scheduled" mode
    • Pick your timezone (this matters—a lot)
    • Set the cron expression or use the UI picker
    • Examples: 0 9 * * 1-5 (9am weekdays) or 0 0 * * 0 (midnight Sunday)
  3. Test it once before scheduling

    • Click "Run Now" to verify it works
    • Check logs for errors
    • Fix any issues, then enable the schedule

API Routines: Triggering from Your Code

API Routines are the same script, but triggered on-demand from your application.

Setup:

  1. Create the routine with the same steps as above
  2. Switch mode to "API"
  3. Claude Code generates a unique endpoint URL and API key
  4. Copy both—you'll need them in your code

Making the API call:

curl -X POST [https://routines.anthropic.com/api/v1/execute/YOUR_ROUTINE_ID](https://routines.anthropic.com/api/v1/execute/YOUR_ROUTINE_ID) \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input": "optional data to pass to the routine"}'

Example: Trigger from a Node.js app

const response = await fetch('[https://routines.anthropic.com/api/v1/execute/my-routine-id](https://routines.anthropic.com/api/v1/execute/my-routine-id)', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk-routine-xxxx',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ input: 'my data' })
});
const result = await response.json();
console.log(result.execution_id); // Track the execution

Key points:

  • API calls are async—you get back an execution_id, not the result
  • Poll the execution status endpoint to check when it's done
  • Results are stored in the Routine's history in Claude Code Desktop

GitHub Webhooks: Auto-Trigger on Push/PR

The most powerful setup: your routine triggers automatically when something happens in GitHub.

Setup:

  1. In Claude Code, create your routine in "Webhook" mode
  2. Claude Code generates a webhook URL
  3. Go to your GitHub repo → Settings → Webhooks
  4. Add a new webhook:
    • Payload URL: paste Claude Code's webhook URL
    • Content type: application/json
    • Events: Pick what triggers it (push, pull_request, issues, etc.)
    • Check "Active"
  5. Save—GitHub will immediately test it

Example use case: Auto-fix code quality on push

// Your routine code
const payload = process.env.WEBHOOK_PAYLOAD; // GitHub sends the event data
const commit = JSON.parse(payload).commits[0];
console.log(`Analyzing commit: ${commit.id}`);
// Run your linter, formatter, or analysis here

Webhook events to watch for:

  • push — runs when code is pushed
  • pull_request — runs when a PR is opened/updated
  • issues — runs when an issue is created
  • workflow_run — runs when a GitHub Action completes (great for post-CI tasks)

Pro tip: Use GitHub's webhook history to debug if your routine isn't triggering.

Managing & Monitoring Your Routines

  • View execution logs — Click your routine → Executions tab → see every run, timestamps, error messages
  • Set alerts — (Coming soon) Get notified if a routine fails 3x in a row
  • Disable without deleting — Toggle the routine off to pause it; re-enable anytime
  • Update the code — Edit and save; new code takes effect on the next execution
  • Set timeouts — Routines max out at 30 minutes; if your task is longer, break it into chunks
  • Cost tracking — Each API call or scheduled execution costs tokens; monitor usage in your dashboard
Field note

The most common mistake: Setting a scheduled routine to run too frequently. Start with daily or weekly. If you need hourly, test with a smaller dataset first—you'll burn through credits fast.

Real-World Workflows

Daily report generator (Scheduled)

  • Routine: Query your database, format a report, email it
  • Schedule: 0 9 * * 1-5 (9am weekdays)
  • Result: Your inbox gets the report automatically every morning

Slack notification on merged PR (Webhook)

  • Trigger: GitHub webhook on pull_request (action: closed + merged)
  • Routine: Parse the PR data, call Slack API, post a summary
  • Result: Your team sees PR changes in real-time, no manual pinging

On-demand analysis (API)

  • Your web app has a "Analyze my data" button
  • Button calls the API Routine endpoint
  • Routine processes the data, stores results in your database
  • Your app polls for the result and shows it to the user

Nightly data sync (Scheduled + Webhook)

  • Combine scheduled (nightly at 2am) with webhook (on demand after a manual GitHub release tag)
  • Same routine, triggered two ways, logs to the same history

What This Means For You

Routines unlock true automation with Claude Code—no servers to manage, no deployment complexity. Pick the trigger type that fits your workflow:

  • Scheduled for predictable, recurring tasks
  • API when you need on-demand execution from your app
  • Webhooks when external services should kick off your routine

Start simple. Test one routine end-to-end. Once you see it working, scale up. The hardest part isn't the setup—it's resisting the urge to automate everything at once.

Next step: Go write your first routine and set it to run tomorrow morning. You'll be hooked.

Field note
Field note

Related: Anthropic and SpaceX Partner on AI Infrastructure: Claude Code Usage Limits Double, Musk Praises Anthropic Over OpenAI — Learn more about Anthropic and SpaceX Partner on AI Infrastructure

Field note

Sources & Further Reading

Claude Code Documentation: Routines — Official setup guide and API reference. Claude Code Desktop App — Where you create and manage routines. GitHub Webhooks Docs — Setting up GitHub triggers. Our previous post: Claude Code Gets a Full Redesign — and Routines — The announcement of Routines and what they mean for enterprises.

Related essay
GitHub Copilot Now Lets You Run Claude and Codex Agents Natively—No Switching Required
Related essay
Claude Agents Just Got a Major Upgrade: Dreaming, Better Memory, and Real Multi-Agent Orchestration
Related essay
Claude Code Gets a Mission Control and Routines That Run While You Sleep

THE CLAUDE INSIDER

Get the Claude playbook in your inbox.

One weekly email for Claude and Claude Code users. Real workflows, no hype. Subscribe and we send you The Claude Power-User Cheatsheet.

GUIDES AND COMPARISONS

— ¶ —

Luke Thompson

Luke Thompson

Editor-in-Chief · The Claude Insider

Luke Thompson is the founder of The Operations Guide, LLC and editor of The Claude Insider. Based in Jonesborough, Tennessee, he has spent years building AI-augmented business systems and automation workflows for operators and teams. He began working with large language models in production well before the current wave of consumer AI tools, integrating them into client workflows, content pipelines, and operational infrastructure. At The Claude Insider, he writes about Claude with the specificity of someone who uses it daily as a professional tool — not as a reviewer or commentator, but as a builder. His coverage focuses on what actually works: prompt patterns, API integration strategies, agentic workflows, and the real-world tradeoffs that practitioners face. He is not affiliated with Anthropic, PBC.

Articles are researched and drafted with AI assistance, reviewed and edited by Luke Thompson.

From Reading to Action

Know where AI can pay off in your company.

Take the free two-minute AI Readiness Assessment. See your score, the two gaps holding you back, and the next move worth making.

Get your readiness score

Instant report · No account to start

Related reading

View archive →