Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Workspace HooksNew to Visual Studio Code? Get it now.
Workspace Hooks

Workspace Hooks

WorkspaceHooks

| (0) | Free
Run configurable shell commands when a VS Code window starts and closes, including empty windows.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Workspace Hooks

Run multiple shell commands when a VS Code window starts or closes. It works without an open folder and commands are stored in your global user settings.

在 VS Code 窗口启动和正常关闭时执行多条 Shell 命令。无需打开工作区,命令保存在用户全局设置中。

Features / 功能

  • Independent parallel execution: one failed or long-running command never blocks the others. / 命令彼此独立,失败或长期运行不会阻塞其他命令。
  • Startup and shutdown lifecycle hooks. / 支持启动和退出生命周期。
  • Runs startup once for the first window and shutdown once after the last window closes. / 第一个窗口启动时执行一次,最后一个窗口关闭后执行一次。
  • Add and remove commands from the Command Palette. / 可通过命令面板添加和删除命令。
  • Configurable working directory and shutdown timeout. / 可配置工作目录和退出超时。
  • English and Simplified Chinese UI. / 支持英文和简体中文界面。
  • Commands only run in trusted workspaces; empty windows are supported. / 工作区模式下仅在受信任的工作区执行,空窗口可正常使用。

Usage / 使用方法

Open the Command Palette (Cmd+Shift+P on macOS or Ctrl+Shift+P on Windows/Linux) and search for Workspace Hooks.

打开命令面板(macOS:Cmd+Shift+P,Windows/Linux:Ctrl+Shift+P),搜索 Workspace Hooks:

  • Workspace Hooks: Add Command / Workspace Hooks: 添加命令
  • Workspace Hooks: Remove Command / Workspace Hooks: 删除命令
  • Workspace Hooks: Run Startup Commands Now / Workspace Hooks: 立即运行启动命令
  • Workspace Hooks: Run Shutdown Commands Now / Workspace Hooks: 立即运行退出命令
  • Workspace Hooks: Open Settings / Workspace Hooks: 打开设置

Example settings / 配置示例:

{
  "workspaceHooks.startupCommands": [
    "echo started >> /tmp/workspace-hooks.log",
    "npm run dev"
  ],
  "workspaceHooks.shutdownCommands": [
    "echo stopped >> /tmp/workspace-hooks.log"
  ],
  "workspaceHooks.cwd": "${workspaceFolder}",
  "workspaceHooks.shutdownTimeout": 10000
}

Output is available under View → Output → Workspace Hooks. / 执行日志位于 视图 → 输出 → Workspace Hooks。

Limitations / 限制

Workspace Hooks coordinates all VS Code windows: opening extra windows does not rerun startup hooks, and closing an intermediate window does not run shutdown hooks. On macOS, VS Code does not expose a separate application-quit event to extensions, so closing the last window is treated as shutdown. Shutdown hooks cannot be guaranteed after a force quit, crash, or power loss.

Workspace Hooks 会协调所有 VS Code 窗口:打开额外窗口不会再次执行启动命令,关闭中间窗口不会执行退出命令。macOS 上 VS Code 没有向扩展提供独立的应用退出事件,因此关闭最后一个窗口即视为退出。强制退出、崩溃或断电时无法保证执行退出命令。

Development / 开发

npm install
npm run compile

Press F5 in VS Code to launch the Extension Development Host. / 在 VS Code 中按 F5 启动扩展调试窗口。

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft