keepcalculator

06 Numbers and Powers

VS Code Agent Session Cleanup & Storage Settings

Card No. 06·6119 · Updated · Standard formula, shown below

This guide explains how to configure Visual Studio Code’s agent session cleanup and storage settings, helping you manage disk space and keep the editor responsive. You’ll learn where these settings live, how to adjust them, and what to do when things don’t behave as expected. No prior configuration is needed, but you should have a basic familiarity with VS Code’s Settings UI.

What You’ll Need

  • Visual Studio Code installed (any recent version, 1.80 or later recommended).
  • Access to the Settings editor (Ctrl+, or Cmd+, on macOS).
  • Basic understanding of JSON if you prefer editing settings.json directly.

Step-by-Step

  1. Open Settings: Launch VS Code, then press Ctrl+, (Windows/Linux) or Cmd+, (macOS) to open the Settings editor. Alternatively, click the gear icon in the lower-left corner and select Settings.
  2. Search for session cleanup: In the search bar at the top of Settings, type session or cleanup. This filters the settings list to show relevant options. You’ll see entries like chat.agentSession.cleanup or github.copilot.chat.agentSession.cleanup depending on your version and extensions.
  3. Adjust cleanup threshold: Look for a setting that controls how long agent sessions are kept before being cleaned up. Common names include chat.agentSession.retentionPeriod or agent.session.cleanupThreshold. Set the value in days (e.g., 7). Lower values free up space sooner but may remove sessions you still want.
  4. Enable automatic cleanup: Some versions have a toggle like chat.agentSession.autoCleanup. Turn it on to allow VS Code to delete old sessions automatically. If you prefer manual control, leave it off and use the command palette instead.
  5. Configure storage location: To change where session data is stored, search for storage in Settings. Look for chat.agentSession.storagePath or similar. Enter an absolute path (e.g., D:\VSCodeSessions on Windows, /Users/me/sessions on macOS). This is optional; by default, data is stored in the user data directory.
  6. Set storage quota: If available, find chat.agentSession.maxStorageSize (in MB). Set a limit like 500 to cap the total size of session files. When the limit is reached, VS Code will delete the oldest sessions first.
  7. Apply and verify: After making changes, close and reopen VS Code (or reload the window with Ctrl+Shift+P → Developer: Reload Window). To verify, check the storage folder for old files or run the command Chat: Clean Up Agent Sessions from the command palette.

Common Mistakes

  • Setting retention to 0: A value of 0 often means “never clean up” or “delete immediately” depending on the setting. Read the description carefully—most use 0 as “keep forever,” which defeats the purpose.
  • Using the wrong setting name: The exact setting name varies by VS Code version and installed AI extensions (e.g., GitHub Copilot). Searching for session is safer than relying on a specific name.
  • Editing settings.json without validation: If you manually edit settings.json, a syntax error can break VS Code. Use the Settings UI whenever possible, or validate the JSON after editing.
  • Ignoring the storage path: Changing the storage path without moving existing files can cause VS Code to recreate the default folder, leaving old files behind. Move the folder manually if you change the path.

Tips

  • Use the command palette for one-off cleanups: Even if auto-cleanup is off, you can manually run Chat: Clean Up Agent Sessions to delete all old sessions immediately.
  • Set a reasonable retention period: For most users, 7–14 days is a good balance. If you’re low on disk space, use 3 days.
  • Monitor storage usage: Check the size of the session folder periodically (see Troubleshooting for where it is). If it’s growing too fast, lower the quota or retention.
  • Combine with workspace trust: If you work with untrusted folders, note that agent sessions may be stored per-workspace. Adjust settings per workspace if needed via Workspace Settings.

Troubleshooting

Settings not appearing: If you can’t find session-related settings, your VS Code version may not support agent sessions, or the feature is behind an experiment flag. Update VS Code to the latest version and check if the setting appears. If not, the feature may be disabled—look for chat.agentSession.enabled and set it to true.

Cleanup not happening: If sessions aren’t being cleaned up despite your settings, check if auto-cleanup is enabled. Some versions require both the retention period and auto-cleanup toggle to be set. Also, verify that the storage path is writable—if it’s read-only, VS Code can’t delete files.

Storage path not taking effect: After changing the path, restart VS Code completely (not just reload). If it still uses the old folder, the setting might be overridden by an extension. Try disabling AI extensions temporarily to isolate the issue.

Error messages about session files: If you see errors like “Failed to delete session,” it’s often due to file locks (e.g., another process is using the files). Close other instances of VS Code and try again. If the problem persists, manually delete the session folder (see FAQ for location).

Frequently Asked Questions

Q: Where are agent session files stored by default?
A: On Windows, they’re in %APPDATA%\Code\User\globalStorage\ (or under workspaceStorage for per-workspace). On macOS, it’s ~/Library/Application Support/Code/User/globalStorage/. Look for a folder named chat.agentSession or similar.

Q: Will changing cleanup settings delete my chat history?
A: It depends on the setting. Some cleanup options only remove session metadata, not chat transcripts. Others delete everything. Read the setting description carefully—if it says “delete session data,” it removes all associated files.

Q: Can I recover deleted sessions?
A: Once deleted, sessions are usually gone permanently. There’s no built-in recycle bin. If you need to keep a session, export it manually before cleanup (if the feature supports export) or back up the storage folder.

Q: How do I know how much space sessions are using?
A: Navigate to the storage folder (see first FAQ) and check its size in your file explorer. You can also use the command Chat: Show Session Storage if available in your version.

Q: Do these settings affect Copilot or other AI extensions?
A: Yes, if the extension uses VS Code’s agent session API. The settings are shared, so adjusting them will affect any extension that relies on agent sessions. Check the extension’s documentation for specific behavior.

Q: Why can’t I set a storage quota?
A: The quota setting may not be available in all versions. If you don’t see it, you can manually limit the folder size using your operating system’s disk quota tools, or simply set a lower retention period.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →