Instructions for AI coding agents working on this repository.
Claude Tasks is a Go application for scheduling and running Claude CLI tasks via cron expressions. It provides a terminal UI (TUI), a headless daemon mode, and an HTTP REST API with a companion React Native mobile app.
This is a fork of kylemclaren/claude-tasks with additional features: per-task model selection, permission mode control, session observability, structured logging, and cron-to-English descriptions, multi-process scheduler lease, environment diagnostics (doctor command), and preflight failure persistence.
# Install dependencies (Go modules)
go mod download
# Build
go build -o claude-tasks ./cmd/claude-tasks
# Run tests
go test -v ./...
# Lint
golangci-lint run --timeout=5mRequires Go 1.24+ and CGO_ENABLED=1 (the SQLite driver depends on CGO).
cmd/claude-tasks/main.go CLI entrypoint, routes subcommands
internal/
api/ REST API (chi router, JSON handlers, CORS middleware)
db/ SQLite database layer (models, CRUD, migrations, scheduler lease management)
doctor/ Environment diagnostics (claude binary, credentials, directories, DB, scheduler lease)
executor/ Claude CLI subprocess runner with dynamic flags, session IDs, usage gating
logger/ Structured JSON run logging per task
scheduler/ Cron scheduling (robfig/cron, 6-field with seconds)
tui/ Bubble Tea terminal UI (list, add, edit, run history, output, settings views)
upgrade/ Self-update from GitHub releases
usage/ Anthropic API usage tracking and threshold enforcement
version/ Build-time version info via ldflags
webhook/ Discord and Slack notification senders
mobile/ Expo/React Native mobile app
- Language: Go 1.24, no generics used currently
- Error handling: Wrap errors with
fmt.Errorf("context: %w", err)for unwrapping - Database: Raw SQL with
database/sql, no ORM. Parameterized queries only. - No global state: Dependencies injected via struct fields
- Package scope: Each internal package has one primary type/responsibility
- Testing: Standard
go test, no external test framework - Formatting:
gofmtstandard, enforced bygolangci-lint
- Cron uses 6-field format:
second minute hour day month weekday - Cron expressions are displayed as human-readable English in the TUI (via
lnquy/cron) - One-off tasks have empty
cron_exprand optionalscheduled_at; they auto-disable after running - Scheduler polls DB every 10 seconds to pick up external changes
- Executor enforces a 30-minute timeout per task
- Executor generates a UUID session ID per run and passes
--session-idto Claude CLI - Executor builds CLI flags dynamically based on task's
modelandpermission_modefields - Usage client reads
~/.claude/.credentials.jsonfor OAuth token - Executor fails task execution if usage threshold enforcement cannot be initialized or checked
- API auth is optional via
CLAUDE_TASKS_AUTH_TOKEN(Bearer token; health endpoint exempt) - CORS can be restricted to a single origin via
CLAUDE_TASKS_CORS_ORIGIN - API run endpoint concurrency is bounded by
CLAUDE_TASKS_API_RUN_CONCURRENCY(default 8;0disables) - Usage threshold enforcement can be bypassed with
CLAUDE_TASKS_DISABLE_USAGE_CHECK=1for non-Anthropic auth setups - Default data directory:
~/.claude-tasks/, overridable viaCLAUDE_TASKS_DATA - Structured JSON logs written to
~/.claude-tasks/logs/<task_id>/per run - Scheduler uses a DB-backed leadership lease (15s TTL, 5s renew interval) to ensure only one process executes tasks across multiple instances
claude-tasks doctorvalidates: claude binary on PATH, usage credentials, data/logs directory permissions, database writability, scheduler lease state- Preflight failures (missing credentials, usage threshold errors) create failed
task_runsrecords with structured log files — never silently dropped - TUI supports
--scheduler=auto|on|off; daemon and serve support--scheduler=true|false - Doctor exits non-zero on any critical failure (FAIL); warnings (WARN) are informational only
| Field | Values | CLI Flag |
|---|---|---|
model |
"", "opus", "sonnet", "haiku" |
--model <alias> |
permission_mode |
"bypassPermissions", "default", "acceptEdits", "plan" |
--dangerously-skip-permissions or --permission-mode <mode> |
Constants in internal/db/models.go:
var ModelAliases = []string{"", "opus", "sonnet", "haiku"}
var PermissionModes = []string{"bypassPermissions", "default", "acceptEdits", "plan"}
const DefaultPermissionMode = "bypassPermissions"GET /api/v1/health
GET /api/v1/tasks (response includes model, permission_mode)
POST /api/v1/tasks (request accepts model, permission_mode)
GET /api/v1/tasks/{id}
PUT /api/v1/tasks/{id}
DELETE /api/v1/tasks/{id}
POST /api/v1/tasks/{id}/toggle
POST /api/v1/tasks/{id}/run
GET /api/v1/tasks/{id}/runs (response includes session_id)
GET /api/v1/tasks/{id}/runs/{runID}
GET /api/v1/tasks/{id}/runs/latest
GET /api/v1/settings
PUT /api/v1/settings
GET /api/v1/usage
SQLite at ~/.claude-tasks/tasks.db. Four tables: tasks, task_runs, settings, scheduler_leases. Schema auto-migrates on startup. Foreign keys enabled via connection string.
Key columns: tasks.model, tasks.permission_mode, task_runs.session_id
Lease table: scheduler_leases (singleton row, tracks holder_id, lease_expires_at for leadership)
- Use parameterized SQL queries to prevent injection
- Wrap errors with context using
%wverb - Keep packages focused on a single concern
- Test with
go test -v ./...before submitting changes - Append new migrations (ALTER TABLE) rather than modifying existing ones
- Run
claude-tasks doctorto validate environment before testing - Ensure preflight failures create run records (never return errors silently)
- ORMs or query builders -- stick with raw SQL
- Global mutable state -- pass dependencies explicitly
- Importing from
internal/packages outside this module - Removing or changing existing migration SQL (append new migrations instead)
- Adding external dependencies for functionality achievable with stdlib (e.g., UUID uses
crypto/rand)