# Set up WakeAgent for Claude Code

> For a person who uses Claude Code — and for the agent helping them. Follow the steps in order. Where a step says
> **ask the person**, stop and ask: never choose a team, a settings file or a scope for them.
> Product page: https://www.keepware.dev/wakeagent · Integrating an agent product instead: https://www.keepware.dev/wakeagent/integrate.md

WakeAgent wakes your AI agents when something happens — a CI run fails, a PR gets a review, a Jira issue moves. Your
team's GitHub, GitLab, Bitbucket, Jira, Sentry, Linear or any webhook sends its events to WakeAgent
(`https://wakeagent.keepware.dev`); a Claude Code session that asked for an event is woken with it. It is a Keepware
product, free, in beta, signed in with a Keepware account.

How it works on this computer: one small program, `wakeagent` (npm package `@keepware/wakeagent`), runs a single
background process (*the resident*) that holds one connection per team and hands each wake to the session that asked
for it — to its background `wakeagent wait` command, through its hooks, as a message into the open session, or by
resuming the closed session in its own permission mode.

## What you need

- macOS (Apple silicon or Intel) or Linux (x64 or arm64). Windows: not yet.
- Claude Code, and Node.js 18 or later (for `npx` / `npm`).
- A Keepware account (https://www.keepware.dev/account). Every person has **Personal**; teams are made and joined on
  keepware.dev → Account → Teams. Every member of a team can use WakeAgent; nothing to buy or tick.

## Try it in a minute

Three steps, nothing to fill in — no team, no webhook:

```bash
npx -y @keepware/wakeagent login                               # 1. sign in (a browser opens)
claude mcp add wakeagent -- npx -y @keepware/wakeagent mcp     # 2. add it to Claude Code; start a new session
```

3. In Claude Code, ask: *"wait for a WakeAgent test event"*. The agent calls `wakeagent_wait` with
   `{kinds: ["test"]}` and runs the command it returns as a background command. Then, in another terminal:

   ```bash
   npx -y @keepware/wakeagent test
   ```

   The session wakes with `[WakeAgent] Test event from you — WakeAgent works.` A test event goes to your Personal space
   (`--team <slug>` sends one to a team; `--note "…"` adds a line; `--in 30` sends it in 30 seconds); it reaches only a
   wait that asked for kind `test`, at most 10 an hour. keepware.dev → Account → WakeAgent → Sources and the menu bar
   app's Overview have a **Send a test event** button too.

Then connect real sources (step 7) — GitHub, GitLab, Bitbucket, Jira, Sentry, Linear — so the agent can wait for CI,
reviews and issues. The steps below are the whole setup, with what each one does.

## 1. Install the program

```bash
npm install -g @keepware/wakeagent      # recommended: a stable path for the hooks and "start at login"
wakeagent --version                     # wakeagent 0.6.9
```

`npx -y @keepware/wakeagent <command>` works for every command without installing. Use the global install anyway if
you want the hooks (step 4) or start at login (step 5): those write the program's own path into a file, and the path
inside npx's cache can be cleared by npm. Below, `wakeagent` means either form.

What it does: puts one signed binary (macOS: signed with Keepware's Developer ID and notarized by Apple) and a small
Node launcher on this computer. It touches nothing else.

## 2. Sign in, once

```bash
wakeagent login
```

A browser opens on keepware.dev; **the person** signs in and sees Personal and every team they're in, all ticked. They
untick any they don't want on this computer and click Allow. (No browser here — `--no-browser` prints the address to
open elsewhere.) The browser ends on a keepware.dev page saying what is connected; the command answers
`Signed in: Personal (personal), Acme (t_…), on this computer as “<computer>-<suffix>”.` followed by the lines for
step 3 (`claude mcp add wakeagent -- …` for Personal, `claude mcp add wakeagent-acme -- … --team acme` for each team). `wakeagent login --team <team>` signs in just one (a slug, an id or `personal`).

What it does: one OAuth grant per space for this computer, each listed on keepware.dev → Account → Connected apps
(named after the computer) and each signed out on its own (`wakeagent logout --team <team>`). A team the person joins
later is offered in the menu bar app ("New team: Beta — Connect"), or connected with `wakeagent login --team <team>`;
nothing is ever connected without the person. The refresh token goes into the macOS keychain (service `WakeAgent`) or, on Linux, a
0600 file under `~/.local/share/wakeagent/tokens/`; access tokens live 10 minutes and never leave the resident's memory.
It never reads or changes anything of Claude Code's. `wakeagent status` lists the teams signed in.

## 3. Add the WakeAgent MCP server

Without `--team` the server is the person's **Personal** space — that is the line to start with:

```bash
claude mcp add wakeagent -- npx -y @keepware/wakeagent mcp
# all projects:       claude mcp add --scope user wakeagent -- npx -y @keepware/wakeagent mcp
# installed globally: claude mcp add wakeagent -- wakeagent mcp
```

**Ask the person** whether this agent should also be woken by one of their teams' events (never pick one for them —
`wakeagent status` lists the teams signed in on this computer), and whether WakeAgent should be available in this
project only (Claude Code's default, `local` scope) or in all their projects (`--scope user`). For each team they name,
one more line with the team's slug:

```bash
claude mcp add wakeagent-acme -- npx -y @keepware/wakeagent mcp --team acme
```

One MCP server is one space: the tools have no team parameter, and an agent can't switch spaces. The server says which
space it is in its instructions and in `wakeagent_sources` ("This connection is Personal. Your teams: acme — add
`--team acme` to wait for its events."). `--team personal` still works and means the same as no `--team`.

What it does: adds a stdio MCP server to Claude Code's configuration (`~/.claude.json`). New sessions get these tools:
`wakeagent_sources`, `wakeagent_events`, `wakeagent_wait`, `wakeagent_subscribe`, `wakeagent_list`, `wakeagent_cancel`,
`wakeagent_trigger_create`, `wakeagent_trigger_list`, `wakeagent_trigger_cancel`. Restart the Claude Code session (or
start a new one) to load them; `/mcp` shows `wakeagent` (and any `wakeagent-<team>`) connected.

## 4. Optional: the hooks

Two Claude Code hooks catch wakes that no background command is waiting for:

- **Stop** — while a session works, a wake for it continues its turn.
- **UserPromptSubmit** — a session idle at its prompt gets its queued wakes the next time the person types.

**Ask the person** which settings file they go into:

| file | applies to |
|---|---|
| `~/.claude/settings.json` | every project of this person |
| `.claude/settings.json` | this project, for everyone who uses the repository (committed) |
| `.claude/settings.local.json` | this project, this person only (not committed) |

```bash
wakeagent hooks install --settings <the file the person chose> --yes
```

(On a terminal, `wakeagent hooks install` asks itself. Without one — an agent's Bash — it changes nothing unless the
file is named with `--settings` or confirmed with `--yes`.) It adds only WakeAgent's two entries and keeps everything
else in the file; `wakeagent hooks uninstall --settings <file> --yes` removes only those. On a computer with nothing
queued the hooks answer at once without starting anything.

## 5. Optional: start at login

Without this, the resident starts the first time any `wakeagent` command runs and stops after 10 idle minutes with
nothing to hold. To have wakes reach this computer after a restart before anyone runs a command:

```bash
wakeagent daemon install                # macOS: a launchd agent (dev.keepware.wakeagent); Linux: a systemd user unit
wakeagent daemon status                 # installed? running? which binary?
```

It runs the installing binary's own path (`wakeagent resident --stay`), restarted only if it fails. Remove it with
`wakeagent daemon uninstall`. No administrator rights; nothing outside your user account.

## 6. Optional: the menu bar app (Mac)

https://www.keepware.dev/downloads/wakeagent/WakeAgent_0.6.9_universal.dmg — one app for Apple silicon and Intel,
macOS 12 or later, signed and notarized by Apple, updates itself. Drag it to Applications and open it: a bolt in the menu
bar shows the state (connected, offline, paused, needs you). Its window has Status (with **Start at login**), This Mac
(what agents here wait for), the Wake log, Triggers (the list, with Delete) and Teams (one sign-in for every team; per team the MCP line to copy
and Sign out). It is the same resident process as the
command line — not a second copy — so both see the same teams and waits.

## 7. Add an event source (on keepware.dev)

**The person** does this, in a browser: keepware.dev → Account → WakeAgent → the team → **Event sources** → Add.
Pick the platform and a name; the page shows the webhook URL, the secret (once) and the platform's own steps. For a
team, only its Owner or Admins can add sources; every member can see them and subscribe.

GitHub, for example: in the repository (or the organization) Settings → Webhooks → Add webhook — Payload URL: the URL
from the page; Content type: `application/json`; Secret: the secret from the page; the events you want (or "Send me
everything") → Add webhook. GitHub sends a ping at once and the source shows **Connected ✓**.

GitLab, Bitbucket, Jira, Sentry, Linear and generic webhooks (HMAC, Bearer, Stripe- or Slack-style signatures) have
their own steps on that page. Which events each platform sends, and what they mean, for the person to read:
<https://www.keepware.dev/wakeagent/events>.

## Event names: kinds and the catalog

Each platform names its events its own way: a push is GitHub's `push` but Bitbucket's `repo:push`; CI is GitHub's
`workflow_run`, GitLab's `pipeline`, Bitbucket's `repo:commit_status_updated`. So every event also has a
platform-neutral **kind** — `push`, `ci.started`, `ci.finished` (with `conclusion`: success, failure, cancelled …),
`pr.opened`, `pr.updated`, `pr.merged`, `pr.closed`, `pr.review`, `comment`, `issue.created`, `issue.updated`,
`issue.moved`, `release`, `deploy`, `alert`, `other` — and `test`, which only a test event has (`wakeagent test`; no
platform sends it, and no other wait ever matches it). **Agents should wait with kinds** (`kinds: ["ci.finished"]`)
unless they need one platform's own event.

To look names and fields up: the tool **`wakeagent_event_types`** (with a platform: each type's typed fields and an
example), `wakeagent_sources` (each source's platform and the types it sent in the last 7 days), `wakeagent types
[platform]` in a terminal, or <https://www.keepware.dev/wakeagent/events.md> (Markdown; for a person, the same as a web page:
<https://www.keepware.dev/wakeagent/events>). A wait whose types the team's platforms
don't have — `types: ["push"]` in a Bitbucket-only team — is refused with the right name (`repo:push`, or
`kinds: ["push"]`), never left waiting for something that can't come.

## 8. Test it

Without any source: *"wait for a WakeAgent test event"*, then `npx -y @keepware/wakeagent test` (see
[Try it in a minute](#try-it-in-a-minute)). Then with one real event, in a Claude Code session started in a repository
whose GitHub source is connected:

1. Ask: *"Use WakeAgent to wait for the next push to this repository, then tell me what came."* The agent calls
   `wakeagent_wait` (for example `{kinds: ["push"], why: "test WakeAgent"}`) and runs the command it returns **as a
   background command**.
2. Push any commit to that repository (or, for CI: *"push this and wait for its CI run"* →
   `{kinds: ["ci.finished"], commit: "<sha>"}`).
3. Within seconds the background command exits and the session wakes with a line like
   `[WakeAgent] GitHub · source "acme/web" · acme/web · push · … · kind=push` followed by
   `(WakeAgent woke this session for the event above — no one typed it. …)`.
4. Check: `wakeagent status` (the team connected, what it holds) and `wakeagent log` (the delivery and who took it);
   keepware.dev → Account → WakeAgent shows the event and the subscription's last outcome.

If nothing comes: the source isn't Connected (check the webhook's recent deliveries on GitHub), the session's MCP
server is another space's (a team's source needs `--team <slug>`; without it the server is Personal), or wakes are
paused (`wakeagent status`; `wakeagent resume`). A test event that woke nothing says so: `wakeagent test` answers
"nothing here waits for a test event yet".

## What WakeAgent does — and never does

- **A wake for a closed session** resumes it (`claude -p --resume <id>`) **in the session's own permission mode** as
  Claude Code recorded it — never a higher one; nobody is at the keyboard, so anything that needs an approval is denied
  and you're told how to open the session. Subscriptions made with `delivery: live` or `never` are never resumed.
- **A wake for an open session** goes in as a message from "wakeagent" through Claude Code's messages between
  sessions, carried by a tiny `claude -p` on Haiku (one small model call on your own plan per wake; turn it off with
  `wakeagent courier off`). A session in another permission-mode class holds the message for your approval.
- **Outside text** (titles, bodies, comments) is left out unless a subscription asked for it, and then it comes only
  inside a block marked as untrusted data, never as instructions.
- **The loop guard**: at most 12 wakes an hour per subscription; past that it pauses and says so. There is no daily limit.
- **Triggers** ("when this happens, start a new session in that folder with this task") made by an agent never run in
  bypassPermissions nor above the mode of the session that made them; only the person can choose bypass (on a terminal,
  `wakeagent trigger create … --mode bypassPermissions`, after typing `bypass`). To make one, ask the agent in the
  project — for example *"when CI fails on main, start a session to fix it"* — and it uses `wakeagent_trigger_create`.
  The menu bar app lists them (what each waits for, its folder and mode, its last run) and deletes them; it doesn't
  make them.
- Never: changes Claude Code's permissions or settings except the hooks file you chose; reads your code or transcripts
  for the service (the service gets the subscription — what to wait for, the session id and folder — never the
  session's content); shares one person's subscriptions with another computer's connection.
- Pause everything on this computer: `wakeagent pause` (`wakeagent resume`); in a team: "Pause all wakes" on
  keepware.dev (Owner / Admin).

## Undo

```bash
wakeagent logout --team personal                     # per space (or --team <team>); also gives the token back to keepware.dev
claude mcp remove wakeagent                          # and wakeagent-<team> for each team you added
wakeagent hooks uninstall --settings <file> --yes
wakeagent daemon uninstall
wakeagent stop
npm uninstall -g @keepware/wakeagent
```

WakeAgent's own data is in `~/Library/Application Support/WakeAgent` (macOS) or `~/.local/share/wakeagent` (Linux).
