Skip to content

Conversation

@dicksontsai
Copy link
Collaborator

Summary

  • Adds set_permission_mode() method to dynamically change permission modes during streaming sessions
  • Adds set_model() method to switch AI models mid-conversation
  • Implements control protocol support matching the TypeScript SDK's capabilities

Motivation

The TypeScript SDK supports dynamic control through setPermissionMode() and setModel() methods on the Query interface. This PR brings the same functionality to the Python SDK, allowing users to:

  1. Start with restrictive permissions for code review, then switch to acceptEdits for implementation
  2. Use different models for different parts of a task (e.g., Sonnet for complex analysis, Haiku for simple tasks)
  3. Adjust permissions based on workflow needs without restarting sessions

Changes

  • ClaudeSDKClient: Added set_permission_mode(mode) and set_model(model) methods
  • Internal Query class: Added set_model(model) method to send control requests
  • E2E tests: Added comprehensive tests verifying the functionality works with real API calls

Test Plan

  • All existing unit tests pass (102 tests)
  • New E2E tests added and passing:
    • test_set_permission_mode: Verifies permission mode changes take effect
    • test_set_model: Confirms model switching works mid-conversation
    • test_interrupt: Validates interrupt capability
  • Type checking passes (mypy)
  • Linting passes (ruff)

Usage Example

async with ClaudeSDKClient() as client:
    # Start with default permissions for review
    await client.query("Analyze this code for issues")
    
    # Switch to auto-accept edits for implementation
    await client.set_permission_mode('acceptEdits')
    await client.query("Now fix the issues we found")
    
    # Use a different model for simpler tasks
    await client.set_model('claude-3-5-haiku-20241022')
    await client.query("Add a simple docstring")

🤖 Generated with Claude Code

Add methods to dynamically change permission mode and model during streaming sessions:
- set_permission_mode(): Switch between default, acceptEdits, and bypassPermissions
- set_model(): Change AI model mid-conversation (e.g., switch to Haiku for simpler tasks)

These features match the TypeScript SDK's setPermissionMode() and setModel() capabilities,
allowing users to adjust permissions and models based on workflow needs without restarting.

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

Co-Authored-By: Claude <[email protected]>
ashwin-ant
ashwin-ant previously approved these changes Sep 27, 2025
ashwin-ant
ashwin-ant previously approved these changes Sep 27, 2025
@dicksontsai dicksontsai merged commit 62289d2 into main Sep 28, 2025
25 of 26 checks passed
@dicksontsai dicksontsai deleted the ccpy branch September 28, 2025 21:09
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.

3 participants