Skip to content

feat: sync daemon session with active Claude Code terminal windows#45

Open
alexflorisca wants to merge 2 commits intomoazbuilds:masterfrom
alexflorisca:feat/session-sync
Open

feat: sync daemon session with active Claude Code terminal windows#45
alexflorisca wants to merge 2 commits intomoazbuilds:masterfrom
alexflorisca:feat/session-sync

Conversation

@alexflorisca
Copy link
Copy Markdown

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:

  • Before each execution, claudeclaw scans ~/.claude/projects/<project>/ for .jsonl session files (Claude Code's native session storage)
  • If the most recently modified session file is newer than claudeclaw's own lastUsedAt timestamp, claudeclaw adopts that session ID
  • All subsequent Telegram/Discord messages then --resume the same thread the user was just in from their terminal, and vice versa
  • On daemon startup, if a terminal session already exists, bootstrap skips creating a new session and joins the active one instead

The sync is transparent — a log line is printed when a session switch occurs, and no configuration is needed.

Test plan

  • Start a Claude Code terminal session in a project (claude or claude --resume)
  • Start claudeclaw daemon in the same project directory
  • Send a Telegram/Discord message — confirm the daemon continues the terminal conversation context
  • Do work in the terminal after the daemon runs — confirm the next Telegram message picks it back up
  • Verify daemon log shows Session sync: adopting terminal session <id>... when a switch occurs
  • Verify no change in behaviour when no terminal session exists (fresh project)

🤖 Generated with Claude Code

alexflorisca and others added 2 commits March 17, 2026 22:59
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>
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.

Sync deamon with all chat windows

1 participant