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.

whenthen status --exit-code exits with status 1 when something is wrong, so another program can check with one call.

Being told when a job keeps failing

Set one command for the installation, and whenthen runs it once when a job has failed three runs in a row, once when that job next succeeds, and once if the job is removed while failing:

whenthen on-failure --command "notify-send 'a scheduled job is failing'"   # any program
whenthen on-failure --command "{python} -m whenthen.github_issue"          # one issue per failing job
whenthen on-failure                 # what is set, and the reports that are open
whenthen on-failure --off

The command reads what happened from its environment: WHENTHEN_EVENT (failing, recovered, removed), WHENTHEN_JOB, WHENTHEN_STATUS, WHENTHEN_STREAK, WHENTHEN_SINCE, WHENTHEN_LAST_LINE, WHENTHEN_WHEN, WHENTHEN_OWNER_REPO. {python} in the command stands for the interpreter whenthen runs in. --streak 5 changes the number for every job; --on-failure-streak N on whenthen add changes it for one (0: never report this job; 20 at most). A job that runs once (--at, --in) is reported at its first failure. A paused job is not newly reported. An open report stays open while its job is paused. A job that works again before any report about it was started is not reported at all. When the command is first set, jobs already failing are reported, except a one-off that has already run.

A report whose command fails is tried again ten minutes later (longer when the report's own --timeout is longer), five times in all, and whenthen status says it could not be delivered. whenthen report <job> --event failing runs the command by hand as a trial: the command gets WHENTHEN_TRIAL=1, and a command of your own that ignores it acts for real.

whenthen.github_issue ships with the package. It opens one issue per failing job in the repository the job names (whenthen add ... --owner-repo owner/name, else its own --repo owner/name), adds a comment when the job fails again while the issue is open, and closes the issue when the job succeeds or is removed. It needs gh, signed in. It writes the job's name, schedule, status and number of failed runs, and a random id of the installation in a hidden marker; never the command line, a path or the machine's name. The last line of the job's log is added only when GitHub says the repository is private, and --if-public owner/name sends the report for a public repository to another one instead. On a trial it writes nothing and prints what it would do.

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.
  • A failure is reported unasked only once an on-failure command is set, and only while the clock ticks: a clock that stopped can report nothing, so something outside has to notice that (whenthen status --exit-code from another machine's check is one way).
  • Requires Python 3.10 or later. One dependency: cw, which generates the command line.

Metadata

Release files for whenthen 0.0.7

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.7
File Size Uploaded Provenance Actions
whenthen-0.0.7.tar.gz 157.9 kB Without provenance Details for whenthen-0.0.7.tar.gz

Built distribution (wheel)

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

Total release size: 241.9 kB

Release files / whenthen-0.0.7.tar.gz

Download URL whenthen-0.0.7.tar.gz
Size 157.9 kB
Tags Source
SHA-256 checksum
How to use checksums
852d9e9b79d1035f2a94c1fe1b842ebdbb596746e9b7b0c248077c1ac1b3c470
BLAKE2b-256 checksum
How to use checksums
fb711aaec671ca91606b82151cadc2114e91f509c4402cecaac7e8f1bb731543
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.7-py3-none-any.whl

Download URL whenthen-0.0.7-py3-none-any.whl
Size 84.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7dc5da6365f0c62c614f3f005f6499c34cf7a444132db07159ebdf38e3e02ac
BLAKE2b-256 checksum
How to use checksums
595946988264072125e265ae7fc4857504ccf7cbb69bfe8bd4a46f796e1b283a
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.7

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