---
title: "Space hooks: run scripts on AI agent events in Cohub"
description: "Space hooks run a script, a prompt or an App Action when something happens in a Cohub Space: a file change, a finished turn, a new Save or an inbound webhook."
lang: "en"
canonical: "https://cohub.live/features/space-hooks"
image: "https://cohub.live/_seo/og/features/space-hooks.png"
updated: "2026-11-17"
---

# Space hooks: run scripts on AI agent events

Space hooks let you run scripts on AI agent events in Cohub: a YAML file in .cohub/hooks/ runs a command, sends a prompt or calls an App Action when a turn finishes, files change, a Save is created or a webhook arrives.

- **Who:** Builders who want checks and follow-ups to happen on their own after the agent or a teammate changes something.
- **When:** You keep telling the agent "now run the tests" or "summarise what changed" after every turn.
- **Why:** A hook is a file in the Space that reacts to Space events, so the rule travels with the project and runs as the Space owner without anyone watching.

![Cohub home page showing an isolated cloud workspace where an agent keeps running tasks after you leave](https://cohub.live/_seo/img/home/home-cloud-sandbox.webp)

Source: <https://cohub.live/>

![Terminal output of cohub spaces webhooks --help: list, url and trigger for hooks declared in .cohub/hooks](https://cohub.live/_seo/img/cli/cli-webhooks-dark.webp)

Source: <https://www.npmjs.com/package/@neta-art/cohub-cli>

## One file per hook
Hooks live in `.cohub/hooks/*.yml` (or `.yaml`, `.json`). Each declares one event and exactly one action: `run` (a shell command), `prompt` (a message to a Chat) or `uses` (a published App Action).

```yaml
# .cohub/hooks/review-after-save.yml
schema: cohub.space-hook.v1
on:
  event: checkpoint.created
prompt:
  text: summarize the new checkpoint and suggest next steps
  intent: followup
```

## Events you can react to
| Event | Fires when | Filters |
|---|---|---|
| `space.fs.changed` | Workspace files change | `paths`, `ignore`, `kinds` |
| `session.turn.finalized` | An agent turn finishes | Chat ids, sources (web, CLI, channel), labels |
| `checkpoint.created` | A Save is created | |
| `app.version.published` | An App version goes live | |
| `task.updated` | A task run changes state | |
| `space.workspace.ready` | A restore or bootstrap finishes | |
| `webhook` | Something POSTs to the hook's URL | Optional shared secret |

## Things to build with hooks
- Run `npm test` when anything under `src/**` changes.
- After every turn in Chats labelled `Review`, ask a reviewer Chat to check the diff.
- When an App version is published, post release notes to a file.
- Receive a webhook from another service and hand its JSON body to a script or an App Action. `cohub spaces webhooks url <name>` prints the URL to give that service.

Step by step, with a real run: [a daily GitHub issues digest](https://cohub.live/guides/github-issues-digest) pairs a scheduled prompt with a `space.fs.changed` hook that posts each new digest file.

## Good to know
- Hooks run as the Space owner, who is also billed.
- Each hook gets context in environment variables such as `COHUB_HOOK_EVENT_TYPE`, `COHUB_HOOK_SESSION_ID` and `COHUB_HOOK_FS_PATHS`.
- Changes under `.cohub/` never trigger file hooks, so a hook can't loop on itself.
- The design is an MVP: no separate hook permissions or concurrency control yet, failures are recorded without automatic retries, and hook discovery assumes a cloud sandbox workspace.

## Full schema
Full schema and environment variables: Space hooks in the repository. For time-based work, use [scheduled prompts](https://cohub.live/features/scheduled-prompts).

## Reference in the docs

**This page:** Which Space events are worth a hook, and what to automate with one.

- [Core concepts](https://cohub.live/docs/learn/core-concepts): Tasks, the run records that hook runs show up as
- [App development](https://cohub.live/docs/developers/apps): App Actions, which a hook can call with uses

## Related

- [Build a daily GitHub issues digest with a scheduled prompt and a Space hook](https://cohub.live/guides/github-issues-digest): To get a GitHub issues digest every morning in Cohub, schedule a prompt that runs a digest skill in a fixed Chat, and add a Space hook that posts each new digest file to a webhook as soon as it is written.
- [Scheduled prompts: cron for AI agents](https://cohub.live/features/scheduled-prompts): Scheduled prompts are cron for AI agents: a Cohub prompt sent to a Space after a delay, at an ISO time, or on a cron expression with a time zone, with each run recorded in a Chat.
- [Set up AI agent scheduled tasks that run inside your Cohub Space while you are away](https://cohub.live/use-cases/schedule-ai-agent-tasks): You schedule AI agent tasks in Cohub with a scheduled prompt: a message the Space sends to its agent once at a set time or on a cron schedule, with every run kept as a Chat.
- [How one Cohub Space works as an AI agent workspace for indie developers](https://cohub.live/use-cases/indie-developer-ai-workspace): Cohub is an AI agent workspace for indie developers: each Space has a cloud sandbox the agent runs commands in, port previews, one-command publishing and prompts that run on a schedule.

## Sources

- [Cohub home page (Space hooks)](https://cohub.live/)
- [Cohub docs: App development (App Actions)](https://cohub.live/docs/developers/apps)

Updated Nov 17, 2026
