Skip to content

Add option to persist session after claude code disconnects - #34

Open
TristanFloch wants to merge 1 commit into
stevemolitor:mainfrom
TristanFloch:feat/persist-sessions
Open

Add option to persist session after claude code disconnects#34
TristanFloch wants to merge 1 commit into
stevemolitor:mainfrom
TristanFloch:feat/persist-sessions

Conversation

@TristanFloch

@TristanFloch TristanFloch commented Jan 20, 2026

Copy link
Copy Markdown

Summary

Add monet-persist-sessions option to keep sessions alive after Claude Code
disconnects, allowing reconnection without restarting the server.

Problem

Closes #33.

When Claude Code disconnects (e.g., exiting the CLI), the monet session is
automatically cleaned up. Users who frequently restart Claude Code sessions while
keeping Emacs running must manually restart the monet server each time before
reconnecting.

Solution

Add a new customizable variable monet-persist-sessions (default nil) that, when
enabled, keeps the websocket server running after Claude disconnects. The session
remains available for a new Claude Code session to reconnect via /ide.

Usage

(setq monet-persist-sessions t)

Test plan

I first set up my Doom Emacs configuration to use this option: link to the exact line.

While multiple monet servers are running on different directories:

  • Start a monet server for a new project directory using monet-start-server
  • Connect to that server using /ide in Claude Code (using a standalone terminal)
  • Terminate the Claude Code session using Ctrl+C Ctrl+C
  • Check the monet session is still running using monet-list-sessions:
    doom                 Port: 11617 Connected: No  Initialized: Yes  Directory: /Users/myuser/myproject/
    
  • Restart Claude Code in the same directory using ENABLE_IDE_INTEGRATION=t claude and check it connected to the right session
  • Double check the monet sessions list:
    doom                 Port: 11617 Connected: Yes Initialized: Yes  Directory: /Users/myuser/myproject/
    

@TristanFloch
TristanFloch marked this pull request as ready for review January 20, 2026 14:05
@stevemolitor

stevemolitor commented Apr 19, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR — the core idea is reasonable and the implementation is clean (lockfile stays in place, client cleared to nil, hooks preserved so reconnection can work).

Two things before I can merge:

  1. Verify reconnection works end-to-end. The PR keeps the session alive, but I want to confirm Claude CLI's /ide actually reattaches to the same session (and that Monet's state — opened diffs, deferred responses, etc. — is in a sane state across the disconnect). Does this work:

    • Start Claude with monet-persist-sessions = t
    • Do some work (open a file, get a diff)
    • Disconnect Claude
    • Start a fresh Claude CLI, /ide → reconnect to the same Monet server
    • Confirm subsequent tool calls work (e.g. a new openFile or selection mention)

    I just want to be sure we're not keeping a partially-broken session around that then fails on reconnect.

  2. Minor: the monet-persist-sessions docstring second line exceeds ~80 cols — could you wrap it? Example:

    (defcustom monet-persist-sessions nil
      "When non-nil, keep sessions alive after Claude Code disconnects.
    Sessions will persist until manually stopped with `monet-stop-server'
    or until Emacs exits.  This allows reconnecting to the same server
    with a new Claude Code session."
      :type 'boolean
      :group 'monet)

Once those are squared away I'm happy to merge. Thanks!

@TristanFloch
TristanFloch force-pushed the feat/persist-sessions branch from 02239ea to d48ec6c Compare May 19, 2026 15:51
@TristanFloch

Copy link
Copy Markdown
Author

Hey @stevemolitor, thank you for taking a look.

  1. I just tested your scenario and it works fine!
  2. Edited the comment ✔️

I'll let you merge if everything else looks good. Thanks!

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.

Add option to persist server sessions after Claude Code disconnects

2 participants