AgentSkillsCN

scheduled-task

创建并管理定时任务,在指定时间自动执行Claude CLI。适用于用户提及“定时”“计划”“计时器”“Cron”“每天”“每小时”“定期”“提醒”“提示”,或希望周期性运行自动化任务的场景。支持Cron表达式、间隔调度以及一次性调度。

SKILL.md
--- frontmatter
name: scheduled-task
description: Create and manage scheduled tasks that execute Claude CLI at specified times. Use when user mentions "定时", "scheduled", "timer", "cron", "每天", "每小时", "定期", "remind", "提醒", or wants to run automated tasks periodically. Supports cron expressions, interval-based, and one-time scheduling.
license: Apache-2.0
metadata:
  author: ai-agent-toolkit
  version: "1.0.0"

Scheduled Task

Create, manage, and execute scheduled tasks using Claude CLI.

Quick Start

code
User Request → Parse Schedule → Generate Task MD → Register → Scheduler Executes → Notify

Create a Task

Parse the schedule type and generate task file:

bash
python scripts/create_task.py \
  --name "Daily Code Review" \
  --schedule "cron:0 9 * * *" \
  --working-dir "/path/to/project" \
  --prompt "Review code quality in src/ directory"

Schedule Types

TypeFormatExampleDescription
Croncron:exprcron:0 9 * * *Daily at 9am
Intervalinterval:Xuinterval:30mEvery 30 minutes
Onceonce:datetimeonce:2026-01-27 15:00One-time execution

Common Patterns

PatternSchedule
Every day at 9amcron:0 9 * * *
Every hourinterval:1h
Every 30 minutesinterval:30m
Weekdays at 8amcron:0 8 * * 1-5

Manage Tasks

bash
# List all tasks
python scripts/list_tasks.py

# Cancel a task
python scripts/cancel_task.py --id task-001

# Run a task manually
python scripts/run_task.py --id task-001

# Start the scheduler (background)
python scripts/scheduler.py --daemon

Directory Structure (Runtime)

code
.scheduled-tasks/
├── registry.json          # Task registry
├── tasks/                 # Task MD files
│   └── task-001.md
├── results/               # Execution results
│   └── task-001_2026-01-26_09-00.md
└── logs/
    └── scheduler.log

Script Reference

create_task.py

ParameterRequiredDescription
--nameYesTask name
--scheduleYesSchedule spec (cron:expr, interval:30m, once:datetime)
--promptYesTask instructions
--working-dirNoWorking directory (default: current)
--focus-filesNoFile patterns to focus on

scheduler.py

ParameterDescription
--daemonRun as background process
--onceCheck and run due tasks once, then exit
--intervalCheck interval in seconds (default: 60)

Cross-Platform Support

  • Windows: Native toast notifications via win10toast
  • macOS: osascript notifications
  • Linux: notify-send (libnotify)

Dependencies

bash
pip install -r scripts/requirements.txt

Error Handling

ErrorAction
Claude CLI not foundNotify user, log error
Task timeout (5min default)Kill process, mark failed, retry later
Invalid cron expressionReject at creation time

Reference Files