Skip to content

perf(agent-hooks): start one fewer process per Claude notify event and Codex hook event - #45301

Merged
nwparker merged 2 commits into
mainfrom
nwparker/reduce-hooks
Nov 20, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/reduce-hooks

Conversation

@nwparker

@nwparker nwparker commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Cuts one process from most managed hook runs without changing anything Orca receives.

  • Claude: every event except PreToolUse and a blocking PermissionRequest (PostToolUse, Stop, UserPromptSubmit, …) threw away the server's reply but still captured it in a $( … ) subshell. These events now send the same request straight to /dev/null. The scripts for Claude-compatible CLIs already post this way.
  • Codex: the payload capture subshell now execs /bin/cat instead of forking it. Claude's script has done this since perf(agent-hooks): start 7 processes per Claude hook event instead of 17 #38180. If /bin/cat is missing, it falls back to the old reader.

Evidence

  • Old vs new comparison: a harness ran each script against a fake hook server. Across 72 runs, requests (headers and body), stdout, exit codes and spool files were identical. The runs covered local and posix scripts for Claude and Codex, 9 events (including a PreToolUse decision, a PermissionRequest decision, an async PermissionRequest, a decision-shaped reply to PostToolUse, and empty stdin), with Orca both up and down.
  • Council comparison (Codex Sol): 1,152 base/head pairs of generated scripts under sh, dash, bash and zsh-as-sh, with errexit and both transports, behaved the same. Windows scripts are byte-identical. No test was added: per AGENTS.md, a test that passes without the change doesn't belong in the repo.
  • Checks: pnpm check:changed passes.
  • Unrelated failure: claude-status-line-install.test.ts fails 2 Windows cases with the same "AppEnvironment not initialized" error at bb227ae04ed without this change.

Risk

Low. The Claude change only touches the path whose reply was already discarded, and it reuses that path's existing post form. The Codex change produces the same bytes, using the reader already shipped for Claude.

🤖 Generated with Claude Code

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

Files Added Deleted Net
Test 0 0 0 0
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

nwparker and others added 2 commits November 19, 2026 23:37
…d Codex hook event

- Claude: an event that asked for no decision (every event but PreToolUse and a
  blocking PermissionRequest) discarded the reply but still captured it in a
  command-substitution subshell. It now posts the same request straight to
  /dev/null, the form non-deciding Claude-compatible scripts already use.
- Codex: the payload capture subshell execs /bin/cat instead of forking it,
  the reader Claude's script has used since #38180. Same bytes; falls back to
  the old reader when /bin/cat is missing.

An old-vs-new harness against a fake hook server gave identical requests,
stdout, exit codes and spool files across 72 runs (local and posix scripts,
9 events, Orca up and down).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nwparker
nwparker marked this pull request as ready for review November 20, 2026 07:53
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When orca_hook_decides is empty, the Claude wrapper runs the post without capturing a reply and exits before decision matching. It spools the event if the final post command fails. The Codex POSIX hook now passes 'exit' and POSIX_HOOK_STDIN_EXEC to the payload-capture builder.

Merge Risk: Minimal · up to 98537

This change reduces process creation in managed hook scripts without changing the events Orca receives. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description covers most template sections with substance: What Changed (Claude and Codex mechanisms), Why (process reduction with no change to what Orca receives), Testing (old-vs-new harness, Cou… Add an ELI5 section in plain language. Add a linked issue number in the 'Fixes #' line, or state that the PR is from a maintainer and no issue exists. Add Visual Proof as 'N/A' with a short reason. State the revert method in the Risk sectio…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: one fewer process started per Claude notify event and per Codex hook event. The raw summary and objectives confirm the Claude /dev/null path change and the Codex exec …
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: one fewer process started per Claude notify event and per Codex hook event. The raw summary and objectives confirm the Claude /dev/null path change and the Codex exec /bin/cat change. The 'perf' prefix and scope are accurate. The title is 87 characters, which is a little long but still clear.

Full details: Description check

Explanation

The description covers most template sections with substance: What Changed (Claude and Codex mechanisms), Why (process reduction with no change to what Orca receives), Testing (old-vs-new harness, Council comparison, pnpm check:changed, and an unrelated Windows failure), and Risk (Low, with rationale). It does not include an ELI5 section, and the Why section does not explain why this approach beats alternatives. The Linked Issue section reads 'Fixes #' with no issue number, and the template requires one for outside contributors. The Visual Proof section is missing; it should state N/A with a reason. The Risk section does not say how to back the change out. The Testing checklist is unticked, and the author states that no test was added without explaining the template's test requirement against the test anti-patterns doc. The AI Disclosure section is filled in with a Claude Code note. The Agent skill upstream boundary checkbox is unticked.

Resolution

Add an ELI5 section in plain language. Add a linked issue number in the 'Fixes #' line, or state that the PR is from a maintainer and no issue exists. Add Visual Proof as 'N/A' with a short reason. State the revert method in the Risk section. Explain why the chosen approach beats the alternatives. Explain why no test was added, given the template's test checkbox. Tick or address the unticked checklist and boundary items.

  • 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: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c03bd161-bb12-4520-89d2-cd786223c76b
Commits

Reviewing files that changed from the base of the PR and between 9945835 and 985377b.

Files selected for processing: 2

  • src/main/claude/hooks/claude-hook-decision-script.ts
  • src/main/codex/hooks/definitions/codex-hook-script.ts

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

@nwparker
nwparker merged commit 3458ac1 into main Nov 20, 2026
93 checks passed
@nwparker
nwparker deleted the nwparker/reduce-hooks branch November 20, 2026 08:21
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