Unhandled EPIPE Error Causing Node.js Application Crash

Resolved 💬 30 comments Opened Jul 1, 2025 by pauloportella Closed Jul 3, 2025
💡 Likely answer: A maintainer (dicksontsai, collaborator) responded on this thread — see the highlighted reply below.

Bug Description
App is crashing
node:events:485
throw er; // Unhandled 'error' event
^

Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:87:19)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}

Node.js v24.0.1

Environment Info

  • Platform: darwin
  • Terminal: tmux
  • Version: 1.0.39
  • Feedback ID: 1b92f826-dc88-45a5-ba4d-f8504cb473bc

Errors

[{"error":"Error: Command failed: security find-generic-password -a $USER -w -s \"Claude Code\"\nsecurity: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.\n\n    at genericNodeError (node:internal/errors:983:15)\n    at wrappedFn (node:internal/errors:537:14)\n    at checkExecSyncError (node:child_process:891:11)\n    at execSync (node:child_process:963:15)\n    at JI (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:702:3921)\n    at file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:623:9038\n    at Q (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:526:13327)\n    at _X (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:623:8184)\n    at H_ (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:623:7265)\n    at T9 (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:623:11432)","timestamp":"2025-07-01T23:01:59.462Z"},{"error":"Error: Language not supported while highlighting code, falling back to markdown: \n    at wY (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1489:1184)\n    at file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1489:912\n    at Array.map (<anonymous>)\n    at AH (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1489:903)\n    at Object.renderToolResultMessage (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1495:933)\n    at jT2 (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1958:3255)\n    at ZU (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:65:19799)\n    at UP (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:42556)\n    at wP (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:38105)\n    at o$ (file:///Users/jrbaron/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:38033)","timestamp":"2025-07-01T23:02:00.631Z"}]

View original on GitHub ↗

30 Comments

dicksontsai collaborator · 1 year ago

Can you provide more details about when you encountered this crash? Was it during the agent loop, or in response to a certain slash command? Do you know when the crash started happening? Is it reproducible?

A number of other users have encountered this issue as well.

pauloportella · 1 year ago

Thanks for your response @dicksontsai, it happened a couple of times after using a write or edit tool. For more context, it was editing a sh file that was already hooked to a Post write/edit hook. It stopped happening on .40 or perhaps it was related to the hook not being setup correctly (Claude was debugging it)

zopu · 1 year ago

I'm also seeing this on darwin (MacOs 14.6.1) and tmux.

zopu · 1 year ago

NB removing the post write/edit hook I had setup has fixed the issue for me for now. Here's the hook definition I had been using in case that helps:

"PostToolUse": [
{
"matcher": "Edit|MultiEdit|Write",
"hooks": [
{
"type": "command",
"command": "bun run format && bun run lint && bun test"
}
]
}
]

adeleglise · 1 year ago

Same for me (MacOS 15.5), claude code 1.0.40 starting to happen after I added hooks for PostToolUse with a bash script.

node:events:485
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:87:19)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Node.js v23.10.0
markbastian · 1 year ago

I am also getting this:

node:events:492
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at __node_internal_errnoException (node:internal/errors:623:12)
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Node.js v20.5.1

It seems to have started with the introduction of a post edit hook:

      "PostToolUse": [
        {
          "matcher": "^(Edit|MultiEdit|Write|mcp__clojure-mcp__clojure_edit|mcp__clojure-mcp__clojure_edit_replace_sexp|mcp__clojure-mcp__file_edit|mcp__clojure-mcp__file_write)$",
          "hooks": [
            {
              "type": "command",
              "command": "cd emr && npm run parinfer -- '${TOOL_PARAMS.file_path}' || true"
            }
          ]
        }
      ]
hburrichter · 1 year ago

Same for me (MacOS 15.5), claude code 1.0.40:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit|NotebookEdit",
        "hooks": [
          {
            "type": "command",
            "command": "uv run ruff format && uv run ruff check --fix"
          }
        ]
      }
    ]
  }
}
node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:95:16)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Node.js v20.14.0
dicksontsai collaborator · 1 year ago

This issue should be fixed in v1.0.41 now. Please upgrade and report back if you see any issues.

krlvi · 1 year ago

@dicksontsai thank you for looking into this. Unfortunately I am still hitting this error
claude -v 1.0.41 (Claude Code)

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "echo 'Write hook fired' >> /Users/kiril/dbg.log"
          }
        ]
      }
    ]
  }
}
camwest · 1 year ago

Also experiencing this issue on v1.0.41.

Environment:

  • Claude Code: 1.0.41
  • Node.js: v20.18.1
  • Platform: macOS 15.5 (Darwin 24.5.0) on ARM64 (Apple Silicon)
  • Terminal: zsh 5.9

Error Details:
Same EPIPE error signature:

node:events:496
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:95:16)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Hook Configuration:
Using both PreToolUse and PostToolUse hooks:

  • PreToolUse: Branch protection script (runs on Bash commands)
  • PostToolUse: Code quality script that runs npx tsc --noEmit and yarn lint:fix (runs on Write/Edit/MultiEdit)

Reproduction:
Error occurs consistently when the PostToolUse hook runs after file edits. The issue disappears completely when commenting out the hooks configuration in .claude/settings.json.

Additional Context:
The PostToolUse hook script includes SIGPIPE handling (trap 'echo "{\"decision\": \"approve\"}" 2>/dev/null; exit 0' SIGPIPE) but the error still occurs, suggesting the issue is in Claude Code's hook execution pipeline rather than the hook scripts themselves.

dicksontsai collaborator · 1 year ago

I am having trouble reproducing the issue, though it still seems to be happening consistently for some reason. If you are willing to report your session with /bug, that will help me out. Thanks!

camwest · 1 year ago
I am having trouble reproducing the issue, though it still seems to be happening consistently for some reason. If you are willing to report your session with /bug, that will help me out. Thanks!

Bug Description
throw er; // Unhandled 'error' event

Environment Info

  • Platform: darwin
  • Terminal: WarpTerminal
  • Version: 1.0.41
  • Feedback ID: b46c4c92-d6b0-4eb1-86fa-9b6d60309de0

Errors

[]
dicksontsai collaborator · 1 year ago

Ok, I was able to get a repro and can confirm that the fix in v1.0.41 was insufficient.

krlvi · 1 year ago

@dicksontsai not sure if this is helpful but it appears that it does not crash with the same scenario but under a Linux VM. Could this be platform (Mac) specific?

dicksontsai collaborator · 1 year ago

There could be platform differences in how stdin flushing is handled. The EPIPE error comes from Claude Code trying to flush the hook input to stdin even after the child process itself has finished. The code did not handle this error properly. This will be fixed in the next release.

hiroka · 1 year ago

## Additional confirmation of the issue

I'm experiencing the same EPIPE error after updating to the latest
ClaudeCode version.

Environment:

  • OS: macOS (Darwin 24.5.0)
  • ClaudeCode Version: 1.0.41
  • Node.js Version: v20.18.3

Error:
Same error as reported above - crashes during operation with work in
progress lost.

Temporary fix applied:
Following the suggestion in this thread, I've disabled PostToolUse hooks
in ~/.claude/settings.json and will test if this resolves the issue.

Status: Testing the workaround, will update if the issue persists.

Thank you for the quick fix in v1.0.41!

pauloportella · 1 year ago

I reencountered the issue when I asked Claude to move some project hooks to the Claude user folder.

Issue Summary ClaudeCode Version: 1.0.41

Claude Code crashes when hook files are deleted before removing their references from settings.json

Steps to Reproduce

  1. Have a hook configured in .claude/settings.json or ~/.claude/settings.json
  2. Delete the hook file (e.g., rm ~/.claude/hooks/my-hook.py)
  3. Claude Code will crash when trying to execute the missing hook

Expected Behavior

Claude Code should handle missing hook files gracefully with an error message rather than crashing

dicksontsai collaborator · 1 year ago

@pauloportella The fix for EPIPE is coming out in the next release, so it's possible that you're encountering the same issue unrelated to the missing references. For reference, here is what the output looks like if a hook file is missing. The error should be non-blocking.

> Write a coding tip to coding_tips.md

⏺ I'll create a coding tips file with a useful tip.

⏺ Read(coding_tips.md)
  ⎿  Read 9 lines (ctrl+r to expand)

⏺ Update(coding_tips.md)
  ⎿  Updated coding_tips.md with 2 additions and 1 removal

PostToolUse:Edit [/Users/dickson/sandbox/.claude/hooks/foo.sh] failed with non-blocking status code 127: /bin/sh:
/Users/dickson/sandbox/.claude/hooks/foo.sh: No such file or directory

⏺ Added a new tip about separation of concerns to the existing coding tips file.
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit|NotebookEdit",
        "hooks": [
            "type": "command",
            "command": "/Users/dickson/sandbox/.claude/hooks/foo.sh"
          }
        ]
      }
    ]
  }
dicksontsai collaborator · 1 year ago

The new release v1.0.43 is now out.

dhrgusdlrns · 1 year ago

It seems like that the update made hook system crazy.
Something about config.json went wrong and eats usage quickly.

dicksontsai collaborator · 1 year ago

@dhrgusdlrns You can review claude --debug and/or transcript mode (ctrl-r) to see which hooks are triggering. The only hooks change between 1.0.41 and 1.0.43 was this fix.

camwest · 1 year ago

FWIW 1.0.43 works great for me now.

dhrgusdlrns · 1 year ago
@dhrgusdlrns You can review claude --debug and/or transcript mode (ctrl-r) to see which hooks are triggering. The only hooks change between 1.0.41 and 1.0.43 was this fix.

I watched it with debug mode. I'm not sure about what is really happening, but it seems like even I don't have any hook, but CC repeatedly tries to use hook and watch and edit config.json file whenever CC uses any tool. I didn't feel something was wrong before the update with debug mode, but now it shows too many debug log whenever I do something. I'm sure that I don't feel this weird feeling since I've used CC.
If you need a detailed log or something, please tell me, I'll show you.
I guess it happened after the update, or I removed the json settings with exit option 2

dicksontsai collaborator · 1 year ago

Why don't you file a new issue with your log and your configuration setup? What you're seeing is unrelated to this issue.

dhrgusdlrns · 1 year ago
Why don't you file a new issue with your log and your configuration setup? What you're seeing is unrelated to this issue.

Oh, I reviewd. my session by reading jsonl and I found something not related with hooks infused 50000 token.
Yes, you were right, it seems doesn't related with this issue, sorry.

DanielMorales9 · 12 months ago

Hi 👋
I am getting the same but could not fix:

node:events:485
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:87:19)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Node.js v23.6.0
1.0.55 (Claude Code)

hiroka · 12 months ago

I was experiencing the same EPIPE error with v1.0.55, but downgrading to v1.0.52 resolved the issue for me:

npm uninstall -g @anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-code@1.0.52

Environment:

macOS

Node.js v20.19.4 (also tested with v22.17.1)

Using global installation

The error completely disappeared after downgrading. Hope this helps others!

kristopherlarson · 12 months ago

Same issue with yesterdays upddate. Has made claude unsuable as it crashes every few minutes.

dicksontsai collaborator · 12 months ago

The cause of the latest crashes is different. We are tracking it in #3891

github-actions[bot] · 11 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.