coding.sh alert
Notify a webhook or a command when failures, cost, sessions, a flag or a score cross a threshold.
coding.sh alert <action>
Notify a webhook or a command when failures, cost, sessions, a flag or a score cross a threshold
Commands
add Add an alert; a webhook alert prints its signing secret once
list List the alerts with their last state, and say which targets are off after failed deliveries
rm Remove an alert
check Read every alert's measure, save its state, and notify each change of state
test Send a test notification (test: true) to an alert's target; a success turns a disabled target back on
Examples
coding.sh alert add failures --measure failure-rate --over 0.5 --window 1d --notify webhook:https://example.com/hook
coding.sh alert check
coding.sh alert list
Notes
States are OK, WARNING, ALERT and NO_DATA. An alert starts at OK, and only a change of state notifies. The measures are the ones coding.sh stats computes, over top-level sessions with their subagents' cost added; score:<NAME> averages the scores of that name given to those sessions (coding.sh score, a judge, a review).
A webhook gets a POST with the JSON body {alert, state, previous, value, threshold, direction, window, by, at} (direction: "under" only with --under, by only with --by agent) and three headers keyed with the alert's secret: X-Coding-Sh-Timestamp (unix seconds), X-Coding-Sh-Signature-V2: sha256=<HMAC-SHA256 of "<timestamp>.<body>">, which covers the timestamp and the body, and X-Coding-Sh-Signature: sha256=<HMAC-SHA256 of the body alone>, which does not stop a replay. A receiver checks V2 and refuses a timestamp more than 5 minutes from its own clock. A command gets the same JSON on stdin and succeeds by exiting 0; on Windows it runs in cmd.exe.
Each notification is tried 3 times, 1 s and then 2 s apart. A change that was not delivered is sent again by the next check. After 5 failed deliveries in a row the target is turned off; alert list says so, and a successful alert test turns it back on: the next check sends the changes it missed.
alert check exits 0 unless the usage is wrong; with --json it lists each alert's state, value and groups. Run it from cron or Task Scheduler. coding.sh serve runs the same check every minute, the first a minute after it starts. The hook and the read commands never run alerts.
Alerts, their states and their secrets are kept in ~/.coding.sh/alerts.json, mode 600 where the OS has file modes. coding.sh alert add
Add an alert; a webhook alert prints its signing secret once.
coding.sh alert add <NAME> [options] Add an alert; a webhook alert prints its signing secret once Arguments name Letters, digits, dot, dash and underscore, up to 64 Options --measure <MEASURE> failure-rate (a share from 0 to 1), cost (USD), sessions, flag:<FLAG> (sessions with that flag or tag), or score:<NAME> (the mean of that numeric or boolean session score, true as 1; categorical and text scores are skipped) --where <QUERY> Only sessions matching a query, e.g. 'agent:codex cost>0.5 tool:Bash -flag:compaction' (keys: coding.sh sessions --help) --by <GROUP> One state per agent, each notified on its own (default: one state for all sessions) --over <N> ALERT when the measure is above N --warn <N> WARNING when the measure is above N and not above --over --under <N> ALERT when the measure is below N instead (a falling score); not with --over or --warn --warn-under <N> WARNING when the measure is below N and not below --under --window <WINDOW> The sessions that started in this much time before the check. One of: 1h, 1d, 7d. --notify <TARGET> webhook:<URL> (a signed JSON POST) or command:"<CMD>" (the same JSON on stdin) --no-data <STATE> State when the window has no sessions (or, for cost, no priced session; for score:<NAME>, no such score): ok, alert, or keep the last state (default: NO_DATA) Examples coding.sh alert add failures --measure failure-rate --over 0.5 --window 1d --notify webhook:https://example.com/hook coding.sh alert add spend --measure cost --warn 20 --over 50 --window 1d --by agent --notify command:"notify-send coding.sh" coding.sh alert add spend --measure cost --warn 20 --over 50 --window 1d --by agent --notify "command:node C:\alerts\notify.mjs"
coding.sh alert list
List the alerts with their last state, and say which targets are off after failed deliveries.
coding.sh alert list List the alerts with their last state, and say which targets are off after failed deliveries Examples coding.sh alert list coding.sh alert list --json
coding.sh alert rm
Remove an alert.
coding.sh alert rm <NAME> Remove an alert Arguments name The alert's name (alert list) Examples coding.sh alert rm failures
coding.sh alert check
Read every alert's measure, save its state, and notify each change of state.
coding.sh alert check [options] Read every alert's measure, save its state, and notify each change of state Options --fresh Wait for every pending capture to be ingested (default: answer after 1.5 s) Examples coding.sh alert check coding.sh alert check --json
coding.sh alert test
Send a test notification (test: true) to an alert's target; a success turns a disabled target back on.
coding.sh alert test <NAME> Send a test notification (test: true) to an alert's target; a success turns a disabled target back on Arguments name The alert's name (alert list) Examples coding.sh alert test failures