Skip to content

rtk-rewrite.sh PreToolUse hook causes EAGAIN (posix_spawn resource exhaustion) under heavy tool use #968

Closed

Description

@waynehoover

Bug

The rtk-rewrite.sh PreToolUse hook causes EAGAIN: resource temporarily unavailable, posix_spawn '/bin/sh' errors when Claude Code is making rapid Bash tool calls.

Root cause

The hook runs on every Bash tool invocation and spawns multiple child processes:

/bin/sh → rtk-rewrite.sh → jq (×3) + rtk rewrite + grep + cut

Under heavy tool use (e.g., parallel agent calls, rapid-fire commands), this saturates the OS process spawn capacity momentarily, causing posix_spawn to fail with EAGAIN.

Environment

  • macOS 15 (Darwin 25.3.0), Apple Silicon
  • Claude Code (CLI)
  • rtk installed via cargo
  • ulimit -u = 8000, kern.maxproc = 12000

Reproduction

  1. Configure the rtk-rewrite hook per the docs
  2. Run a Claude Code session with heavy Bash tool use (e.g., launching background tasks, parallel searches, agent subprocesses)
  3. Intermittent EAGAIN: resource temporarily unavailable, posix_spawn '/bin/sh' errors appear

Suggestion

Consider one or more of:

  1. Cache the rtk --version check — the version guard runs rtk --version | grep | cut on every invocation. This could be checked once and cached in a file.
  2. Combine the jq calls — the script calls jq 3 separate times (parse input, build updated input, build output). These could be a single jq invocation.
  3. Use a long-running sidecar instead of spawning fresh processes per hook invocation — e.g., a simple socket/pipe server that the hook script queries.
  4. Rate-limit or debounce — if the same command pattern was just checked, skip the rewrite.

Activity

  1. added 4 commits that reference this issue on Apr 2, 2026
    2358105
    f7f5b93
    b3a7e75
    74a1fd2
  2. self-assigned this
    on Apr 2, 2026
  3. added
    bug
    effort-medium
    on Apr 4, 2026
  4. pszymkowiak commented on Apr 4, 2026

    @pszymkowiak
    Collaborator

    [w] wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 92%

    Summary

    PreToolUse hook spawns too many child processes per invocation, causing EAGAIN under heavy parallel tool use; PRs #970 and #956 already in progress to address this.

    📁 Relevant files
    • rtk-rewrite.sh

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  5. pszymkowiak commented on Apr 12, 2026

    @pszymkowiak
    Collaborator

    This will be fixed by #956 which replaces the bash hook chain (/bin/sh → rtk-rewrite.sh → jq ×3 + grep + cut) with a single native Rust binary: rtk hook claude.

    One process instead of ~6 per hook invocation — no more posix_spawn saturation under parallel agent use.

  6. added 4 commits that reference this issue on May 14, 2026
    06b8c29
    70a8249
    6ed4b91
    a0e7c24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugeffort-medium

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions