Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

VS Code has separate controls for cleaning up agent worktrees, automatically retiring merged sessions, and syncing Copilot session history. Use Chat: Open Worktree Cleanup to review inactive worktrees, configure the preview cleanup settings for merged sessions, and turn off session sync separately if you want future session data to stay local. Archiving or marking a session done hides it from active lists; deleting a session is permanent.

Choose what you want to clean up

These controls affect different things, so choose the one that matches your goal:

  • Free worktree storage: review and clean up inactive worktrees. Session and branch history remain available.
  • Reduce clutter in active session lists: archive or mark sessions done. Their history is retained.
  • Automatically retire merged sessions: configure the two preview settings that mark qualifying sessions done and later delete them.
  • Keep Copilot session history local: disable sync for future data. Existing cloud copies require a separate deletion action.

See Microsoft’s Manage agent sessions in VS Code, AI settings reference, and Sync and query session history for the documented controls. Experimental and preview features can change.

Review and clean up worktrees manually

The manual cleanup view lets you inspect eligible inactive worktrees before confirming cleanup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Open the Command Palette and run Chat: Open Worktree Cleanup.
  2. Select an inactivity threshold: 7, 15, 30, 60, or 90 days.
  3. Review the estimated worktree sizes. Clear the selection for any worktree you want to keep.
  4. Confirm cleanup for the remaining selected items.

The view excludes active, running, waiting-for-input, pinned, done, archived, untitled, or error-state sessions; sessions newer than the selected threshold; and worktrees whose size cannot be measured. Cleanup marks selected sessions done and schedules worktree removal. VS Code attempts to commit uncommitted changes to the session branch first. If it cannot preserve changes or remove a worktree, it leaves the worktree in place. Session and branch history are retained, and restoring a session recreates its worktree.

Enable storage cleanup suggestions

The experimental suggestion setting is off by default according to the settings reference, although experiments can override the default. To opt in, add this to User or Profile Settings:

"chat.agentSessions.sessionStorageCleanupSuggestion.enabled": true

VS Code can suggest cleanup when inactive worktrees use at least 5 GiB or when 20 worktrees are eligible. Dismissing a suggestion hides it for the current window. To stop future suggestions, choose Don’t Show Again or run Chat: Disable Session Storage Cleanup Suggestions.

Automatically clean up merged sessions

Automatic merged-session cleanup is in preview and disabled by default. It has two independent stages: the first marks qualifying inactive sessions done; the second permanently deletes them after a grace period. Microsoft’s documented recommendation is 15 days for each stage. Add or adjust these settings in User or Profile Settings:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
"chat.agentSessions.autoMarkAsDoneMergedSessionsAfterDays": 15,
"chat.agentSessions.autoDeleteMarkedAsDoneMergedSessionsAfterDays": 15

The first value is the number of inactive days before automatic marking as done. The second is the delay after automatic marking before permanent deletion. Setting either value to 0 disables that stage. When either setting is enabled, VS Code checks at startup and hourly.

Which sessions qualify

A session must be inactive beyond the configured threshold, have at least one merged pull request, and have no related open pull requests. External sessions are excluded. Automatic deletion applies only to sessions VS Code automatically marked done; sessions you marked done manually are not eligible. Restoring an automatically completed session clears its deletion eligibility.

When worktrees are removed

Even when a session qualifies for deletion, VS Code removes its worktree only if the branch tracks an upstream and has no outgoing commits or uncommitted changes. If Git state is unknown or conditions are unsafe, the worktree is retained. Cleanup does not force-remove a worktree.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep Copilot session history local

To stop future session data from syncing, set this setting to false:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
"chat.sessionSync.enabled": false

To keep sync enabled generally but exclude specific repositories, use exact owner/repo names or glob patterns:

"chat.sessionSync.excludeRepositories": [
  "my-org/private-repo",
  "my-org/secret-*"
]

Matching repositories stay local. Copilot Business and Enterprise users may also be subject to GitHub.com enterprise or organization policy, or the VS Code CopilotSessionSync group policy. If policy disables sync, the setting is forced off and users cannot override it.

Delete session data already synced

Turning sync off does not remove sessions already synced to GitHub.com. To remove existing data, run Delete Session Sync Data (github.copilot.sessionSync.deleteSessions), select the sessions, and choose either Delete from local and cloud or Delete from cloud only. Deleting from local and cloud is irreversible.

Protect work before deleting

Archiving or marking done changes a session’s visibility, not whether its history is retained. Deletion is permanent. Before deleting a session, commit or integrate any unique work that exists only in its worktree. Automatic worktree cleanup has Git safeguards, but those safeguards do not replace reviewing work you need to keep.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.