Automation

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.

MechanismStarts whenStops whenScope
/goalPrevious turn finishesA model confirms the condition is metCurrent session
/loop or scheduled taskA time interval or cron time arrivesYou stop it, it expires, or Claude decides it is doneCurrent session
Stop hookPrevious turn finishesYour script or prompt decidesSettings scope
ChannelExternal event arrivesEvent is handledRunning session
RoutineSchedule, API call, or GitHub event firesCloud run completesClaude Code on the web

Pick based on what should trigger the next turn.

/goal

Use /goal when there is a verifiable completion condition:

text
/goal migrate the auth module until npm test passes and no imports use the old session API

Claude 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:

text
/loop every 5 minutes check whether the deploy finished and summarize any failure

Use 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

NeedUse
Keep working until a condition holds/goal
Poll or remind inside one session/loop or scheduled task
React to CI, alerts, or webhooksChannels
Enforce policy around every tool callHooks
Run autonomously in the cloudRoutines
Orchestrate many agents in one repeatable runDynamic 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.