Skip to content

Conversation

@randombet
Copy link

Current ClaudeSDKClient is base on subprocess and once subprocess is dead or quit unexpectedly. We will lose the session info.
SessionPersistentClient leverages ClaudeSDKClient and auto save and persist session data on local file.

@dicksontsai
Copy link
Collaborator

Thanks for this PR. I think we should just build this resilience into the default ClaudeSDKClient itself by leveraging the resume option. That way, we can avoid having to duplicate the conversation history storage (once here, once within Claude Code)

@randombet
Copy link
Author

Thanks for this PR. I think we should just build this resilience into the default ClaudeSDKClient itself by leveraging the resume option. That way, we can avoid having to duplicate the conversation history storage (once here, once within Claude Code)

By "once within Claude Code", you mean on the server side, right? In that case, we still need session info (e.g session id, cost etc) on client side. LMK what do you think? @dicksontsai

@EdanStarfire
Copy link

For reference, the init messages received right at the start of the SDK agent running have a sessionID and that can be used to resume sessions. BUT - when you use the built-in resume functionality, you pass it the OLD sessionID and you get a NEW one. So you have to capture that and remember that the new SessionID is the new session if you need to re-resume again. I've tested this extensively over a large batch of tools, and it's been rock solid.

I have an example of capturing and updating the claude code session ID for being able to resume here:
https://github.com/EdanStarfire/claudecode_webui/blob/main/src/claude_sdk.py#L706-L722

and this is me passing the session ID for resumption when creating the agent.
https://github.com/EdanStarfire/claudecode_webui/blob/main/src/claude_sdk.py#L674-L676

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