CloudCode Routines: Setup, Gotchas, and Remote AI Automation
Run one-shot AI prompts on Anthropic's cloud via GitHub repo clones—no laptop needed. Use cloud env vars for API keys, full network access for untrusted domains, specific prompts. Limits: Pro 5 runs/day, Max 15, min 1hr interval.
Essential Setup for Stateless Remote Routines
CloudCode routines execute prompts on Anthropic's infrastructure by cloning your GitHub repo, reading claude.md and scripts, then destroying the clone after. Requires a GitHub repo; select it during setup alongside model, cloud environment, schedule (hourly min, daily, weekdays), connectors (Slack/Gmail OAuth), and permissions. Prompts must be one-shot—specific enough to complete without user input, as no interaction occurs.
Test via 'Run Now' to watch in real-time, interrupt, or continue. Past runs persist in history for debugging. For code changes/reviews, output pushes to a new GitHub branch; other tasks are fully stateless.
Example: Prompt "Send a message in the internal ClickUp channel" succeeds after adding ClickUp API key to cloud env vars and setting network access to full (trusted blocks unvetted domains like ClickUp).
Managing Secrets, Access, and Network Security
Never rely on .env (gitignored); inject API keys via cloud environment variables (e.g., YouTube API key). Explicitly instruct prompts: "My YouTube API key is available as an environment variable. Use it directly from the environment. Don't look for a .env."
Network levels: Trusted limits to Anthropic-vetted domains (Anthropic services, GitHub, Google Cloud); full allows all but risks malicious outbound requests if prompt ingests bad content. Use custom for specific domains. Setup scripts run pre-Claude for package installs.
Stateless runs lack local files/cookies; browser automations (e.g., Playwright CLI on school community) fail without API endpoints using headers/cookies/API keys. Rule: If not in GitHub repo or reachable via API, it won't work.
Connectors enable OAuth for services like Slack/ClickUp, easier than manual keys.
Triggers, Limits, and Prompt Optimization
Triggers: Schedule (natural language, 1hr min), API calls (POST from other automations), GitHub events (PRs, pushes, issues, releases). Compares to local scheduled tasks/: Routines need no machine/session, but lack local files, require 1hr min (vs 1min local), fully autonomous.
Quotas: Pro 5 runs/day, Max 15, Team/Enterprise 25 (metered overage possible). Each: 4 vCPUs, 16GB RAM, 30GB disk—avoid massive repos; use dedicated repo per routine to minimize claude.md context drain on token limits.
Optimize prompts with order of operations, skills, error self-correction: e.g., "Run skill X, then Y; if error, Z." Keeps agentic WAT framework (workflows, agents, tools) intact vs script-only cloud deploys—self-corrects mid-run, leaves memory trails across stateless executions.
Why Routines Excel and Quick Fixes
Beats local tasks: Laptop-off freedom preserves full agent reasoning from claude.md/scripts. Migrate by copying prompts, adapting for env vars/statelessness.
FAQs: No cron needed (natural language); no local files; any model selectable; real-time watchable; MCP via connectors; individual account only (team sharing untested); normal sub costs; failures logged—add "If fail, Slack me"; always test multiple times.
Risks low for private repos you control; test thoroughly to avoid unintended changes (runs as you).