Overview Version History Q & A Rating & Review
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
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/.