Skip to content

fix: hook relay stdin — remove & that disconnects pipe - #57

Merged
aterrylu merged 7 commits into
mainfrom
terry/auto-install-hooks
Mar 24, 2026
Merged

fix: hook relay stdin — remove & that disconnects pipe#57
aterrylu merged 7 commits into
mainfrom
terry/auto-install-hooks

Conversation

@aterrylu

Copy link
Copy Markdown
Owner

Summary

The inline curl hook command had a trailing & to background it. But Claude Code pipes event JSON via stdin to the hook command, and backgrounding disconnects stdin — so curl -d @- reads nothing and fails.

Fix: Remove the &. Claude Code's async: true already runs hooks in the background.

Root cause

# Broken: & disconnects stdin, curl reads empty body
echo '{"event":"Stop"}' | sh -c 'curl -d @- http://... &'

# Fixed: async:true in hook config handles backgrounding
echo '{"event":"Stop"}' | sh -c 'curl -d @- http://...'

🤖 Generated with Claude Code

@nox-0x nox-0x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core fix is correct: backgrounding with & disconnects stdin, causing curl -d @- to read an empty body and silently fail. Removing & and relying on async: true is exactly right — the --max-time 2 / timeout: 3 safeguards prevent blocking. Sidebar refactor looks clean; moving time to the top row and adding the notification count badge improves scannability. Defaulting to "working" instead of "unknown" during initial load is a reasonable UX call. Solid fix.

aterrylu and others added 7 commits March 24, 2026 02:08
Server now ensures the autonomos-relay.sh hook script is installed
and registered in Claude Code's settings.json on every startup.

- installHookRelay() runs at startup, after claude binary validation
- Copies hook script from packages/server/hooks/ to ~/.claude/hooks/
- Registers on 10 Claude Code hook events with async: true
- Idempotent: skips if already installed and up to date
- Updates script if bundled version is newer
- Uses ~ paths in settings.json (portable across machines)
- Non-fatal: warns on failure, server continues

No manual setup needed — just start the server and hooks are ready.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the file-based hook relay (autonomos-relay.sh + installHooks.ts)
with per-session hook injection via Claude Code's --settings flag.

How it works:
- createSession() passes --settings with hooks config as inline JSON
- Each hook event fires: curl -d @- $AUTONOMOS_SERVER/api/hooks/$SESSION_ID
- AUTONOMOS_SERVER and AUTONOMOS_SESSION_ID already injected by buildEnv()
- Merges with user's existing hooks (empirically verified)

What this eliminates:
- No relay script file to install
- No global settings.json mutation
- No install button needed
- No user action required
- Sessions outside autonomOS are completely unaffected

Deleted: installHooks.ts (no longer needed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… right)

Restructured sidebar session rows:
- Top row: icon + title (left), time + unread count in red (right)
- Bottom row: project · branch (left), status label (right)
- Default status for new sessions: spinning (was dashed circle)
- Unread count shown on all states, not just needs-input

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude Code pipes event JSON via stdin to the hook command. The trailing
& backgrounds curl, which disconnects stdin so -d @- reads nothing.
Claude Code's async:true already runs the hook in the background.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aterrylu
aterrylu force-pushed the terry/auto-install-hooks branch from bc891eb to 5db3b26 Compare March 24, 2026 09:08
@aterrylu
aterrylu merged commit 74e247f into main Mar 24, 2026
1 check passed
@aterrylu
aterrylu deleted the terry/auto-install-hooks branch March 24, 2026 09:09
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.

2 participants