{"slug": "how-to-use-goal-and-routines-in-claude-code-for-autonomous-scheduled-workflows", "title": "How to Use /goal and /routines in Claude Code for Autonomous Scheduled Workflows", "summary": "Anthropic's Claude Code now supports /goal and /routines commands that enable developers to define persistent objectives and schedule recurring tasks for autonomous execution, reducing the need for manual oversight in workflows like daily testing and documentation sync.", "body_md": "# How to Use /goal and /routines in Claude Code for Autonomous Scheduled Workflows\n\nCombine /goal and /routines in Claude Code to run recurring tasks autonomously. Learn how to set completion conditions so agents finish without stopping early.\n\n## Running Recurring Tasks Without Babysitting Claude Code\n\nMost people use Claude Code as a back-and-forth assistant: ask a question, get an answer, ask again. That works fine for one-off tasks. But the moment you want Claude to do something on a schedule — run tests every morning, summarize new tickets weekly, keep documentation in sync — the interactive model breaks down fast.\n\nThat’s where `/goal`\n\nand `/routines`\n\ncome in. Together, these two Claude Code commands let you define what you want done and when to do it, then step away while Claude executes autonomously. No babysitting, no repeated prompts, no agent that stops halfway through because it wasn’t sure whether to proceed.\n\nThis guide covers how each command works, how to combine them for scheduled autonomous workflows, and — critically — how to write completion conditions that prevent Claude from stopping early or spinning indefinitely.\n\n## What `/goal`\n\nActually Does\n\nThe `/goal`\n\ncommand sets a persistent, top-level objective for your Claude Code session. Instead of issuing individual task instructions and hoping Claude holds context, `/goal`\n\nanchors everything Claude does to a single declared outcome.\n\nThink of it less like a prompt and more like a contract. You’re telling Claude: this is the definition of done. Everything else is a step toward that.\n\n### Syntax and Basic Usage\n\n```\n/goal <description of the desired end state>\n```\n\nA concrete example:\n\n```\n/goal All TypeScript files in /src have passing lint checks, \n      type errors are resolved, and the test suite passes with \n      no skipped tests.\n```\n\n## Remy is new. The platform isn't.\n\nRemy is the latest expression of years of platform work. Not a hastily wrapped LLM.\n\nNotice that this is written as a **state**, not a command. “Passing lint checks” is a condition you can verify. “Fix the code” is not. That distinction matters a lot when Claude is running autonomously.\n\n### What Changes When You Set a Goal\n\nWithout `/goal`\n\n, Claude treats each message as an isolated instruction. With `/goal`\n\n, Claude:\n\n- Keeps the end state in context across the entire session\n- Plans multi-step sequences rather than single actions\n- Checks itself against the goal condition before stopping\n- Re-evaluates its approach when a step fails, rather than asking you what to do\n\nThis is the shift from “AI assistant” to “AI agent.” Claude isn’t waiting for your next instruction — it’s working toward a defined outcome.\n\n## What `/routines`\n\nDoes\n\n`/routines`\n\nis the scheduling layer. It lets you define tasks that should run on a cadence — daily, weekly, on a trigger, or at a specific time — without you kicking them off manually each time.\n\n### Syntax\n\n```\n/routines add <routine-name> --schedule \"<cron or natural language>\" --task \"<what to do>\"\n```\n\nExample:\n\n```\n/routines add daily-lint-check \\\n  --schedule \"every day at 7am\" \\\n  --task \"Run lint on all modified files in /src and write a summary to logs/lint-report.md\"\n```\n\nYou can list active routines with `/routines list`\n\nand remove them with `/routines remove <routine-name>`\n\n.\n\n### What Makes a Good Routine Definition\n\nA routine task description should be self-contained. Since Claude won’t have a conversation to refer back to, the task string needs to include:\n\n- What to operate on (which files, directories, APIs, or services)\n- What action to take\n- Where to put the output\n- What “done” looks like\n\nVague task descriptions like “check the code” produce unreliable results. Specific ones like “run `npm test`\n\nand append the pass/fail summary to logs/test-history.md with today’s date” give Claude enough to work with.\n\n## Combining `/goal`\n\nand `/routines`\n\nfor Autonomous Workflows\n\nUsed separately, these commands are useful. Used together, they form a proper autonomous workflow loop.\n\nHere’s the pattern:\n\n**Set a**— the persistent end state you want to maintain`/goal`\n\n**Define**— the recurring tasks that work toward or verify that goal`/routines`\n\n**Set completion conditions**— explicit criteria so Claude knows when each run is finished\n\n### A Practical Example: Automated Code Quality Monitoring\n\nSuppose you want Claude to check your codebase every morning, fix auto-fixable issues, and flag anything it can’t fix.\n\n**Step 1: Set the goal**\n\n```\n/goal The /src directory has zero fixable lint errors. \n      All non-auto-fixable issues are logged to \n      logs/manual-review.md with file path and line number.\n```\n\n**Step 2: Add the routine**\n\n```\n/routines add morning-quality-check \\\n  --schedule \"weekdays at 8am\" \\\n  --task \"Run eslint --fix on /src. Log any remaining errors \n          that cannot be auto-fixed to logs/manual-review.md. \n          Append a completion summary to logs/quality-log.md \n          with timestamp and counts.\"\n```\n\n**Step 3: Define the completion condition explicitly**\n\nThis is where most people go wrong. If you don’t tell Claude what “done” looks like for a given run, it may keep trying to fix unfixable errors, or stop too early because it hit an ambiguous state.\n\nAdd this to your task description:\n\n```\nThe routine is complete when: (a) eslint --fix has run on all \n.ts and .tsx files, (b) any remaining errors are written to \nlogs/manual-review.md, and (c) the summary line has been \nappended to logs/quality-log.md. Do not retry errors that \neslint cannot fix automatically.\n```\n\nNow Claude has a clear exit condition. It finishes the run, writes the output, and stops — rather than looping indefinitely on unresolvable errors.\n\n## Setting Completion Conditions That Actually Work\n\nThe most common failure mode with autonomous Claude Code workflows isn’t the AI doing something wrong — it’s the AI not knowing when it’s done.\n\n### Why Agents Stop Early\n\nClaude Code will stop a routine mid-run if it encounters:\n\n- An ambiguous state with no clear next action\n- A step that requires human confirmation (by default)\n- An error it wasn’t told how to handle\n- No visible progress after several attempts\n\nEach of these can be addressed with explicit instructions.\n\n### Pattern 1: Define the Output Artifact\n\nThe clearest completion condition is a file that either exists or doesn’t.\n\n```\nThe routine is complete when logs/2024-01-15-report.md exists \nand contains at least a summary section.\n```\n\nClaude can check this condition deterministically. It either created the file or it didn’t.\n\n### Pattern 2: Define Exit Conditions for Each Error Type\n\nTell Claude explicitly what to do when something goes wrong:\n\n```\nIf a file fails linting and cannot be auto-fixed:\n  - Log it to logs/manual-review.md and continue\n  - Do NOT stop the run\n  - Do NOT ask for confirmation\n\nIf the test suite fails:\n  - Log the failure output to logs/test-failures.md\n  - Mark the run as failed in logs/quality-log.md\n  - Stop the routine for today\n```\n\nThis prevents Claude from pausing to ask you a question at 3 AM when it hits an unexpected state.\n\n### Pattern 3: Set a Maximum Retry Count\n\nFor tasks that involve retries (API calls, build steps), set an explicit ceiling:\n\n```\nRetry failed steps up to 3 times. After 3 failures, \nlog the error and continue to the next file.\n```\n\nWithout this, Claude may retry indefinitely or give up after one failure depending on how it interprets the situation.\n\n### Pattern 4: Use a Done Marker\n\nFor longer workflows with multiple steps, have Claude write a marker file when everything completes:\n\n```\nWhen all steps are complete, write \"DONE\" to .routine-status/morning-check-complete.\n```\n\nYou can check this file externally to confirm the routine actually finished.\n\n## Advanced Patterns for Scheduled Workflows\n\nOnce you have the basics working, a few patterns make autonomous workflows significantly more reliable.\n\n### Chaining Routines\n\nYou can set up routines that depend on each other by using the output of one as the input for the next.\n\n```\n/routines add generate-changelog \\\n  --schedule \"every Friday at 5pm\" \\\n  --task \"Read logs/quality-log.md from this week. \n          Summarize key issues and resolutions. \n          Write to CHANGELOG-draft.md.\"\n\n/routines add review-changelog \\\n  --schedule \"every Friday at 5:30pm\" \\\n  --task \"Read CHANGELOG-draft.md. Check for completeness. \n          If summary is at least 100 words and covers all \n          log entries, rename it to CHANGELOG.md. \n          Otherwise log 'incomplete' to changelog-errors.log.\"\n```\n\nThe 30-minute gap gives the first routine time to finish before the second starts. You could also use a trigger-based approach if your setup supports it.\n\n### Using `/goal`\n\nAcross Multiple Sessions\n\nBy default, `/goal`\n\npersists for the duration of a session. If you want a goal to survive across sessions (useful for long-running projects), write it to a file Claude loads on startup.\n\nCreate a file called `AGENT_GOAL.md`\n\nin your project root:\n\n```\n# Current Agent Goal\n\nMaintain zero fixable lint errors in /src. \nAll open GitHub issues labeled \"bug\" should have \nat least a triage comment within 24 hours of creation.\n```\n\n## Seven tools to build an app. Or just Remy.\n\nEditor, preview, AI agents, deploy — all in one tab. Nothing to install.\n\nThen reference it in your routine:\n\n```\n/routines add load-goal \\\n  --schedule \"on session start\" \\\n  --task \"Read AGENT_GOAL.md and set it as the active goal \n          for this session.\"\n```\n\nThis keeps Claude aligned with your project’s objectives even when sessions restart.\n\n### Parameterized Routines\n\nIf you’re running similar routines across multiple directories or services, parameterize them:\n\n```\n/routines add check-service \\\n  --schedule \"every hour\" \\\n  --task \"For each directory in /services: \n          run health check, log status to \n          logs/{service-name}-health.log. \n          Done when all directories have been checked.\"\n```\n\nClaude will iterate through the directories and produce per-service logs without you writing separate routines for each one.\n\n## Common Mistakes and How to Fix Them\n\n### Mistake 1: Imperative Goals Instead of State Goals\n\n**Wrong:**\n\n```\n/goal Fix all the bugs in the codebase.\n```\n\n**Right:**\n\n```\n/goal The test suite passes with 0 failures and 0 errors. \n      All files in /src compile without TypeScript errors.\n```\n\nThe second version is verifiable. Claude can check whether the conditions are met.\n\n### Mistake 2: Task Descriptions Without Scope\n\n**Wrong:**\n\n```\n--task \"Clean up the code\"\n```\n\n**Right:**\n\n```\n--task \"Run prettier on all .ts files in /src/components. \n        Stage the changes. Do not commit. \n        Write a list of modified files to logs/format-changes.md.\"\n```\n\nScope prevents Claude from doing too much (refactoring unrelated files) or too little (touching one file and stopping).\n\n### Mistake 3: No Error Handling Instructions\n\nIf your task can fail — and most real tasks can — you need to say what Claude should do when it does. Without explicit instructions, Claude’s behavior on errors is unpredictable.\n\nAlways include:\n\n- What to do on failure\n- Whether to continue or stop\n- Where to log the error\n\n### Mistake 4: Overlapping Routines\n\nIf two routines operate on the same files at overlapping times, they’ll conflict. Either stagger the schedules or use a lock file:\n\n```\nBefore starting: check if .routine-lock exists. \nIf it does, wait 5 minutes and check again. \nIf not, create .routine-lock. \nDelete .routine-lock when done.\n```\n\n## Where MindStudio Fits for Teams Who Want More\n\nClaude Code with `/goal`\n\nand `/routines`\n\nis powerful for developers comfortable in the terminal. But it has real limits: it runs locally, it doesn’t have a UI for non-technical stakeholders, and connecting it to external services (Slack notifications, database writes, third-party APIs) requires custom code.\n\nIf you’re building autonomous workflows that need to run in the cloud, trigger on external events, or interact with business tools, [MindStudio](https://mindstudio.ai) handles a lot of that infrastructure for you.\n\nMindStudio’s [autonomous background agents](https://mindstudio.ai/blog/what-are-ai-agents) run on a schedule — daily, weekly, or on a cron expression — without any server to manage. You define the workflow once, connect it to tools like Slack, Notion, HubSpot, or Google Workspace through built-in integrations, and it runs on its own.\n\nFor teams where developers are using Claude Code for deep technical work but need to share results with broader teams, the combination works well: Claude Code handles the code-level reasoning locally, while MindStudio handles the reporting, notifications, and downstream actions that involve non-technical stakeholders.\n\n### Built like a system. Not vibe-coded.\n\nRemy manages the project — every layer architected, not stitched together at the last second.\n\nYou can [try MindStudio free at mindstudio.ai](https://mindstudio.ai) — no credit card required, and the scheduled agent setup takes under an hour.\n\n## Real-World Use Cases\n\nHere are some workflows that work well with `/goal`\n\n+ `/routines`\n\n:\n\n### Daily Documentation Sync\n\n```\n/goal /docs accurately reflects the current API surface \n      in /src/api. All public functions have docstrings. \n      README is current.\n\n/routines add doc-sync --schedule \"every day at 9am\" \\\n  --task \"Compare function signatures in /src/api against \n          /docs. Update any outdated entries. \n          Add missing docstrings. \n          Write change summary to logs/doc-updates.md. \n          Done when all functions match their documentation.\"\n```\n\n### Dependency Security Checks\n\n```\n/routines add security-audit --schedule \"every Monday at 6am\" \\\n  --task \"Run npm audit. If vulnerabilities found, \n          write report to logs/security-{date}.md. \n          If critical vulnerabilities exist, \n          write CRITICAL to security-alert.txt. \n          Done when audit has run and output is logged.\"\n```\n\n### Test Coverage Monitoring\n\n```\n/goal Test coverage for /src/core stays above 80%.\n\n/routines add coverage-check --schedule \"after each push\" \\\n  --task \"Run jest --coverage. \n          If coverage drops below 80% for any file in /src/core, \n          log the file and current coverage to logs/coverage-drop.md. \n          Write overall coverage percentage to \n          logs/coverage-history.md with timestamp.\"\n```\n\n## Frequently Asked Questions\n\n### Does `/goal`\n\npersist across Claude Code sessions?\n\nBy default, `/goal`\n\nis scoped to a single session and resets when you close and reopen Claude Code. To persist a goal across sessions, write it to a file in your project (like `AGENT_GOAL.md`\n\n) and reference it in a startup routine. Some teams also store goals in a `.claude/config`\n\nfile for automatic loading.\n\n### How do I prevent a routine from running if the previous run didn’t complete?\n\nUse a lock file pattern. At the start of the routine task, instruct Claude to check for a `.routine-lock`\n\nfile. If it exists, skip the run and log a “previous run incomplete” message. If it doesn’t exist, create it, run the task, then delete it on successful completion. This prevents overlapping runs and surfaces incomplete executions.\n\n### Can `/routines`\n\ntrigger on events rather than just schedules?\n\nClaude Code’s native `/routines`\n\nsupports time-based scheduling. For event-driven triggers (like “run when a PR is opened” or “run when a file changes”), you’ll need to combine it with external tooling — a file watcher, a CI/CD hook, or a webhook. The routine itself can be called from those external triggers by invoking Claude Code from a script.\n\n### What happens if Claude hits an error during a routine and I’m not at my computer?\n\nWithout explicit error handling instructions in the task definition, Claude’s behavior varies — it may retry, pause, or stop. The safest approach is to include explicit instructions for every expected error type: log and continue, log and stop, or retry up to N times. This makes failure behavior predictable regardless of when the error occurs.\n\n### How specific do completion conditions need to be?\n\nAs specific as possible. The clearer the exit condition, the less likely Claude is to stop early or loop indefinitely. The best completion conditions are checkable by Claude in a single step — does this file exist, does this command return exit code 0, does this log contain the expected string. Vague conditions like “when everything looks good” leave too much to interpretation.\n\n### Can I run multiple goals simultaneously?\n\nClaude Code supports one active `/goal`\n\nper session. If you need parallel autonomous workflows with separate goals, run them in separate Claude Code sessions with separate working directories. Some teams use tmux or similar tools to manage multiple concurrent sessions on the same machine.\n\n## Key Takeaways\n\n`/goal`\n\nsets a persistent end state that Claude works toward across multi-step tasks — write it as a verifiable condition, not a command.`/routines`\n\nschedules tasks on a cadence without manual triggering — task descriptions need to be self-contained with scope and output locations defined.- Completion conditions are the most important part of any autonomous workflow — without them, agents stop early or loop indefinitely.\n- Handle errors explicitly in your task descriptions: what to do on failure, whether to continue or stop, and where to log.\n- For cloud-based scheduled agents that integrate with business tools and work for non-technical teams,\n[MindStudio](https://mindstudio.ai)extends what Claude Code handles locally.", "url": "https://wpnews.pro/news/how-to-use-goal-and-routines-in-claude-code-for-autonomous-scheduled-workflows", "canonical_source": "https://www.mindstudio.ai/blog/claude-code-goal-routines-autonomous-workflows/", "published_at": "2026-06-24 00:00:00+00:00", "updated_at": "2026-06-24 14:13:43.245138+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "large-language-models", "ai-agents"], "entities": ["Anthropic", "Claude Code"], "alternates": {"html": "https://wpnews.pro/news/how-to-use-goal-and-routines-in-claude-code-for-autonomous-scheduled-workflows", "markdown": "https://wpnews.pro/news/how-to-use-goal-and-routines-in-claude-code-for-autonomous-scheduled-workflows.md", "text": "https://wpnews.pro/news/how-to-use-goal-and-routines-in-claude-code-for-autonomous-scheduled-workflows.txt", "jsonld": "https://wpnews.pro/news/how-to-use-goal-and-routines-in-claude-code-for-autonomous-scheduled-workflows.jsonld"}}