Does VS Code Autosave Automatically? How to Protect Your Work Across Multiple Files

VS Code does not autosave by default; you must manually enable Auto Save in your settings to protect against unexpected closures.

When working with multiple files in VS Code, understanding the autosave behavior is critical to prevent data loss from crashes or power failures. By default, the editor only persists changes when you explicitly press ⌘ S (macOS) or Ctrl S (Windows/Linux), or when the editor loses focus. This guide explains how to configure VS Code autosave settings, using the TypeScript repository as a practical example of a multi-file codebase that requires proper save configuration.

Understanding VS Code Autosave Behavior

Out of the box, VS Code operates with files.autoSave set to "off". This means the editor maintains your changes in memory but does not write them to disk until you trigger a save action. While this prevents unnecessary disk writes, it leaves your work vulnerable to unexpected application closures.

VS Code provides four distinct autosave modes controlled by the files.autoSave setting:

  • "off" – No automatic saving; files only save on manual trigger (default behavior)
  • "afterDelay" – Saves files automatically after a period of inactivity (default delay is 1000ms)
  • "onFocusChange" – Saves the current file when the editor loses focus (e.g., when you click another tab)
  • "onWindowChange" – Saves all open files when the VS Code window loses focus (e.g., switching to another application)

How to Enable VS Code Autosave for Multiple Files

To protect your work across multiple files, you must configure the autosave setting in your VS Code preferences. You can apply these settings at the user level (global) or workspace level (project-specific).

User Settings (Global)

Apply autosave to all VS Code projects by modifying your user settings:

  1. Open the Command Palette (⌘ Shift P or Ctrl Shift P)
  2. Type "Preferences: Open User Settings (JSON)"
  3. Add the autosave configuration:
{
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 1500
}

Workspace Settings (Project-Specific)

For team projects or specific repositories, create a workspace settings file at .vscode/settings.json in your project root:

{
  "files.autoSave": "onFocusChange"
}

This ensures consistent autosave behavior for all contributors who open the project in VS Code.

Configuring Autosave in the TypeScript Repository

The TypeScript repository (microsoft/TypeScript) does not ship with a default autosave configuration. The only VS Code-specific file included in the repository is .vscode/launch.template.json, which provides debugging configurations for running the TypeScript compiler test suite.

Because the repository's .gitignore explicitly ignores **/.vscode/* files (except for the launch template), you can safely create a local .vscode/settings.json file to enable autosave without affecting other contributors or submitting changes to version control.

To configure autosave specifically for TypeScript development:

  1. Create .vscode/settings.json in the repository root (if it doesn't exist)
  2. Add your preferred autosave configuration:
{
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 1000
}

This configuration is particularly valuable when working with the TypeScript compiler source code, as you may have dozens of files open simultaneously across the src/compiler directory, and manual saving becomes impractical.

Summary

  • VS Code does not autosave by default; you must explicitly enable the feature to prevent data loss.
  • Configure autosave via the files.autoSave setting with options including "afterDelay", "onFocusChange", and "onWindowChange".
  • The TypeScript repository does not include default autosave settings, allowing developers to create local .vscode/settings.json configurations.
  • For multi-file workflows, "afterDelay" with a 1000-1500ms delay provides the best balance between performance protection and disk I/O efficiency.

Frequently Asked Questions

Does VS Code autosave by default when I open multiple files?

No, VS Code does not autosave by default under any circumstances. Whether you have one file or fifty files open, the editor maintains changes in memory only until you manually save (⌘ S/Ctrl S) or configure files.autoSave to one of the automatic modes.

What is the best autosave setting for coding in TypeScript projects?

For TypeScript development, "afterDelay" with a 1000-1500ms delay is generally optimal. This setting ensures your changes persist to disk shortly after you stop typing, protecting against crashes while avoiding excessive disk writes during rapid editing sessions across multiple compiler source files.

Will enabling autosave affect Git integration in VS Code?

Enabling autosave does not change how Git tracks changes, but it does mean modified files will appear in the Source Control panel more quickly. Since autosave writes to disk immediately, VS Code's Git integration will detect the file changes and display them in the changes list without requiring manual saves.

Why doesn't the TypeScript repository include a default autosave configuration?

The TypeScript repository intentionally avoids enforcing editor-specific behaviors like autosave settings. According to the repository structure, the only VS Code configuration provided is .vscode/launch.template.json for debugging tests. Autosave preferences vary by developer workflow, so the team leaves this configuration to individual developers via their local .vscode/settings.json files, which are gitignored to prevent personal preferences from affecting the shared codebase.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →