Skip to content

bug: claude-code-acp causes infinite recursion when used as csa review tool #272

@RyderFreeman4Logos

Description

@RyderFreeman4Logos

Summary

When csa review --branch main selects claude-code as the review tool, the spawned claude-code-acp sub-agent reads the project's CLAUDE.md/AGENTS.md rules which contain "MUST use csa review" directives, causing it to invoke csa run inside Bash — creating an infinite recursion loop.

Reproduction

cd /path/to/project  # with CLAUDE.md containing CSA delegation rules
csa review --branch main
# Result: exit 143 (SIGTERM), zero stdout output

Root Cause Analysis (via strace)

Fault Chain

csa review --branch main
  └─ selects tool: claude-code (claude-code-acp)
     └─ claude-code-acp starts, reads CLAUDE.md/AGENTS.md
        └─ Turn 1: git log, git diff (normal)
        └─ Turn 2: Bash("csa run --tool auto \"Review...\"")  ← RECURSION
           └─ csa run spawns another sub-process...
              └─ parent csa idle-timeout triggers SIGTERM
                 └─ claude-code-acp stderr write → EPIPE (pipe closed)
                    └─ Node.js unhandled 'error' event at utils.js:50
                       └─ Process exits with code 143

Evidence from strace

  1. Successful exec: claude-code-acp starts via systemd-run --user --scope
  2. JSONRPC output: 362 write(1,...) calls — sub-agent is actively working
  3. Recursive csa run invocation found: claude-code-acp calls Bash("csa run --tool auto \"You are performing a comprehensive code review...\"")
  4. EPIPE on stderr: node:events:486 throw er; Error: write EPIPE at ...utils.js:50:28
  5. Final status: termination_reason = "sigterm", exit_code = 143

Impact

  • csa review is completely non-functional for projects with CSA delegation rules in CLAUDE.md
  • Zero output returned to caller — silent failure with no diagnostic information
  • User sees only exit code 144 or 143 with empty stdout/stderr

Suggested Fixes

Fix 1: Anti-recursion environment variable (recommended)

Set CSA_IN_SUBPROCESS=1 (or similar) when spawning sub-tools. claude-code-acp (and other tools) should check this env var and skip CSA-related rules/invocations.

Fix 2: Instruction injection for claude-code tool

When csa review spawns claude-code-acp, prepend to the system prompt:

CRITICAL: You are running INSIDE a CSA subprocess. Do NOT invoke `csa run`, `csa review`, or `csa debate` — this would cause infinite recursion.

Fix 3: Capture and report EPIPE errors

Currently, when claude-code-acp crashes with EPIPE, CSA reports a generic SIGTERM with zero output. The EPIPE error message should be captured and included in the error report.

Environment

  • csa 0.1.43 (v0.1.15-38-g718232d-dirty)
  • claude-code-acp via @zed-industries/claude-code-acp
  • Node.js v24.14.0 / v25.6.1
  • Linux 6.1.0-43-amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions