[Feature Request] Preserve CLI Tool Sessions (Claude Code, Codex CLI, etc.) Across WSL Reconnection After Sleep/Hibernate
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
# [Feature Request] Preserve CLI Tool Sessions (Claude Code, Codex CLI, etc.) Across WSL Reconnection After Sleep/Hibernate
## Problem Statement
When developing inside WSL (Windows Subsystem for Linux) using VS Code's Remote - WSL extension, there is a significant workflow disruption caused by the following sequence:
1. A developer uses **AI-assisted CLI tools** (e.g., Claude Code, OpenAI Codex CLI, Gemini CLI) inside the WSL terminal within VS Code.
2. These tools maintain long-running **conversation/session state** — a single workday often involves one or two continuous sessions that carry hours of context, decisions, and incremental progress.
3. The developer needs to **sleep or hibernate** the Windows machine at the end of the day (or during breaks), as the work spans multiple days.
4. Upon waking the machine, **WSL disconnects** from the Windows host. The VS Code remote connection is lost and must be re-established manually.
5. After VS Code reconnects to WSL, **all previously running CLI tool processes are dead**. Their session histories, though usually persisted to disk, cannot be resumed — the tools start a new session with no memory of prior conversation.
**Current workarounds are inadequate:**
- Manually copying session IDs or critical context before sleep is fragile and easily forgotten.
- Keeping the machine awake for days wastes power and is impractical.
- Some tools (like Claude Code) support session resume via a `--resume` flag and a session ID, but there is no mechanism to **automatically recover** these sessions after an unexpected process termination caused by WSL disconnection.
## Proposed Solution
VS Code's Remote - WSL extension should **monitor and preserve the session state of long-running CLI tools** in the WSL terminal, and **automatically restore** them when the WSL connection is re-established after an interruption (sleep/hibernation).
### Specific capabilities:
1. **Session Detection & Caching**
- Detect well-known AI/assistive CLI tools (Claude Code, Codex CLI, Gemini CLI, etc.) that expose a `--resume` or session-recovery mechanism.
- Before WSL disconnects (triggered by host sleep/hibernation), capture each tool's current **session ID / conversation handle** and **working directory**, and write them to a well-known cache file on the Windows host filesystem (e.g., `%LOCALAPPDATA%\Microsoft\VS Code\WSL\session-cache.json`).
2. **Automatic Resume on Reconnection**
- When VS Code reconnects to the same WSL distro after a sleep/wake cycle, read the cache file.
- For each cached session, open a new terminal in the original working directory and run the tool's resume command (e.g., `claude --resume `).
3. **Extension API / Hooks**
- Expose a VS Code extension API or lifecycle hooks for `onRemoteDisconnect` and `onRemoteReconnect`, so third-party extensions can integrate their own session-preservation logic.
### Example cache format:
```json
{
"version": 1,
"wslDistro": "Ubuntu-22.04",
"sessions": [
{
"tool": "claude-code",
"sessionId": "abc123-def456",
"workingDirectory": "/home/user/projects/my-app",
"timestamp": "2026-07-21T18:30:00Z"
},
{
"tool": "codex-cli",
"sessionId": "sess_789012",
"workingDirectory": "/home/user/projects/my-api",
"timestamp": "2026-07-21T19:15:00Z"
}
]
}
```
## Why This Matters
- **Work continuity**: AI coding assistants have become a primary development interface. Losing a session means losing hours of conversation context, decisions, and partially-finished refactoring work.
- **Multi-day workflows**: Real-world development rarely fits into a single uninterrupted session. The inability to resume after sleep fragments work and reduces the practical value of these tools.
- **Existing tool capability**: Many CLI tools already support session resume (`--resume`), but the *orchestration layer* (VS Code + WSL) lacks the glue to use it across disconnects.
- **Low engineering cost**: This is primarily about capturing a few environment variables and session IDs before a well-known lifecycle event (sleep/hibernation), and replaying them after reconnection.
## Alternatives Considered
- **Windows-side terminal (cl.exe, etc.)**: Avoids WSL disconnection entirely, but forces developers to give up the native Linux development environment that WSL provides.
- **Third-party session managers (`tmux`, `screen`)**: These persist terminal sessions within WSL, but are killed when WSL itself terminates on host sleep. WSL 2 does not survive host suspend.
- **Manual session ID bookkeeping**: Individual users can work around the issue, but this should be solved at the platform level for all VS Code + WSL developers.
## Environment
- **VS Code**: Latest stable
- **Extension**: Remote - WSL (ms-vscode-remote.remote-wsl)
- **WSL Version**: WSL 2
- **Host OS**: Windows 11
- **Target Tools**: Claude Code, OpenAI Codex CLI, Gemini CLI, and any CLI tool with `--resume` / session recovery support
Contributor guide
Assessment
This issue has not been assessed yet.