Skip to main content
skill CX Codex

encore-go-cron — Claude Code skill: scheduled jobs in Encore Go

Teaches the agent to declare recurring work in Encore Go with cron.NewJob. Useful when a job should run on a timer instead of a request.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add encoredev/skills --skill encore-go-cron -a claude-code
npx skills add encoredev/skills --skill go-cron -a claude-code
Open on GitHub

What encore-go-cron does

The skill covers wiring a schedule to an existing //encore:api endpoint. The cron.NewJob declaration lives as a package-level variable, never inside a function, and points at an endpoint defined earlier in the file.

Two schedule formats are documented. Every takes an interval such as "1h" or "30m", and that interval has to divide 24 hours evenly, so "7h" is rejected. Schedule takes a five-field cron expression, all times in UTC. A table of common expressions is included: "0 * * * *" hourly, "0 2 * * *" daily at 02:00 UTC, "0 0 * * 0" Sunday midnight.

Crons stay silent under encore run — only a deployed environment fires them, so local testing of a schedule tells you nothing. Mark the endpoint private or it can be called from outside. Keep the handler idempotent, since a job may fire late or repeat during a redeploy. When the background work is event-driven rather than time-driven, the same collection offers encore-go-pubsub.

What it helps with

  • declare a cron job in Encore Go without config mistakes
  • pick between an Every interval and a Schedule expression
  • convert local time to UTC for a schedule
  • keep the cron endpoint off the public API
  • make the handler safe to run twice

Example prompts for the agent

  • Add an hourly job that cleans up expired sessions with cron.NewJob
  • Schedule a daily aggregation at 02:00 UTC in Encore Go
  • Why doesn't my cron fire under encore run?

How to install encore-go-cron

1Skills CLI (Vercel)

npx skills add encoredev/skills --skill encore-go-cron -a claude-code
npx skills add encoredev/skills --skill go-cron -a claude-code

2Manually: put the files in place

~/.claude/skills/go-cron/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/go-cron/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about encore-go-cron

How do I install encore-go-cron in Claude Code?

Run npx skills add encoredev/skills --skill encore-go-cron -a claude-code. The skill file then lands at ~/.claude/skills/go-cron/SKILL.md.

What does encore-go-cron do?

It shows the agent how to declare recurring jobs in Encore Go using cron.NewJob from encore.dev/cron, and explains both schedule formats.

Why does my cron job never run locally?

encore run does not execute crons; only a deployed environment does. You have to check the schedule after deploying.

Source text

SKILL.md · Apache-2.0
---
name: encore-go-cron
description: >-
  Schedule periodic / recurring work in Encore Go using `cron.NewJob` from `encore.dev/cron`. Covers `Every: "1h"` interval syntax and `Schedule: "0 9 * * 1"` cron expressions.
when_to_use: >-
  User wants to run a Go job on a schedule — anything with the words schedule, scheduled, daily, hourly, weekly, periodic, recurring, every N minutes/hours, "at HH:MM UTC", midnight, batch job, aggregation job, nightly, cleanup job, or background work that runs on a timer rather than in response to a request. Trigger phrases: "every day at 02:00 UTC", "daily aggregation", "run hourly", "scheduled task", "cron", "nightly cleanup", "on a schedule".
---

# Encore Go Cron Jobs

## Instructions

A `cron.NewJob` declaration in Encore Go ties a schedule to an existing `//encore:api` endpoint. The endpoint runs at the chosen cadence. Declare the job as a package-level variable — not inside a function.

```go
package cleanup

import (
    "context"
    "encore.dev/cron"
)

// 1. The endpoint to call (typically private: //encore:api private)
//encore:api private
func CleanupExpiredSessions(ctx context.Context) error {
    // Cleanup logic
    return nil
}

// 2. Package-level cron declaration
var _ = cron.NewJob("cleanup-sessions", cron.JobConfig{
    Title:    "Clean up expired sessions",
    Schedule: "0 * * * *", // Every hour
    Endpoint: CleanupExpiredSessions,
})
```

## Schedule Formats

| Field | Example | Description |
|---|---|---|
| `Every` | `"1h"`, `"30m"`, `"6h"` | Simple interval. **Must divide 24h evenly** — `"7h"` is invalid. |
| `Schedule` | `"0 9 * * 1"` | Standard cron expression (5 fields, UTC). |

### Common cron expressions

| Cron | Meaning |
|---|---|
| `"0 * * * *"` | Every hour, on the hour |
| `"0 2 * * *"` | Daily at 02:00 UTC |
| `"0 0 * * 0"` | Weekly on Sunday at midnight UTC |
| `"0 4 15 * *"` | 04:00 UTC on the 15th of each month |

## Important behaviour

- **Cron jobs do not execute when running locally with `encore run`.** Only deployed environments fire crons.
- The cron endpoint should be `private` so it can't be triggered externally — only the cron scheduler should call it.
- All times in `Schedule` are UTC. Convert from local time when designing the schedule.
- The endpoint must be defined at module load — declare it before the `cron.NewJob` reference.

## Guidelines

- Use `Every` for "run on a regular interval" (must divide 24h).
- Use `Schedule` for specific times of day or days of week.
- Keep endpoint logic idempotent: a cron may fire late or be retried in a redeploy window.
- For event-driven background work (not time-driven), use the `encore-go-pubsub` skill instead.

© encoredev · Apache-2.0 · encoredev/skills

Similar skills

All skills for Backend and APIs →

From the same set25

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor