Skip to main content

whenthen

When a condition holds, then run a task: a light scheduler for commands, made to be driven by AI agents.

pip install whenthen
whenthen add backup --command "rsync -a /home/me/notes /backup/notes" --times 03:00 --dry-run
backup: runs `/usr/bin/rsync -a /home/me/notes /backup/notes` at 03:00 every day (Europe/Paris); next Thu 3 Dec 2026 03:00 CET (in 15h 52m), then Fri 4 Dec 2026 03:00 CET, Sat 5 Dec 2026 03:00 CET.

Drop --dry-run and the job is stored, and one entry is added to your machine's own scheduler (a crontab line; on macOS a launchd agent). That entry, the clock, runs whenthen tick every minute; the tick works out what is due and runs it. Jobs are small JSON records, not cron lines, so things cron cannot do work anyway:

whenthen add check-build --command "curl -fsS https://example.com/build" --in 10h   # once
whenthen add poll --command "curl -fsS https://example.com/health" --every 90m     # any interval
whenthen add report --script "weekly-report" --times 09:00 --weekdays mon          # a stored script
whenthen status                                                                    # is everything running?

A laptop that was asleep runs what it missed, once, when it wakes.

Made for agents

A person rarely types these commands. An agent reads "update my feeds every weekday at six", emits typed flags, and whenthen checks them and answers with the sentence above, which the agent reads back. The command never parses English, and never stores a cron expression: models get schedules wrong often enough (research) that a deterministic check and a plain read-back sit between the sentence and the schedule.

Two things ship for Claude Code and are linked into ~/.claude by one command:

whenthen install-skills
  • the whenthen skill: English to flags, which tool to use when it is not this one, the dry-run and read-back procedure, what needs a person's yes;
  • the whenthen-keeper agent: sets up several jobs, writes the script when a task is more than one command, audits the schedule, finds out why a job did not run, and returns a short JSON report.

Every command prints JSON.

What to run

Form Flag Notes
one program with arguments --command "prog arg" no shell syntax; the program's full path is resolved and stored when you add the job
a stored script --script "name arg" store it first: whenthen script-put name --from file
a Python function --call pkg.module:function --param k=v runs under the interpreter that added the job
a named recurring request --intent key --param k=v from the vocabulary, below

Secrets do not go in any of these (they would be stored in the job). Name a file of NAME=value lines with --env-file; it is read when the job runs.

A job runs the script it was added with and no other: the script's hash is stored with the job, and a script changed afterwards is not run until the job is added again with --replace. A run started by whenthen cannot add or change jobs, scripts, the vocabulary or the clock.

When to run it

Flag Meaning
--in 10h once, a duration from now (90s, 20m, 1h30m, 2d, 1w)
--at 2026-12-03T07:00 or --at 15:00 once, at that time (a bare time means the next time it is that time)
--every 90m repeatedly, at any interval of a minute or more
--times 07:00,19:00 with --weekdays mon-fri, --days 1,15, --months jun-aug on a calendar rule
--cron "0 6 * * 1-6" a five-field cron expression, converted to the calendar form
--tz Europe/Paris the zone for wall-clock times (default: the machine's, stored by name when the job is added)
--on-event build-finished no time: the job runs when another program says so (below)

A rule whenthen cannot honour exactly is refused with the reason, not approximated. On the days clocks change, a daily job runs once and an hourly one runs every hour.

A job added with --on-event waits for a program that already knows the moment: a build script, a git hook, a shortcut on a phone. That program calls whenthen fire <job> --occurrence <id>, with an id unique to the event; the same id never runs twice.

Policy: --timeout 30m stops a long run and everything it started; --grace 1h skips an occurrence that would start later than that (default: run it once, however late); --overlap allow lets a run start while the previous one is going (default: skip and record it); --delay 20s makes each run wait that long before it starts, so that several jobs due in the same minute do not all start in the same second.

Looking after jobs

whenthen ls                 # every job: when, next, last run
whenthen show <name>        # the full record and its latest runs
whenthen run <name>         # run it now, exactly as the clock would
whenthen runs <name>        # history
whenthen log <name>         # the end of the latest run's log
whenthen pause <name>       # resume <name>, rm <name>
whenthen clock              # what wakes the tick: status | install | remove (--clock cron | launchd)

whenthen status reports the things that go wrong silently: a clock that stopped ticking, a job that keeps failing, a job that is overdue, an occurrence skipped as too late or whose run never started, a job record that cannot be read.

A job record and the JSON these commands print hold the machine's name, absolute paths and the stored request. Quote the echo line in a bug report, not the raw output.

The vocabulary

Name a request once, use it by name afterwards:

whenthen intent-add backup-notes \
  --command "{python} -m mynotes backup {target?}" \
  --phrase "back up my notes" "save my notes"
whenthen add nightly-backup --intent backup-notes --times 02:00

{name} is a required parameter, an argument that is exactly {name?} an optional one, {python} the interpreter running whenthen. A package can contribute its own entry as a JSON document: whenthen intent-add --from entry.json.

From Python

import whenthen

result = whenthen.add("poll", command="curl -fsS https://example.com/health", every="90m", dry_run=True)
print(result["echo"])
whenthen.status()

The verbs are plain functions (whenthen.tools.verbs, each importable from whenthen); the command line is generated from them. Everything whenthen raises on purpose is a whenthen.WhenthenError.

How it is built, and where it grows

A job is (trigger, task, policy). One function, fire(job, occurrence), runs a task: it refuses an occurrence it has already seen, applies the overlap rule and the time limit, and writes a run record. The tick asks each job's trigger one question, "is an occurrence due, and under which key?", and knows nothing about times. The places made to be extended:

Seam Default Could be
triggers.KINDS: a kind of trigger and its answer to the tick at, every, calendar, event a condition polled each minute, recurrence rules
clock= (an object, or a name in clocks.CLOCKS) launchd on macOS (one agent file), cron elsewhere (one crontab line) a systemd user timer
fire <job> --occurrence <key>, from any program the tick a webhook, a file watcher, a phone reporting a named place
root= the data directory: ~/.local/share/whenthen/ (or $WHENTHEN_DATA_DIR) another directory
spawn= on tick a detached process on this machine a Python program that embeds the tick

Conditions that whenthen itself watches (a state, a place) are the next phase: each is one more entry in KINDS.

The reasoning is in the decision record; the evidence in the research.

A package that installs its own launchd agent, systemd timer or crontab line can hand that schedule over: how.

Limits

  • Times are honoured to the minute, and only while the machine is awake.
  • Jobs run on the machine where they were added.
  • Two data roots on one machine each get their own clock entry.
  • The guards (a run cannot reschedule; a job is bound to its script) protect against accidents and careless agents. They are not a security boundary: anything running as the same user can edit the records.
  • The clock is launchd on macOS and cron on Linux. The cron clock also works on macOS (whenthen clock install --clock cron), but a job it starts there cannot read the login Keychain, so gh and other tools that keep a token in it fail; that is why it is not the default. Installing one clock removes the other.
  • Nothing reports a failure unasked: ask whenthen status.
  • Requires Python 3.10 or later. One dependency: cw, which generates the command line.

Metadata

Release files for whenthen 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whenthen 0.0.6
File Size Uploaded Provenance Actions
whenthen-0.0.6.tar.gz 134.1 kB Without provenance Details for whenthen-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for whenthen 0.0.6
File Interpreter ABI Platform Actions
whenthen-0.0.6-py3-none-any.whl Python 3 none any Details for whenthen-0.0.6-py3-none-any.whl

Total release size: 201.7 kB

Release files / whenthen-0.0.6.tar.gz

Download URL whenthen-0.0.6.tar.gz
Size 134.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5b82a69f0810ff74e4ca726d3de084c7c69c4ad675a4d4685e6c7e495d7a3659
BLAKE2b-256 checksum
How to use checksums
84ab3562c19188a9be300d4de06aa24ae215d549697aa257b654cbb50d4ac15a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.12 {"installer":{"name":"uv","version":"0.13.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / whenthen-0.0.6-py3-none-any.whl

Download URL whenthen-0.0.6-py3-none-any.whl
Size 67.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
070b5c763aec659b50a9656971e069f74bc5e4e7af8ee488457fe4bb48ca63eb
BLAKE2b-256 checksum
How to use checksums
c3d1f191cc1f1d672a7aac09055e5f9a3e970c3e1aa98b55909be0dc92db6816
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.12 {"installer":{"name":"uv","version":"0.13.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for whenthen 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page