[BUG] claude -p prints lines that cannot be redirected to stdout or stderr
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
This is a cosmetic issue: Running "claude -p" prints unnecesarry blank lines. Below is the cause of the issue claude code detected about its own behaviour:
---
Found it! Look at this line near the end:
write(1, "It's currently 2026-01-10 (Janua"..., 208It's currently 2026-01-10 (January 10th, 2026).
The claude CLI is writing directly to file descriptor 1 (stdout) with write(1, ...) - this is a direct system call that bypasses shell redirections!
Before that write, there are likely write(1, "\n", 1) calls (writing newlines) that aren't shown in your filtered output.
To see the newline writes, run:
bashstrace -e write=1 claude -p --model=haiku "what time is it" 2>&1 | grep 'write(1'
The claude binary is using raw system calls to write directly to file descriptor 1, which means standard shell redirections won't work. You'd need to close/redirect FD 1 at the file descriptor level before launching the process, not just with shell redirections.
The only real solution: live with the empty lines - they appear on the terminal but won't be in your captured output variable.
What Should Happen?
claude -p --model=haiku "what time is it" 2>&1 > /dev/null
should have no output.
Error Messages/Logs
Steps to Reproduce
claude -p --model=haiku "what time is it" 2>&1 > /dev/null
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗