Skip to content

Conversation

@ltawfik
Copy link
Collaborator

@ltawfik ltawfik commented Jul 2, 2025

Summary

Fixes #30 - When permission_mode='bypassPermissions' fails, users experience a silent failure where their async iterator completes without yielding any messages.

Problem

Users report "no response is received and the program terminates" when using bypassPermissions. The async for loop completes without executing its body, making it appear as if nothing happened.

Root Causes

  1. CLI version incompatibility - Older CLIs don't recognize --permission-mode flag
  2. Root user restriction - Security check prevents bypassPermissions when running as root
  3. Disabled in settings - Falls back to interactive mode when disabled
  4. Other security restrictions - Various scenarios causing the CLI to exit without output

Solution

This PR adds comprehensive error detection that transforms silent failures into clear, actionable error messages:

  • Tracks whether ANY output was received (_received_any_output)
  • Checks stderr for specific error patterns
  • Provides different error messages for different failure modes
  • Adds --debug flag for bypassPermissions to capture more diagnostics
  • Updates entrypoint to 'sdk-cli' for better CLI integration

Changes

  • subprocess_cli.py: Enhanced error detection and reporting
  • test_transport.py: Added comprehensive tests for all failure scenarios

Test Plan

  • Added unit tests for all error scenarios
  • Manually tested with old CLI version
  • Verified error messages are clear and actionable
  • All existing tests pass

Example

Before (silent failure):

async for message in query(prompt="test", options=ClaudeCodeOptions(permission_mode="bypassPermissions")):
    print("Got message\!")  # This never executes, confusing users

After (clear error):

ProcessError: Claude Code CLI terminated without producing any output when using bypassPermissions mode. This can happen when:
1. Running as root/sudo (security restriction)
2. bypassPermissions is disabled in settings
3. Other security restrictions are in place

Try using permission_mode='acceptEdits' instead, which is the recommended mode for SDK usage.

🤖 Generated with Claude Code

When permission_mode='bypassPermissions' is used but the CLI cannot
honor it (due to root user, disabled settings, or CLI version issues),
the SDK would fail silently - the async iterator would complete without
yielding any messages, appearing as "no response" to users.

This commit adds comprehensive error detection:
- Tracks whether any output was received from the CLI
- Detects specific error messages in stderr
- Provides clear, actionable error messages for each failure mode
- Adds --debug flag when using bypassPermissions for better diagnostics
- Updates entrypoint to 'sdk-cli' for better CLI integration

The fix transforms silent failures into helpful errors that explain
what went wrong and how to fix it.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ltawfik ltawfik closed this Jul 2, 2025
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.

ClaudeCodeOptions: bypassPermissions causes silent failure with no response

2 participants