Skip to content

feat: generic hook relay + notification badges - #48

Merged
aterrylu merged 2 commits into
mainfrom
terry/hook-relay
Mar 24, 2026
Merged

feat: generic hook relay + notification badges#48
aterrylu merged 2 commits into
mainfrom
terry/hook-relay

Conversation

@aterrylu

Copy link
Copy Markdown
Owner

Summary

Event bus architecture for Claude Code → autonomOS communication. A single hook script relays ALL lifecycle events to the server, which decides how to handle each one.

graph LR
  CC[Claude Code] -->|hook event JSON| HS[autonomos-relay.sh]
  HS -->|POST /api/hooks/:id| S[Server]
  S -->|stores| N[Notifications]
  D[Dashboard] -->|polls every 3s| S
  D -->|shows badge| SB[Sidebar]
Loading

Key design decisions:

  • Env var gating: Only sessions spawned by autonomOS have AUTONOMOS_SERVER set. Regular Claude Code sessions are completely unaffected.
  • Fire-and-forget: 2s timeout, async, silent on failure. If the server is down, the hook exits cleanly.
  • Server-side handling: The hook is a dumb pipe. All logic for what constitutes a "notification" lives on the server, so we can iterate without redeploying the hook.

What's included

Component File What it does
Hook script packages/server/hooks/autonomos-relay.sh Reads stdin event JSON, POSTs to server
Hooks API packages/server/src/routes/hooks.ts Receives events, stores notifications
Session env packages/server/src/sessions.ts Injects AUTONOMOS_SERVER + AUTONOMOS_SESSION_ID
Store packages/dashboard/src/store.ts notificationCounts, fetch/mark-read actions
Sidebar packages/dashboard/src/components/Sidebar.tsx Blue dot badge, mark-read on click

Test plan

  • Start a session via dashboard — verify AUTONOMOS_SERVER is in env (env | grep AUTONOMOS)
  • Regular Claude Code session (outside dashboard) — AUTONOMOS_SERVER is NOT set
  • Trigger a Notification/Stop/PermissionRequest event — blue dot appears on sidebar
  • Click the session — badge clears
  • Kill the server, trigger hooks — no errors in Claude Code, no delay

🤖 Generated with Claude Code

aterrylu and others added 2 commits March 23, 2026 19:51
Event bus architecture: a single hook script relays ALL Claude Code
lifecycle events to the autonomOS server. The server decides what to
do with each event type — currently tracks notifications for sidebar
badges, extensible for future event handling.

Hook relay (packages/server/hooks/autonomos-relay.sh):
- Reads event JSON from stdin, POSTs to server
- Only activates when AUTONOMOS_SERVER env var is set (sessions
  spawned by autonomOS). Regular Claude Code sessions unaffected.
- Fire-and-forget with 2s timeout — silent on server down
- Registered on all hook events with async: true

Server:
- POST /api/hooks/:sessionId — receives raw hook events
- GET /api/hooks/:sessionId/notifications — unread count
- POST /api/hooks/:sessionId/read — mark as read
- buildEnv() injects AUTONOMOS_SERVER + AUTONOMOS_SESSION_ID into PTY env

Dashboard:
- notificationCounts in store, polled every 3s
- Blue dot badge on session cards with unread notifications
- Clicking a session marks its notifications as read

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aterrylu
aterrylu merged commit cf2686d into main Mar 24, 2026
1 check passed
@aterrylu
aterrylu deleted the terry/hook-relay branch March 24, 2026 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant