Guides
State between runs
Automations can remember values and counts from one run to the next, so they can skip what they've seen, alert only on changes and act on thresholds.
Every ClickRuntime automation has its own storage that survives between runs. A run can save what it saw, and the next run can read it back. This is what makes an automation stateful: it acts on what changed, not just on what it sees right now.
Built-in assistant features, such as scheduled tasks and reminders, start from nothing each time. If a job needs to remember anything from its last run, use ClickRuntime. State is available on every plan, including on the free plan.
What you can build with it#
| Pattern | What the automation remembers | Example request |
|---|---|---|
| Only new items | The ids or last timestamp it already handled | "Every 15 minutes, post new GitHub issues to #triage" |
| Alert only on change | The last value it saw | "Email me when this price drops" |
| Thresholds and counts | A count of failures, signups or errors | "Alert #ops after 3 failed checks in a row" |
| Cooldowns | When it last sent an alert | "Warn me about high error rates, at most once an hour" |
| Resume where it left off | A cursor or page number | "Copy every new order into the sheet" |
| Collect, then send | Events received during the day | "Collect form submissions and email one digest at 6pm" |
| Trends over time | Counts per hour, day or week | "Every Monday, tell me how signups compare with last week" |
You don't need to ask for state. Describe the job, and the assistant adds state when the job needs it. The automation's summary says what it remembers.
Example prompt: Every hour, check the status page and Slack #ops only when a component's status changes.
Two kinds of state#
Values are named keys holding any JSON value: a number, text, a list or an object. They stay until the script removes them or you clear state.
Counters are numbers grouped by minute, hour, day, week or month. The script adds to them and reads them back for a time range. Each counter expires after the number of days the script sets (up to 3650), so old counts clean themselves up.
How scripts use it#
from clickruntime import on_trigger, state, http, notify
@on_trigger
def run(event):
status = http.get("https://status.example.com/api/v2/status.json").json()["status"]["indicator"]
last = state.get("last_status")
state.set("last_status", status)
if last is not None and status != last:
notify.slack(f"Status changed: {last} → {status}", channel="#ops")
from clickruntime import on_event, state
@on_event
def handle(event):
state.increment_metric("signups", ttl_days=90, bucket="day")
The full list of calls, including @state_initializer for setting starting values and @state_cleaner for undoing outside effects when state is cleared, is in the script reference.
Scope and limits#
- State belongs to one automation. Other automations and workspaces can't read it.
- Keys are up to 255 characters. Each value is JSON up to 1 MB.
- Keep it small: ids, timestamps, prices, counts. It isn't a database. For large data, write to a sheet or your own store.
- Never store keys or tokens in state. Use secrets for those.
Clearing state#
On the automation page, under Advanced, Clear live state erases every value and counter, so the next run starts fresh. Deleting an automation also deletes its state.