Skip to Content
caffeine docs

Automation

Schedules, gates, keychain secrets, budget, hooks, stats and gc.

How caffeine runs on its own: schedules, gates that skip runs with nothing to do, secrets for runs without a shell, spending caps, and hooks that tell you how it went.

Schedules

Declare them in workspace.yaml, next to the targets:

schedules:
  - { pipeline: news-watch, targets: [my-blog], at: "mon 07:00" }
  - { pipeline: maintenance-rust, at: "daily 03:30" }             # no targets: --all
  - { pipeline: upstream-compat, at: "every 6h", dry_run: true }
FieldMeaning
pipelineThe pipeline to run.
targetsTarget names. Empty or missing: every target that lists the pipeline (--all).
atdaily HH:MM, weekdays HH:MM, weekends HH:MM, mon,thu HH:MM (any days, sun…sat), hourly, every 15m, every 6h (5 minutes at least).
dry_runRun with --dry-run.
caffeine schedule list               # what is declared, and whether it is installed (● / ○)
caffeine schedule install            # write and load the macOS LaunchAgents
caffeine schedule remove             # unload and delete them all
caffeine schedule cron               # crontab lines instead, for Linux or cron lovers

install writes one LaunchAgent per schedule in ~/Library/LaunchAgents (dev.caffeine.<pipeline>.<targets>.plist) and loads it with launchctl. It also removes the caffeine LaunchAgents that are no longer in workspace.yaml. Run it again after every change to schedules:. --no-load writes the files without loading them.

Each scheduled run:

  • runs caffeinate -i caffeine run … --plain, so the Mac does not fall asleep in the middle of it;
  • gets the PATH you had when you ran install, so cargo, gh and claude are found;
  • logs to ~/.caffeine/logs/<pipeline>.<targets>.log, on top of the usual run logs.

A run that was due while the Mac slept starts when it wakes up. To wake the Mac on time, use sudo pmset repeat wakeorpoweron MTWRFSU 06:55:00 (once, outside caffeine).

Credentials for scheduled runs

A LaunchAgent has no shell, so nothing from your .zshrc is set. Two things to check:

  • Claude Code login. The claude CLI uses your login from the macOS keychain, which LaunchAgents can read. If a scheduled run says "Not logged in", create a long-lived token with claude setup-token and store it as CLAUDE_CODE_OAUTH_TOKEN (below).
  • API key roles (auth: api_key, see Runners): store the Console key in the keychain and list its variable in keychain_env, like the other secrets below.
  • Other secrets (MCP tokens, API keys): store them in the keychain and list them in config.yaml:
caffeine secret set MONITORING_MCP_TOKEN      # you are prompted: the value never shows in history or ps
caffeine secret delete MONITORING_MCP_TOKEN
# config.yaml
keychain_env: [CLAUDE_CODE_OAUTH_TOKEN, MONITORING_MCP_TOKEN]

At the start of caffeine run and caffeine approve, every variable of keychain_env that is not already set is read from the keychain (service caffeine, account = the variable name). A variable that is set in the environment wins. A missing entry prints a warning and the run goes on.

Gates: don't pay for nothing

Put a gate first. It exits 78 when there is nothing to do, which stops the pipeline as a success and costs nothing.

GateGoes on when
caffeine gate changed <url>The page's content changed since the last successful run.
caffeine gate changed --cmd "<command>"The command's output changed.
caffeine gate release <owner/repo>The repo has a new latest GitHub release. The tag is written to .agent/RELEASE.txt.
caffeine gate cargocargo update would change the lockfile, or cargo audit reports an advisory.
caffeine gate npmnpm outdated lists a package, or npm audit finds a vulnerability.
steps:
  - name: 01-gate
    run: caffeine gate release org/project
  - name: 02-implement
    prompt: prompts/upstream/implement.md      # reads .agent/RELEASE.txt

changed and release remember what they saw per target and pipeline, in state.json. The new value is only recorded when the whole run succeeds and is not a dry run. A run that fails is tried again next time, on the same news. --key <name> names what is remembered, when one pipeline has several gates.

release uses gh when it is installed (no rate limit with your login), and the public GitHub API otherwise.

Budget

# config.yaml
budget:
  daily_usd: 5
  monthly_usd: 60

Before a run, and before each target starts, caffeine adds up the cost of the runs of the day (or the month) from their summaries. When a cap is reached, the run is refused with the amount spent. Costs come from the claude runner; llm and cmd steps count as 0. Per step, max_budget_usd in a pipeline still caps each claude agent.

Hooks

# config.yaml
hooks:
  on_finish: 'osascript -e "display notification \"$CAFFEINE_PIPELINE: ok=$CAFFEINE_OK, inbox=$CAFFEINE_INBOX\" with title \"caffeine\""'
  on_failure: 'curl -s -d "caffeine: $CAFFEINE_PIPELINE failed ($CAFFEINE_FAILED target(s))" ntfy.sh/my-private-topic'

on_finish runs after every run, on_failure too when a target failed. They run in the home folder, for 60 seconds at most, and their own failure never fails the run. Their environment:

VariableValue
CAFFEINE_PIPELINEPipeline name.
CAFFEINE_OK1 when every target succeeded, 0 otherwise.
CAFFEINE_TARGETS, CAFFEINE_FAILEDHow many targets ran, and failed.
CAFFEINE_COST_USDCost of the run.
CAFFEINE_INBOXHow many inbox items the run created.
CAFFEINE_SUMMARIESPaths of the targets' summary.json, one per line.

caffeine sends nothing anywhere by itself: the hook is yours, and so is where it sends.

Stats

caffeine stats              # last 30 days
caffeine stats -d 7 --no-gh

Per pipeline: runs, ok, skipped, failed (or interrupted), cost, cost per useful run, average duration. Per model role: steps, cost, and the fallback rate (how often the role's work failed its check and a fallback role had to take over). With gh, what became of the pull requests: merged as is (a single commit), merged after edits, open, closed.

The fallback rate tells you whether a cheaper model is good enough for a step; the "merged as is" rate tells you whether a pipeline has earned auto-merge.

After a deploy: caffeine check deployed

When a pipeline merges (caffeine pr --auto-merge) and the merge deploys, check the production site afterwards:

  - name: 99-pr
    run: caffeine pr --auto-merge
  - name: 100-live
    run: caffeine check deployed https://example.com --contains "{{version}}" --wait 900

It requests the URL every --interval seconds (15) until it answers --status (200) and, with --contains, until the page contains that text: a version number or a build id tells the new version from the old one. Past --wait seconds (600), the step fails, and hooks.on_failure tells you. The site is broken and you know it within minutes, not when a visitor writes to you.

Feedback

Each time you edit, close or reject what a pipeline made, say why in one line:

caffeine feedback news-watch "the summary was in English"
caffeine feedback maintenance-rust --target my-site "bumped a crate the Dockerfile pins"
caffeine feedback                     # recent notes

caffeine reject <id> <reason> records its reason the same way. The notes go to ~/.caffeine/feedback.jsonl, and stats and digest group them per pipeline. A reason that comes back is a check to write, or a sentence to add to a prompt.

Digest

caffeine digest                       # the last 7 days, in Markdown
caffeine digest -d 1 --out ~/Desktop/caffeine-today.md

One page, built from the summaries, the inbox and the feedback (no model, so free and exact): totals and cost, what waits for a decision with the commands to decide, what failed and where its logs are, the pull requests, a table per pipeline, and the feedback that comes back. Schedule it and send it with a hook:

# pipelines/digest.yaml
steps:
  - name: digest
    run: caffeine digest --out .agent/REPORT.md

Housekeeping: caffeine gc

caffeine gc -n                        # what would go (dry run)
caffeine gc                           # runs older than 90 days
caffeine gc -d 30 --keep-summaries    # drop logs older than 30 days, keep each summary.json

It removes run folders older than --days, decided inbox items decided before then, clones and cache copies left in ~/.caffeine/app/ by a crash (older than a day), and locks whose process is gone. Pending inbox items and the state are never touched. With --keep-summaries, stats, runs and digest still see the old runs.

It also prunes the local cache (see Caches): entries not used (restored or saved) for cache.max_age_days, then the least recently used ones until the store fits in cache.max_gb. Without these keys in config.yaml, entries stay until you remove them. An S3 store is never pruned by gc: use the bucket's lifecycle rules. A memory kept on the store (memory_store: cache) is never pruned either. Saves cut short by a crash (older than an hour) are swept too. So are the containers of sandboxed runs whose caffeine process is gone (caffeine-…-<pid>, left by a second Ctrl-C or a crash), and the pods, Secrets and network policies that a dead caffeine of this install left in a kubernetes sandbox's namespace.

caffeine cache ls                                  # every entry: namespace, key, size, last use
caffeine cache rm deps                             # every entry of the pipeline `deps`
caffeine cache rm deps --target site --key linux-  # one target, one key

cache rm also drops the pipeline's share: target and share: global entries, for every pipeline that shares them. cache rm <pipeline> --memory drops its memory instead, with memory_store: cache.

On this page