Skip to content

Fix: route ANTHROPIC_LOG=debug output to stderr#235

Open
joaquinhuigomez wants to merge 1 commit intoanthropics:mainfrom
joaquinhuigomez:fix/stderr-debug-logging
Open

Fix: route ANTHROPIC_LOG=debug output to stderr#235
joaquinhuigomez wants to merge 1 commit intoanthropics:mainfrom
joaquinhuigomez:fix/stderr-debug-logging

Conversation

@joaquinhuigomez
Copy link
Copy Markdown

@joaquinhuigomez joaquinhuigomez commented Mar 17, 2026

No description provided.

When ANTHROPIC_LOG=debug is set, the Anthropic HTTP client logs debug
output via console.log(), which writes to stdout. This corrupts the
JSON protocol used for parent-child process communication in the SDK.

The fix: replace the default `console` logger with a stderr-based
logger when the client runs inside the SDK subprocess. The logger
interface (log, warn, error) is preserved but all output routes to
process.stderr instead of process.stdout.

Affected code in the Anthropic client constructor (cli.js):
  BEFORE: this.logger = options.logger ?? console
  AFTER:  this.logger = options.logger ?? stderrLogger

Includes a test that verifies debug logging does not leak to stdout.

Fixes anthropics#157
@joaquinhuigomez joaquinhuigomez force-pushed the fix/stderr-debug-logging branch from a1ba724 to 238cadd Compare March 28, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants