If saving a generated file in VS Code on your Mac keeps changing its contents, first identify which formatter is running. VS Code’s editor.formatOnSave setting applies formatting when a file is saved, but VS Code does not provide a built-in path pattern that exempts selected files from that setting. For a formatter such as Prettier, use its own ignore file; otherwise, turn off format-on-save at a scope that fits the files you need to protect.

Identify what is changing the file

VS Code can format on save through editor.formatOnSave, and language extensions can provide formatters. A save-time Code Action, such as organizing imports, is a separate setting and can also alter file contents. VS Code’s editing documentation describes format-on-save; its Code Actions on Save guide covers save-time actions.

To narrow down the cause, open the generated file, check its language mode in the status bar, and search Settings for formatOnSave and codeActionsOnSave. The @modified filter in Settings can help reveal configured values. If the file changes despite formatting being off, inspect the installed extensions and project scripts: a generator or another save action may be responsible. Disabling formatting will not stop an independent tool from rewriting the file.

Exclude generated paths when using Prettier

If Prettier is the formatter, add the generated path to .prettierignore at the project root. For example, to skip generated files under src/generated, use this entry:

src/generated/

Prettier documents .prettierignore as its file exclusion mechanism and says editor integrations can use it. Its patterns use Git-ignore syntax. This is the most targeted option when you want format-on-save to continue for other files handled by Prettier. Check that the formatter selected for this file really is Prettier; another formatter may use different rules or ignore controls. Prettier: Ignoring Code

Disable formatting at a suitable VS Code scope

On Mac, press ⇧⌘P and run Preferences: Open User Settings (JSON) for a global change, or Preferences: Open Workspace Settings (JSON) to affect only the current project. The workspace file is stored in the project’s .vscode folder. VS Code documents both settings scopes and their Mac commands in User and workspace settings.

To stop formatting on save throughout just this workspace, add the setting below to its existing JSON object. Preserve other settings already there, and add a comma where needed:

{
  "editor.formatOnSave": false
}

For a language-wide exception, scope the setting to that language instead. Replace typescript with the file’s actual VS Code language identifier, which you can inspect from the status bar:

{
  "[typescript]": {
    "editor.formatOnSave": false
  }
}

This disables format-on-save for every file in that language at the chosen scope, not just generated paths. Settings can also be overridden by more specific scopes, so if the file still changes, search @modified and inspect both user and workspace settings as well as any language-specific blocks. VS Code’s settings reference documents language-specific settings and precedence.

Check save-time actions separately

If formatting is already off but saving still rearranges imports or applies fixes, look for editor.codeActionsOnSave. It controls actions such as organize imports and fix-all. Remove or change only the action causing the rewrite; disabling this setting wholesale can also remove useful save-time behavior. VS Code’s Code Actions on Save documentation explains the supported controls.

Do not use files.exclude as a formatting safeguard: VS Code documents it as an Explorer visibility setting, not a control over whether a formatter edits a file. If the formatter has no path-based ignore feature and only a few generated files are affected, the practical VS Code option is to disable format-on-save for their language or workspace, then format ordinary files manually with Format Document (⇧⌥F) when needed. VS Code documents that command in Basic editing.

For generated files that must remain byte-for-byte stable, prefer the formatter’s own documented ignore mechanism when available. Otherwise use the narrowest available VS Code setting scope, then save a representative generated file and inspect the diff to confirm which behavior is responsible.

Sources