-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add /loop command for periodic task execution #2638
Copy link
Copy link
Open
Description
Summary
Add a /loop slash command that periodically executes a given prompt or slash command at a fixed interval, enabling hands-off monitoring and automation workflows.
Motivation
Developers frequently need to repeat the same action at regular intervals — watching a CI pipeline, polling deployment status, periodically reviewing incoming PRs. Currently this requires manually re-entering the same prompt each time.
Relation to hooks: The existing hooks system triggers actions in response to events (tool calls, session lifecycle).
/loopcomplements this by enabling time-based periodic execution, which hooks cannot do.
Proposed Syntax
/loop [interval] <prompt or /command>
/loop status # show running loops
/loop stop [id] # stop a specific loop, or all if no id
- interval (optional): Duration such as
30s,5m,1h. Default:10m. - prompt: Any text prompt or slash command to execute each cycle.
Examples
/loop 5m check if CI pipeline has passed for current branch
/loop 10m /review-pr 2525
/loop 1h summarize new commits on main since last check
/loop 30s is the dev server healthy?
/loop status
/loop stop
/loop stop 2Behavior Design
Core Loop
- Execute the prompt immediately on first invocation, then repeat at the specified interval
- Each iteration should be clearly delimited in output (timestamp + iteration count)
- Only one loop runs at a time (simplifies UX; multi-loop support can be a follow-up)
Stopping
- User interrupt: Ctrl+C or Escape stops the loop
- Explicit command:
/loop stop - Max iterations: Optional — e.g.,
/loop 5m --max 12 check CI(auto-stop after 12 cycles)
Context Management
- Each iteration starts with a fresh context to avoid context window exhaustion during long-running loops
- Sharing context across iterations can be considered as a follow-up
Error Handling
- If a single iteration fails, log the error and continue to the next cycle
- After 3 consecutive failures, warn the user and pause
User Interaction
- While a loop is running, the user should still be able to type and interact normally
- Loop output should be visually distinguished from interactive output (e.g., separator with timestamp, or collapsible sections in WebUI)
Safety
- Loop iterations respect the current approval mode — destructive actions still require confirmation unless in YOLO mode
- Show estimated token cost per iteration after the first run, so users can decide whether to continue
- Minimum interval floor (e.g., 10s) to prevent accidental API abuse
Use Cases
| Scenario | Command |
|---|---|
| Monitor CI pipeline | /loop 5m check if CI passed on current branch |
| Watch deployment | /loop 2m is the staging deployment healthy? |
| Review incoming PRs | /loop 30m /review-pr |
| Track build output | /loop 1m check for new build errors in logs |
| Periodic git sync check | /loop 1h are there new commits on main I should rebase onto? |
Implementation Considerations
- Register
/loopand sub-commands (status,stop) inBuiltinCommandLoader - Parse interval with
s/m/hsuffix support - Run iterations as independent prompt submissions with isolated context
- Loop manager service to track active loop state (start/stop/status)
- Both CLI (Ink) and WebUI should be supported
- Use existing i18n infrastructure for status messages
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels