Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Actions On SaveNew to Visual Studio Code? Get it now.
Actions On Save

Actions On Save

tonychen

|
3 installs
| (0) | Free
Run a configured command when matching files are saved.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Actions On Save

Run one or more configured shell commands when files are saved and match a user-specified pattern.

Features

  • Run a list of shell commands sequentially on save (actionsOnSave.commands).
  • Match files by a regex against the file path (actionsOnSave.pattern).
  • Skip auto-save triggers by default; opt-in via actionsOnSave.runOnAutoSave.
  • Keep command output in an Output panel (shown only on error by default).
  • Restore cursor/viewport after formatting; optionally move cursor to line end (actionsOnSave.cursorAtLineEnd).
  • Per-file concurrency guard to avoid duplicate concurrent runs.

Settings

  • actionsOnSave.commands (string[]): list of shell commands to run (default: ["pnpm run lint:fix"]). Supports template tokens (see below).
  • actionsOnSave.pattern (string): JavaScript RegExp string matched against full file path (default: .*\\.(js|ts|jsx|tsx)$).
  • actionsOnSave.runOnAutoSave (boolean): if true, also run on auto-save (default: false).
  • actionsOnSave.cursorAtLineEnd (boolean): if true, move cursor to end of the current line after running commands (default: false).

Template tokens

You can use the following tokens inside commands; they will be replaced when the file is saved:

  • {{file}} — absolute file path (quoted).
  • {{relativeFile}} — path relative to the workspace folder (quoted when possible).
  • {{workspaceFolder}} — workspace folder path (quoted).
  • {{fileBasename}} — file basename.

Example settings.json snippet

"actionsOnSave.commands": [
  "pnpm fmt {{file}}",
  "pnpm lint:fix {{file}}"
],
"actionsOnSave.pattern": ".*\\.(js|ts)$",
"actionsOnSave.runOnAutoSave": false,
"actionsOnSave.cursorAtLineEnd": false

Usage / Development

  • Install and build:
pnpm i
pnpm build
  • Launch the Extension Development Host (open this folder in VS Code and press F5). Save files that match your pattern.

Behavior notes

  • Output panel is not shown for successful runs by default; it is shown on error to help debugging.
  • If a command is already running for the same file, new triggers are skipped. If you want a different strategy (queue/cancel), request it and I can add it.

Debugging

  • Use the existing .vscode/launch.json to run the Extension Development Host and hit breakpoints in src/.
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft