How to Use /goal and /routines in Claude Code for Autonomous Scheduled Workflows
Combine /goal and /routines in Claude Code to run recurring tasks autonomously. Learn how to set completion conditions so agents finish without stopping early.
Running Recurring Tasks Without Babysitting Claude Code
Most 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.
That’s where /goal and /routines come 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.
This 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.
What /goal Actually Does
The /goal command sets a persistent, top-level objective for your Claude Code session. Instead of issuing individual task instructions and hoping Claude holds context, /goal anchors everything Claude does to a single declared outcome.
Think 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.
Syntax and Basic Usage
/goal <description of the desired end state>
A concrete example:
/goal All TypeScript files in /src have passing lint checks,
type errors are resolved, and the test suite passes with
no skipped tests.
Remy is new. The platform isn't.
Remy is the latest expression of years of platform work. Not a hastily wrapped LLM.
Notice 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.
What Changes When You Set a Goal
Without /goal, Claude treats each message as an isolated instruction. With /goal, Claude:
- Keeps the end state in context across the entire session
- Plans multi-step sequences rather than single actions
- Checks itself against the goal condition before stopping
- Re-evaluates its approach when a step fails, rather than asking you what to do
This is the shift from “AI assistant” to “AI agent.” Claude isn’t waiting for your next instruction — it’s working toward a defined outcome.
What /routines Does
/routines is 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.
Syntax
/routines add <routine-name> --schedule "<cron or natural language>" --task "<what to do>"
Example:
/routines add daily-lint-check \
--schedule "every day at 7am" \
--task "Run lint on all modified files in /src and write a summary to logs/lint-report.md"
You can list active routines with /routines list and remove them with /routines remove <routine-name>.
What Makes a Good Routine Definition
A routine task description should be self-contained. Since Claude won’t have a conversation to refer back to, the task string needs to include:
- What to operate on (which files, directories, APIs, or services)
- What action to take
- Where to put the output
- What “done” looks like
Vague task descriptions like “check the code” produce unreliable results. Specific ones like “run npm test and append the pass/fail summary to logs/test-history.md with today’s date” give Claude enough to work with.
Combining /goal and /routines for Autonomous Workflows
Used separately, these commands are useful. Used together, they form a proper autonomous workflow loop.
Here’s the pattern:
- Set a
/goal— the persistent end state you want to maintain - Define
/routines— the recurring tasks that work toward or verify that goal - Set completion conditions — explicit criteria so Claude knows when each run is finished
A Practical Example: Automated Code Quality Monitoring
Suppose you want Claude to check your codebase every morning, fix auto-fixable issues, and flag anything it can’t fix.
Step 1: Set the goal
/goal The /src directory has zero fixable lint errors.
All non-auto-fixable issues are logged to
logs/manual-review.md with file path and line number.
Step 2: Add the routine
/routines add morning-quality-check \
--schedule "weekdays at 8am" \
--task "Run eslint --fix on /src. Log any remaining errors
that cannot be auto-fixed to logs/manual-review.md.
Append a completion summary to logs/quality-log.md
with timestamp and counts."
Step 3: Define the completion condition explicitly
This 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.
Add this to your task description:
The routine is complete when: (a) eslint --fix has run on all
.ts and .tsx files, (b) any remaining errors are written to
logs/manual-review.md, and (c) the summary line has been
appended to logs/quality-log.md. Do not retry errors that
eslint cannot fix automatically.
Now Claude has a clear exit condition. It finishes the run, writes the output, and stops — rather than looping indefinitely on unresolvable errors.
Setting Completion Conditions That Actually Work
The 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.
Why Agents Stop Early
Claude Code will stop a routine mid-run if it encounters:
- An ambiguous state with no clear next action
- A step that requires human confirmation (by default)
- An error it wasn’t told how to handle
- No visible progress after several attempts
Each of these can be addressed with explicit instructions.
Pattern 1: Define the Output Artifact
The clearest completion condition is a file that either exists or doesn’t.
The routine is complete when logs/2024-01-15-report.md exists
and contains at least a summary section.
Claude can check this condition deterministically. It either created the file or it didn’t.
Pattern 2: Define Exit Conditions for Each Error Type
Tell Claude explicitly what to do when something goes wrong:
If a file fails linting and cannot be auto-fixed:
- Log it to logs/manual-review.md and continue
- Do NOT stop the run
- Do NOT ask for confirmation
If the test suite fails:
- Log the failure output to logs/test-failures.md
- Mark the run as failed in logs/quality-log.md
- Stop the routine for today
This prevents Claude from pausing to ask you a question at 3 AM when it hits an unexpected state.
Pattern 3: Set a Maximum Retry Count
For tasks that involve retries (API calls, build steps), set an explicit ceiling:
Retry failed steps up to 3 times. After 3 failures,
log the error and continue to the next file.
Without this, Claude may retry indefinitely or give up after one failure depending on how it interprets the situation.
Pattern 4: Use a Done Marker
For longer workflows with multiple steps, have Claude write a marker file when everything completes:
When all steps are complete, write "DONE" to .routine-status/morning-check-complete.
You can check this file externally to confirm the routine actually finished.
Advanced Patterns for Scheduled Workflows
Once you have the basics working, a few patterns make autonomous workflows significantly more reliable.
Chaining Routines
You can set up routines that depend on each other by using the output of one as the input for the next.
/routines add generate-changelog \
--schedule "every Friday at 5pm" \
--task "Read logs/quality-log.md from this week.
Summarize key issues and resolutions.
Write to CHANGELOG-draft.md."
/routines add review-changelog \
--schedule "every Friday at 5:30pm" \
--task "Read CHANGELOG-draft.md. Check for completeness.
If summary is at least 100 words and covers all
log entries, rename it to CHANGELOG.md.
Otherwise log 'incomplete' to changelog-errors.log."
The 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.
Using /goal Across Multiple Sessions
By default, /goal persists 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.
Create a file called AGENT_GOAL.md in your project root:
# Current Agent Goal
Maintain zero fixable lint errors in /src.
All open GitHub issues labeled "bug" should have
at least a triage comment within 24 hours of creation.
Seven tools to build an app. Or just Remy.
Editor, preview, AI agents, deploy — all in one tab. Nothing to install.
Then reference it in your routine:
/routines add load-goal \
--schedule "on session start" \
--task "Read AGENT_GOAL.md and set it as the active goal
for this session."
This keeps Claude aligned with your project’s objectives even when sessions restart.
Parameterized Routines
If you’re running similar routines across multiple directories or services, parameterize them:
/routines add check-service \
--schedule "every hour" \
--task "For each directory in /services:
run health check, log status to
logs/{service-name}-health.log.
Done when all directories have been checked."
Claude will iterate through the directories and produce per-service logs without you writing separate routines for each one.
Common Mistakes and How to Fix Them
Mistake 1: Imperative Goals Instead of State Goals
Wrong:
/goal Fix all the bugs in the codebase.
Right:
/goal The test suite passes with 0 failures and 0 errors.
All files in /src compile without TypeScript errors.
The second version is verifiable. Claude can check whether the conditions are met.
Mistake 2: Task Descriptions Without Scope
Wrong:
--task "Clean up the code"
Right:
--task "Run prettier on all .ts files in /src/components.
Stage the changes. Do not commit.
Write a list of modified files to logs/format-changes.md."
Scope prevents Claude from doing too much (refactoring unrelated files) or too little (touching one file and stopping).
Mistake 3: No Error Handling Instructions
If 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.
Always include:
- What to do on failure
- Whether to continue or stop
- Where to log the error
Mistake 4: Overlapping Routines
If two routines operate on the same files at overlapping times, they’ll conflict. Either stagger the schedules or use a lock file:
Before starting: check if .routine-lock exists.
If it does, wait 5 minutes and check again.
If not, create .routine-lock.
Delete .routine-lock when done.
Where MindStudio Fits for Teams Who Want More
Claude Code with /goal and /routines is 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.
If you’re building autonomous workflows that need to run in the cloud, trigger on external events, or interact with business tools, MindStudio handles a lot of that infrastructure for you.
MindStudio’s autonomous background 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.
For 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.
Built like a system. Not vibe-coded.
Remy manages the project — every layer architected, not stitched together at the last second.
You can try MindStudio free at mindstudio.ai — no credit card required, and the scheduled agent setup takes under an hour.
Real-World Use Cases
Here are some workflows that work well with /goal + /routines:
Daily Documentation Sync
/goal /docs accurately reflects the current API surface
in /src/api. All public functions have docstrings.
README is current.
/routines add doc-sync --schedule "every day at 9am" \
--task "Compare function signatures in /src/api against
/docs. Update any outdated entries.
Add missing docstrings.
Write change summary to logs/doc-updates.md.
Done when all functions match their documentation."
Dependency Security Checks
/routines add security-audit --schedule "every Monday at 6am" \
--task "Run npm audit. If vulnerabilities found,
write report to logs/security-{date}.md.
If critical vulnerabilities exist,
write CRITICAL to security-alert.txt.
Done when audit has run and output is logged."
Test Coverage Monitoring
/goal Test coverage for /src/core stays above 80%.
/routines add coverage-check --schedule "after each push" \
--task "Run jest --coverage.
If coverage drops below 80% for any file in /src/core,
log the file and current coverage to logs/coverage-drop.md.
Write overall coverage percentage to
logs/coverage-history.md with timestamp."
Frequently Asked Questions
Does /goal persist across Claude Code sessions?
By default, /goal is 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) and reference it in a startup routine. Some teams also store goals in a .claude/config file for automatic loading.
How do I prevent a routine from running if the previous run didn’t complete?
Use a lock file pattern. At the start of the routine task, instruct Claude to check for a .routine-lock file. 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.
Can /routines trigger on events rather than just schedules?
Claude Code’s native /routines supports 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.
What happens if Claude hits an error during a routine and I’m not at my computer?
Without 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.
How specific do completion conditions need to be?
As 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.
Can I run multiple goals simultaneously?
Claude Code supports one active /goal per 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.
Key Takeaways
/goalsets a persistent end state that Claude works toward across multi-step tasks — write it as a verifiable condition, not a command./routinesschedules 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.
- Handle errors explicitly in your task descriptions: what to do on failure, whether to continue or stop, and where to log.
- For cloud-based scheduled agents that integrate with business tools and work for non-technical teams, MindStudio extends what Claude Code handles locally.

