microsoft / microsoft/vscode

Agent host: Delete... on a Claude session doesn't delete the SDK transcript — session resurrects on next list refresh

Open
#325,673 1 comment 0 reactions 1 assignee Claimed by @roblourens View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Type: Bug

### Summary

For **agent host** Claude sessions, right-click → **"Delete..."** appears to work (confirmation dialog, session disappears from the sidebar) — but the session **resurrects on the next session-list refresh or window reload**, with its custom title and read/archived state wiped.

This is the agent-host sibling of #313072 (which tracks the extension-host `claude-code://` variant, a silent no-op). The agent-host variant is arguably worse because it *looks* like it worked, destroys the user's session metadata, and then brings the conversation back as an untitled "stranger" session.

### Steps to Reproduce

1. `chat.agentHost.enabled: true` + `chat.agents.claude.preferAgentHost: true`, open the Agents window
2. Create a Claude (agent host) session, optionally rename it
3. Right-click the session → **Delete...** → confirm — session disappears ✅
4. Trigger a session list refresh (send a turn in another session, or reload the window)

**Expected:** session is permanently gone.
**Actual:** session reappears in the list, with default title and reset read/archived state.

### Root cause (traced through 1.128.0 sources)

The delete path never deletes the SDK-side transcript:

- `DeleteAgentSessionAction` → `chatSessionsService.deleteChatSessionItem` → `agentHostSessionListController.deleteChatSessionItem` → store `disposeSession` → server-side `AgentService.disposeSession` (`src/vs/platform/agentHost/node/agentService.ts`)
- `disposeSession` tears down in-memory state and deletes the **VS Code per-session data dir** (`sessionDataService.deleteSessionData` — metadata DB, checkpoints, title overlay, read/archived state)…
- …but **never calls the SDK's `deleteSession`**. The transcript at `~/.claude/projects//.jsonl` survives.

Meanwhile `ClaudeAgent.listSessions` (`src/vs/platform/agentHost/node/claude/claudeAgent.ts`) deliberately surfaces every SDK transcript:

> *"SDK is the source of truth; the per-session DB is a pure overlay/cache … We deliberately do NOT filter entries that lack a DB — external Claude Code CLI sessions have no DB and must still surface."*

That rule (correct for external CLI sessions) is exactly what resurrects the "deleted" session — now metadata-less, because the overlay DB *was* deleted.

### Suggested fix

The bundled SDK (0.3.198) already exposes `deleteSession(sessionId)` (removes transcript + file-history), and the agent host already calls it in the `truncateSession` remove-all-turns path (`claudeAgent.ts` — `await this._sdkService.deleteSession(sessionId)`). Wiring the same call into the session-delete path (after `shutdownLiveQuery`, mirroring truncate's ordering) would make Delete actually delete.

Care needed for the inverse case: sessions created by the external CLI that the user deletes from the Agents window — deleting the transcript is presumably the user's intent there too, but worth an explicit decision.

### Environment

- VS Code 1.128.0 stable, macOS (also reproduces via remote SSH agent host on Linux)
- Agent host Claude in native (BYOK) mode, `claudeUseCopilotProxy: false`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.