Replace query() with ClaudeSDKClient for native session management#56
Replace query() with ClaudeSDKClient for native session management#56RichardAtCT merged 2 commits intomainfrom
Conversation
Swap the stateless query() function for per-request ClaudeSDKClient instances,
eliminating temp session IDs and the delete-old/save-new session swap pattern.
- sdk_integration.py: Use async with ClaudeSDKClient(options) + client.query()
+ client.receive_response() instead of query() async generator. Remove
active_sessions dict, _update_session(), _execute_query_with_streaming().
Use ResultMessage.result for content extraction with message fallback.
- session.py: New sessions created with session_id="" instead of temp_ prefix.
Storage save deferred until Claude responds. update_session() now takes
session object directly instead of session_id string.
- facade.py: Remove startswith("temp_") checks. Simplified post-execution
session update to single update_session(session, response) call.
- Tests updated for new ClaudeSDKClient mock pattern and session lifecycle.
|
PR Review Summary
What looks good
Issues / questions
Suggested tests (if needed)
Verdict
|
When Claude returns no session_id for a new session, log warnings in both the session manager and facade so the gap is diagnosable. Add tests covering the empty session_id path and fix a misleading comment in the eviction test.
Summary
query()for per-requestClaudeSDKClientinstances, eliminating temp session IDs (temp_*) and the delete-old/save-new session swap patternsession_id=""and deferred storage save until Claude responds with a real IDupdate_session()takes aClaudeSessionobject directly instead of a string ID, simplifying the facade's post-execution flowResultMessage.resultfor content extraction with fallback to message parsingTest plan
poetry run pytest tests/ -v)ResultMessage(not temp)options.resumecorrectly toClaudeSDKClientResultMessage.resultused when available, falls back to message extraction🤖 Generated with Claude Code