feat(cli): persist Claude session mappings across restarts#51
Open
2yclaw wants to merge 1 commit intofastclaw-ai:mainfrom
Open
feat(cli): persist Claude session mappings across restarts#512yclaw wants to merge 1 commit intofastclaw-ai:mainfrom
2yclaw wants to merge 1 commit intofastclaw-ai:mainfrom
Conversation
Claude CLI sessions survive on disk (~/.claude/projects/), but the conversationID→sessionID mapping in CLIAgent was only held in memory. After a weclaw restart, users lost their conversation context even though the Claude session still existed. This change adds load/save logic for the sessions map: - On startup: load from ~/.weclaw/sessions.json - On session update or reset: write back to disk - Keyed by agent name to support multiple CLI agents - Atomic write (tmp + rename) to prevent corruption on crash - Corrupt file detection: refuses to overwrite if JSON is malformed - Graceful degradation: if persistence fails, falls back to current behavior Only affects CLI agents that use --resume (currently Claude). ACP and HTTP agents are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
conversationID → sessionIDmappings to~/.weclaw/sessions.json--resumeworks across weclaw restartsProblem
Claude CLI sessions are stored on disk by Claude Code (
~/.claude/projects/), but weclaw's in-memorysessions map[string]stringis lost on restart. Afterweclaw restart, users start a new conversation even though the Claude session still exists — losing all context.Solution
Add
loadSessions()/saveSessions()toCLIAgentwith these properties:map[agentName]map[conversationID]sessionID— supports multiple CLI agentsos.Renameto prevent corruption on crash--resumeIDs gracefully (auto-creates new session), so no TTL neededOnly affects CLI agents that use
--resume(currently Claude). ACP and HTTP agents are unchanged.Changes
agent/cli_agent.go: +86 lines, 1 file changedTest plan
go build ./...— compiles cleanlygo vet ./...— no warnings~/.weclaw/sessions.jsoncreatedweclaw restart→ send message → verify log showsresuming sessionwith same session IDweclaw restart→ verifyloaded N session(s) for claudein log