Backend routine

A .ts routine that runs as a background process — on schedule or on demand.

Routine
Create in Cowork
Cowork Studio

$ cowork routine run task-archiver

reading tasks.json… 14 tasks

archiving 5 completed > 7 days

✓ done — archived: 5

A headless routine: registered in .cowork/project.json#routines and run in a Bun subprocess with the full runtime — fetch, node:fs, ctx.secrets, ctx.db. Run it from the CLI, from an app via cowork.routines.run, or on a schedule.

Use this shape for maintenance and automation — cleanups, backups, syncs, reports. In Cowork: Create → Routine → Backend routine.

Create it

This template is built into Cowork Studio's Create dialog. Open Manage Workspace, pick the matching tab, click its Add button and choose Backend routine — name it, and the files land in your workspace ready to edit.

Code

// Cowork/Routines/my-routine.ts
export default async (args, ctx) => {
  ctx.log('My Routine started', { args })
  // Do the work here — call an API, read files, write a table…
  return { ok: true, startedAt: new Date().toISOString() }
}