When
A file change, Save, finalized turn, published App version, Task Run transition, or inbound HTTP request should trigger work inside the Space.
Outcome
- Declarative hooks under
.cohub/hooks/* - Event matching without self-trigger loops
- Webhook endpoints addressed by hook file name
- Runs visible as Tasks with curated event context
Steps
- Choose an event: ``
text space.fs.changed space.workspace.ready session.turn.finalized checkpoint.created app.version.published task.updated webhook`` - Add one YAML/JSON file per hook. Exactly one of
run,prompt, orusesis required: ``yaml schema: cohub.space-hook.v1 on: event: task.updated run: | echo "task=$COHUB_HOOK_TASK_ID status=$COHUB_HOOK_TASK_STATUS"`` - Use
paths,ignore,kinds,sessionIds,sources, or label filters underonwhere supported.prompt.sessionIdis the action target, not a trigger filter. - Remember that FS matching ignores
.cohub/**, andtask.updatedfilters outspace_hooktasks and theirrun_commandchildren to prevent re-entry. - Read event context from
COHUB_HOOK_*variables. Optional values are exported as empty strings; file paths and changed fields are bounded. - Verify the resulting Task Run in the Tasks surface.
Webhook triggers (v2.46)
A hook with on.event: webhook becomes an endpoint named after its file:
# .cohub/hooks/mail.yml -> POST /api/spaces/:spaceId/webhooks/mail
schema: cohub.space-hook.v1
on:
event: webhook
secret: wh_a1b2c3
uses: alice/tools/mail-inbox/deliver# External service
curl -X POST https://<api>/api/spaces/<spaceId>/webhooks/mail \
-H 'content-type: application/json' \
-H 'x-cohub-webhook-secret: wh_a1b2c3' \
-d '{"messageId":"...","from":"..."}'
# Local testing and endpoint discovery
cohub spaces webhooks ls --json
cohub spaces webhooks url mail
cohub spaces webhooks trigger mail --body '{"messageId":"..."}'The JSON body (64 KB max) arrives as COHUB_HOOK_WEBHOOK_BODY; the response is { taskRunId, hook, eventId }. Webhooks are rate-limited per Space. The secret is optional and can also be passed as ?secret=.
Task Run hooks (v2.18)
task.updated fires on Task Run state transitions (pending -> running -> completed/failed) and exposes the task id/type/status, changed fields, and error. Use it to launch follow-up validation or notification work without polling generation or Chat state.
uses: run an App Action (v2.46)
Instead of a shell command or prompt, a hook can run a published App Action:
schema: cohub.space-hook.v1
on:
event: checkpoint.created
uses: alice/tools/mail-inbox/deliver
with:
dir: inbox/mailThe payload in with is delivered as JSON on stdin to the Action. See App Actions.
Scheduled prompts vs Hooks
| Mechanism | Good for |
|---|---|
| Scheduled prompt | Time-based recurrence |
| Space Hooks | Domain events, state transitions, inbound webhooks |
Done when
- [ ] The hook file is in the Space workspace
- [ ] A real event produces one expected Task Run
- [ ] Filters and action target are distinct
- [ ] A webhook endpoint responds and (when configured) rejects a wrong or missing secret
- [ ] No retry storm or self-trigger loop occurs
Avoid
- Modifying matched paths without an exit condition
- Putting secrets in hook YAML instead of Space env (
on.secretis a trigger credential, not a storage location for other secrets) - Polling Chat when
task.updatedprovides the event boundary - Using hooks as a substitute for product permission design