feat: sync daemon session with active Claude Code terminal windows#45
Open
alexflorisca wants to merge 2 commits intomoazbuilds:masterfrom
Open
feat: sync daemon session with active Claude Code terminal windows#45alexflorisca wants to merge 2 commits intomoazbuilds:masterfrom
alexflorisca wants to merge 2 commits intomoazbuilds:masterfrom
Conversation
When a user is chatting in their terminal with Claude Code while the daemon also serves Telegram/Discord, the two chat windows use separate sessions and have no shared context. This adds automatic session detection: before each execution, claudeclaw scans ~/.claude/projects/<project>/ for .jsonl session files and adopts the most recently active one if it's newer than claudeclaw's own lastUsedAt timestamp. This means Telegram and Discord messages continue the same conversation thread the user was just having in their terminal, and vice versa. The session is also picked up on daemon startup (bootstrap skips creating a new session when a terminal session already exists), so switching between interfaces is coherent from the first message. Closes moazbuilds#39 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Fixes #39
When a user is actively chatting in a Claude Code terminal session while the daemon is also serving Telegram or Discord, the two windows are disconnected — each has its own conversation context and neither knows what the other is doing.
This PR adds automatic terminal session detection:
~/.claude/projects/<project>/for.jsonlsession files (Claude Code's native session storage)lastUsedAttimestamp, claudeclaw adopts that session ID--resumethe same thread the user was just in from their terminal, and vice versaThe sync is transparent — a log line is printed when a session switch occurs, and no configuration is needed.
Test plan
claudeorclaude --resume)Session sync: adopting terminal session <id>...when a switch occurs🤖 Generated with Claude Code