File descriptors to serial ports (/dev/ttyUSB*) not properly closed after bash command execution
Resolved 💬 2 comments Opened Jan 13, 2026 by pguinet Closed Feb 26, 2026
Description
When Claude Code executes bash commands that access serial ports (e.g., /dev/ttyUSB0), the file descriptors are not properly closed after the command completes. This causes the Claude Code process to hang indefinitely, requiring a kill -9 to terminate.
Steps to reproduce
- Connect an Arduino/ESP device to
/dev/ttyUSB0 - Ask Claude to read serial output using direct bash commands:
``bash``
cat /dev/ttyUSB0
# or
stty -F /dev/ttyUSB0 115200 raw -echo
- Even with
timeout, the Claude process keeps the fd open and becomes unresponsive
Observed behavior
- The bash command completes (timeout works, no child process remains)
- But Claude Code keeps the file descriptor to
/dev/ttyUSB0open - The process enters sleeping state (
wait_woken) and never recovers lsof /dev/ttyUSB0shows the Claude process still holding the fd- Only
kill -9can terminate the session
Diagnostic info
$ cat /proc/<pid>/status | grep State
State: S (sleeping)
$ cat /proc/<pid>/wchan
wait_woken
$ lsof /dev/ttyUSB0
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
claude <pid> user 22r CHR 188,0 0t0 868 /dev/ttyUSB0
Environment
- Claude Code version: 2.1.6
- OS: Linux (openSUSE Tumbleweed)
- Device: ESP8266 on /dev/ttyUSB0
Workaround
Avoid direct bash access to serial ports. Use arduino-cli monitor with timeout instead, which seems to work correctly:
timeout 30 arduino-cli monitor -p /dev/ttyUSB0 -c baudrate=115200This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗