Automation: Goals, Loops, Routines & Channels
Choose between goals, loops, scheduled tasks, routines, channels, and hooks when Claude Code should keep working without constant prompting.
The Automation Map
Claude Code has several ways to keep work moving without you typing every next prompt. They look similar from the outside, but they start the next action for different reasons.
| Mechanism | Starts when | Stops when | Scope |
|---|---|---|---|
/goal | Previous turn finishes | A model confirms the condition is met | Current session |
/loop or scheduled task | A time interval or cron time arrives | You stop it, it expires, or Claude decides it is done | Current session |
| Stop hook | Previous turn finishes | Your script or prompt decides | Settings scope |
| Channel | External event arrives | Event is handled | Running session |
| Routine | Schedule, API call, or GitHub event fires | Cloud run completes | Claude Code on the web |
Pick based on what should trigger the next turn.
/goal
Use /goal when there is a verifiable completion condition:
/goal migrate the auth module until npm test passes and no imports use the old session APIClaude keeps working across turns. After each turn, a small evaluator checks whether the goal is done. If not, Claude starts another turn.
Good goals are measurable:
- "all tests in package X pass"
- "no call sites import the old API"
- "every checklist item in this design doc is complete"
- "the issue backlog query returns zero open items"
Avoid goals that depend on taste or hidden human judgment.
/loop and Scheduled Tasks
Use /loop or scheduled tasks when time should trigger the next check:
/loop every 5 minutes check whether the deploy finished and summarize any failureUse this for polling deployments, watching a long-running CI job, or reminding yourself to revisit a task. Session-scoped scheduled tasks can come back when you resume the session, but they are not durable infrastructure.
Routines
Routines run on Claude Code on the web. They can trigger from:
- A recurring schedule.
- A one-off future time.
- An API call.
- GitHub events such as pull requests or releases.
Use routines when work should run even if your laptop is closed. Examples: nightly dependency review, weekly architecture drift report, or PR review automation.
Channels
Channels push external events into a running Claude Code session through MCP. They are useful when polling is the wrong model:
- CI fails and sends the failure to Claude.
- Monitoring fires an alert.
- A teammate sends a message that should become session context.
- A webhook delivers a state change.
Hooks push Claude events outward. Channels push external events inward.
Hooks as Automation Glue
Hooks are deterministic. Use them when a rule must run every time:
- Format after edits.
- Block writes to sensitive files.
- Send a notification when Claude stops.
- Create quality gates around agent-team tasks.
For long-running automation, hooks often pair with /goal or routines: the goal decides whether the work is complete; hooks enforce checks around each turn.
Decision Guide
| Need | Use |
|---|---|
| Keep working until a condition holds | /goal |
| Poll or remind inside one session | /loop or scheduled task |
| React to CI, alerts, or webhooks | Channels |
| Enforce policy around every tool call | Hooks |
| Run autonomously in the cloud | Routines |
| Orchestrate many agents in one repeatable run | Dynamic workflow |
Official References
Continue with practice
You have finished the core ideas of Automation: Goals, Loops, Routines & Channels.
If you want to turn the idea into something reusable, continue practicing on AgentWay.