[Feature Request] Add clear_context() method to ClaudeSDKClient for context reset without reconnection
Resolved 💬 3 comments Opened Feb 10, 2026 by cdxiaodong Closed Feb 13, 2026
Problem
When using ClaudeSDKClient in a long-running/daemon process, there is no way to reset conversation context while keeping the connection alive. The only workaround is disconnect() + creating a new ClaudeSDKClient, which incurs 2-5 seconds startup overhead per request due to CLI subprocess initialization.
Proposed Solution
Add a clear_context() method that resets conversation history while keeping the connection alive:
async with ClaudeSDKClient(options=options) as client:
await client.query("Task 1...")
await collect_response(client)
# Clear context, keep connection alive
await client.clear_context()
# Fresh context, no memory of Task 1
await client.query("Task 2...")
Implementation Suggestion
Add a new control request subtype "clear_context" in the control protocol, similar to existing "interrupt", "set_model", etc:
{
"type": "control_request",
"request": { "subtype": "clear_context" }
}
Use Cases
- API Gateway / Service Mode: A single long-running process handling multiple independent user requests
- Batch Processing: Processing multiple unrelated tasks without context leakage
- Multi-tenant Applications: Ensuring user A's data doesn't leak to user B
Current Workaround
# Slow: ~3-5 seconds per request due to CLI startup
for request in requests:
async with ClaudeSDKClient(options=options) as client:
await client.query(request)
Environment
- SDK Version: 0.1.33
- CLI Version: 2.1.37
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗