---
name: patchcord-subscribe
description: >
  Start a persistent Patchcord realtime listener that wakes Grok when new
  messages arrive. Use ONLY when the user explicitly runs
  /patchcord-subscribe or asks to subscribe to Patchcord.
disable-model-invocation: true
user-invocable: true
---

# Patchcord subscribe for Grok

The user explicitly requested `/patchcord-subscribe`. Do not replace this with
`patchcord__wait_for_message` or a polling loop.

## Start

1. Drain the backlog with `patchcord__inbox`. Process pending actionable
   messages before starting the listener.
2. Start a persistent Grok `monitor` with this command:

   ```text
   monitor(
     description: "patchcord realtime listener",
     persistent: true,
     timeout_ms: 3600000,
     command: "patchcord subscribe | grep --line-buffered '^PATCHCORD:'; exit ${PIPESTATUS[0]}"
   )
   ```

   The explicit `cd` is not needed when Grok runs from the project directory;
   `patchcord subscribe` resolves `.grok/config.toml` by walking to the git
   root. The listener owns its pidfile and reconnects itself.
3. Tell the user: **“Patchcord listener active — I’ll pick up new messages as
   they arrive.”**

## On each notification

When monitor surfaces `PATCHCORD: 1 new from <sender>`:

1. Say that a Patchcord ping arrived and call `patchcord__inbox`.
2. Do the requested work.
3. Reply with concrete results using `patchcord__reply`; classify the outcome
   as DONE, BLOCKED, or ACTIONABLE.
4. Do not start another monitor. The existing listener persists across turns.

## Errors and stopping

If the monitor stream ends, inspect its final output and report one sentence:

- `already running (pid N)` — another listener is active; do not respawn.
- `ticket: token rejected (HTTP 401|403)` — the project bearer is invalid.
- `no patchcord config found` — Grok is outside a configured project.
- `subscribe: fatal: ...` — report the fatal line verbatim.

Do not use `pgrep`, `ps`, `pkill`, `killall`, hand-written pidfiles, or
respawn loops. Stop by ending the Grok session, or run
`patchcord subscribe --stop` from the project directory.
