---
name: loop
description: Create and manage scheduled tasks and heartbeats
commandType: local
---

# Loop Command

Create and manage scheduled tasks and heartbeats.

## Usage

```
/loop <subcommand> [options]
```

## Subcommands

### create <name> --cron <expression> [options]
Create a scheduled task or heartbeat.

### list
List all tasks.

### delete <id>
Delete a task.

### enable <id>
Enable a task.

### disable <id>
Disable a task.

### trigger <id>
Manually trigger a task.

## Options

| Option | Description |
|--------|-------------|
| --cron \<expr\> | Cron expression (required) |
| --type \<type\> | Task type: heartbeat (default) \| scheduled |
| --session \<name\> | Session name (heartbeat required) |
| --mode \<mode\> | Mode: session (default) \| fork |
| --prompt \<text\> | Prompt (scheduled required) |
| --agent-type \<type\> | Agent type (default: default) |
| --transport \<type\> | Transport: stdio (default) \| http \| websocket \| cli |
| --recurring | Recurring execution |
| --durable | Persistent storage |

## Cron Expression Format

```
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── weekday (0-6, 0=Sun)
│ │ │ │ │
* * * * *
```

## Examples

Create a heartbeat task:
```
/loop create main-heartbeat --cron "*/5 * * * *" --session main --type heartbeat
```

Create a scheduled task:
```
/loop create hourly-sync --cron "0 * * * *" --prompt "Sync data" --type scheduled
```

List all tasks:
```
/loop list
```

Delete a task:
```
/loop delete hb_xxx
```

Enable a task:
```
/loop enable st_xxx
```

Trigger a task:
```
/loop trigger hb_xxx
```

## Task Types

### Heartbeat
- Supports session and fork modes
- session mode: Uses specified session for execution
- fork mode: Forks a new session for execution
- Session must be specified

### Scheduled Task
- Executes via SubAgent
- No session concept (meaningless for remote/CLI)
- Can specify agent type and transport
- Default transport: stdio