Backend Routine Example

A headless routine — pure backend logic, no UI at all.

Routine
Cowork Studio

$ cowork routine run task-archiver

reading tasks.json… 14 tasks

archiving 5 completed > 7 days

✓ done — archived: 5

A .ts routine with no frontend: it moves tasks completed more than 7 days ago from tasks.json into archive.json. Run it on demand or on a schedule.

Use this shape for maintenance and automation — cleanups, backups, scheduled jobs.

Installation

cowork template install tasks-archiver

Code

// Cowork/Routines/task-archiver.ts
const WEEK = 7 * 24 * 60 * 60 * 1000;
export default async function run({ files, now }) {
  const tasks = await files.readJson('tasks.json');
  const old = tasks.filter((t) => t.done && now - t.doneAt > WEEK);
  const keep = tasks.filter((t) => !old.includes(t));
  const archive = await files.readJson('archive.json', []);
  await files.writeJson('archive.json', [...archive, ...old]);
  await files.writeJson('tasks.json', keep);
  return { archived: old.length };
}