Skip to content

fix(daemon): exec the Claude hook and status line commands so sh becomes Node (#3416) - #3427

Merged
mvschwarz merged 2 commits into
mvschwarz:mainfrom
billbenetti:fix/3416-exec-hooks
Nov 17, 2026
Merged

mvschwarz merged 2 commits into
mvschwarz:mainfrom
billbenetti:fix/3416-exec-hooks

Conversation

@billbenetti

@billbenetti billbenetti commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What a user gets

Refs #3416 (item 1; items 2 and 3 come separately). Every OpenRig Node hook and the seat status line now start with exec, so the /bin/sh -c that Claude Code runs them through becomes the Node process instead of waiting on it. On Debian/Ubuntu, where /bin/sh is dash and does not exec the last command of sh -c, each hook event costs one process instead of two (about 500 fewer sh processes a minute on the 90-seat host from the issue). Exit codes, stdout and stdin are unchanged.

  • hooks/claude.json: the 14 plugin hook commands start with exec "${OPENRIG_NODE:-node}" ….
  • The status line and activity relay entries that launch writes into .claude/settings.local.json start with exec too.
  • As discussed in the issue, OpenRig recognises those generated entries by their exact shape. parseManagedClaudeNodeCommand (and through it isOwnedCollectorCommand, isOwnedRelayCommand and restore-check) and the relay's own settingsRelayPath accept one plain leading exec, so both the shape earlier versions wrote and the new one stay OpenRig's: a launch replaces either, rig down takes either back, and the plugin's relay still stays quiet when the settings relay (in either shape) is registered for the event.
  • docs/reference/claude-status-line.md (copy the collector command into a wrapper without its leading exec) and the plugin README (the settings relay shape may start with exec).

How you verified it

On 49a41912f plus this change (rebased onto fe0d346df with no overlap), Linux (/bin/sh = dash), Node 22, focused Vitest with --maxWorkers=2; I did not run the full npm test on this host.

  • New and extended tests in claude-hook-node-invocation.test.ts:
    • the refresh through the real writers replaces old commands both without and with exec (5 kinds × 2 prefixes);
    • the generated relay and status line commands, run through /bin/sh -c, are the Node process itself (process.pid equals the spawned child's pid), with a pinned and a legacy interpreter;
    • every plugin manifest command starts with exec and runs as the shell's own pid;
    • both readers accept exec / exec\t before the old shape and refuse exec exec …, exec -a name …, 'exec' …, execnode …, exec <script> alone, exec, and other wrappers.
  • claude-core-plugin-load.test.ts: the plugin relay deduplicates against a pinned settings relay with and without exec.
  • rig-teardown.test.ts: rig down restores the person's settings bytes when the relay hooks and the status line are in either shape.
  • restore-check-service.test.ts: the activity-hook check is green for the relay command with exec (bare node and an absolute interpreter), next to the existing shapes.
  • claude-activity-hook-delivery.test.ts: disable strips the owned relay in both shapes; the other expectations of the generated shape are updated there and in claude-collector-unchanged-write, claude-context-collector and permission-stop-relay.
  • Results: in the 57 daemon test files that touch these settings, the change leaves only failures that the base also has in my sandbox (4 startup classic-clear cases, the provider-switch-cli integration, 2 claude-relay-project-cleanup git-clean cases, and the relay asset's 0755 mode, which my sandbox copy doesn't keep). Control: the new tests against the base sources fail in 25 cases, every exec case. tsc --noEmit for packages/daemon is clean.

Anything you were unsure about

  • Scenario rule: this touches claude-code-adapter.ts (launch artery), but a runtime: stub seat never goes through the Claude adapter, and the stub does not run Claude Code's hooks or status line, so a stub scenario cannot see either shape. The coverage is the tests above, which execute the real generated and shipped commands through /bin/sh.
  • Downgrade: a daemon older than this change does not recognise the exec shape, so after a downgrade it would treat those entries as the person's own (no refresh, and its relay would be added next to the existing one). Upgrade is covered: the matchers accept both shapes.
  • Codex: untouched. Codex hook commands are generated separately, and the plugin's Codex activity entries are no-ops.
  • No plugin version bump and no CHANGELOG edit, per CONTRIBUTING.

If this is security-related

Not security-related.

  • One concern per PR; no version bump; no CHANGELOG.md edit
  • Tests added or updated where the change is testable
  • I listed the checks I ran, their results, and any checks I could not run

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements
    • Claude activity-relay, hook, and status-line commands now use exec to run Node directly, replacing the invoking shell.
    • Existing commands without exec remain recognized during refresh, cleanup, and duplicate-event suppression, preserving compatibility with previously generated settings.
    • Managed commands continue to use their selected Node executable; a missing pinned executable does not fall back to another executable on the system.
  • Documentation
    • Clarified how to copy the collector path and directory arguments from the generated status-line command, excluding its leading exec.

…mes Node (mvschwarz#3416)

The plugin's hooks/claude.json commands and the status line and activity relay entries that launch
writes into .claude/settings.local.json now start with `exec`. Under dash, `sh -c` otherwise stays as
a parent of every Node hook, so each event cost two processes.

OpenRig owns the generated settings entries by their exact shape, so parseManagedClaudeNodeCommand
(and the matchers in claude-owned-settings.ts and restore-check that use it) and the relay's own
settingsRelayPath accept one plain leading `exec`: a launch replaces, and rig down takes back, both
the shape earlier versions wrote and the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Claude hook and status-line commands now use a leading exec before Node. Managed-command parsers accept one plain leading exec and continue to support earlier command forms. Tests cover command generation, parsing, invocation, and teardown.

Changes: Claude command generation and execution

Layer / File(s) Summary
Emit exec-prefixed commands
packages/daemon/src/adapters/claude-code-adapter.ts, packages/daemon/assets/plugins/openrig-core/hooks/claude.json, packages/daemon/test/claude-context-collector.test.ts, packages/daemon/test/claude-collector-unchanged-write.test.ts, packages/daemon/test/permission-stop-relay.test.ts, docs/reference/claude-status-line.md
Generated and shipped Claude commands now use a leading exec. Related tests expect the prefix. The status-line instructions identify how to copy the collector arguments and select OPENRIG_HOME.
Recognize prefixed and legacy commands
packages/daemon/assets/plugins/openrig-core/hooks/scripts/activity-relay.cjs, packages/daemon/src/domain/claude-activity-hooks.ts, packages/daemon/assets/plugins/openrig-core/README.md, packages/daemon/test/claude-activity-hook-delivery.test.ts, packages/daemon/test/claude-core-plugin-load.test.ts, packages/daemon/test/restore-check-service.test.ts
The command parsers and matcher accept one leading plain exec. Tests cover both prefixed and earlier commands.
Verify invocation and teardown
packages/daemon/test/claude-hook-node-invocation.test.ts, packages/daemon/test/rig-teardown.test.ts
Tests verify shell replacement by Node, command-grammar acceptance and rejection, and settings restoration for prefixed and earlier commands.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related issues

  • mvschwarz/openrig#3416 requests exec prefixes for Claude hook and generated status-line commands. This change adds those prefixes.
  • mvschwarz/openrig#421 concerns entries written to project-local .claude/settings.local.json. This change updates command text and ownership matching, but does not change where the entries are written.

Suggested reviewers: mvschwarz, openrig-review

Merge Risk: Minimal · up to 73ffe

This change makes Claude hook and status-line commands replace the shell with Node, which removes one extra process per hook event. The existing command forms are still recognized. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: adding a leading exec to the Claude hook and status line commands so that sh is replaced by Node. The raw summary and PR objectives confirm this is the primary change.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: adding a leading exec to the Claude hook and status line commands so that sh is replaced by Node. The raw summary and PR objectives confirm this is the primary change. The title uses a conventional fix(daemon) prefix and is specific enough for a teammate scanning history. The #3416 reference in the title differs from the #3427 number in the objectives, which is a metadata mismatch and does not affect the title's relevance.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 72d821b9-9bfe-46a4-a947-138b4202eb02
Commits

Reviewing files that changed from the base of the PR and between 2c53dcb and 73ffe7b.

Files selected for processing: 1

  • packages/daemon/test/claude-hook-node-invocation.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

…nterpreter (mvschwarz#3416)

The bash 3.2 behind macOS /bin/sh exits 126 when `exec` can't find the pinned interpreter;
dash and current bash exit 127. Both mean the shell couldn't run it, and the test now also
checks that nothing ran in its place (the collector's sidecar isn't written again).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@billbenetti

Copy link
Copy Markdown
Contributor Author

The package-tests (daemon) failure at claude-hook-node-invocation.test.ts:156 was macOS-only. On macos-latest, /bin/sh is bash 3.2 in sh mode, and exec of a missing path exits 126. dash and bash 5 exit 127.

73ffe7b4f changes only the test. It accepts 126 or 127, and it also checks that nothing ran in its place: the collector's sidecar, deleted before the call, is not written again. The guarantee is unchanged: no hidden fallback to a different PATH interpreter.

This PR's own daemon job (run 44115350172) is still waiting for a macOS runner. The same commit passed package-tests (daemon) on macos-latest in #3433's run, which contains it: https://github.com/mvschwarz/openrig/actions/runs/44116385134/job/134155463152

@openrig-review openrig-review 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.

Approved at 73ffe7b. The Claude hook and status line commands OpenRig writes now exec their Node process, so the shell is replaced rather than kept alive beside it, and the settings matchers recognise the new shape. Both review halves are clear, and required CI passes at this head. Thank you, @billbenetti.

@mvschwarz
mvschwarz merged commit 75dcf6d into mvschwarz:main Nov 17, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRig roadmap Nov 17, 2026
@mvschwarz

Copy link
Copy Markdown
Owner

Thanks, @billbenetti, this is now merged into main as 75dcf6d6. Each Claude hook and status line run now replaces its shell with Node instead of keeping both alive, which by your figures saves about 500 sh processes a minute on the 90-agent host from #3416. The settings matchers recognise both the old and the new shape, so refresh, disable and rig down keep working on folders written either way. Thank you for the measurement behind it, and for tracking down the macOS 126 in the test.

The known limit, as the change records it: a daemon older than this change doesn't recognise the exec shape, so after a downgrade a refresh can add a duplicate relay entry, the status line may not refresh, and rig down can leave the exec entries in place.

mvschwarz pushed a commit that referenced this pull request Nov 18, 2026
…tch (#3416) (#3439)

Item 2 of #3416 (item 1 is #3427, already on main). The activity relay is a fresh Node process for every Claude hook event, and its first global fetch loaded Node's bundled HTTP client each time. It now posts with node:http, or node:https for an https base URL: the same body to the same URL with the same bearer token, at most 1.5 s, every error swallowed, so the daemon records exactly what it did before. One behaviour is tighter: the connection closes as soon as the daemon's response headers arrive, so a peer that sends headers and then stalls the body no longer keeps the hook process alive. The author measured roughly half the child CPU per event in a same-host microbenchmark; that is their measurement, not a measured daemon or fleet responsiveness gain. No new refusal, setting or error code.
@mvschwarz mvschwarz added this to the v0.7.19 milestone Nov 19, 2026
@mvschwarz

Copy link
Copy Markdown
Owner

@billbenetti, thanks again: this is now released in OpenRig 0.7.19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants