Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Command ChainNew to Visual Studio Code? Get it now.
Command Chain

Command Chain

Robin H

|
1 install
| (0) | Free
Compose and execute auditable command chains in Visual Studio Code.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Command Chain

Command Chain is a Visual Studio Code extension for defining small, reusable command sequences under the commandChain.* namespace.

It supports named command chains from user settings, direct one-off execution through commandChain.execute, optional delays between steps, repeat counts, success and failure branches, and variable substitution for command arguments.

Installation

Install Command Chain from the Extensions view by searching for hrnan.command-chain,

or through the CLI:

code --install-extension hrnan.command-chain

or install a packaged VSIX locally:

code --install-extension ./command-chain-0.0.1.vsix

For local builds:

npm install
npm run compile
npx @vscode/vsce package

Configuration

The extension contributes:

  • Command: commandChain.execute
  • Setting: commandChain.commands

Configured command chains are read from user settings only. Workspace and workspace-folder values for commandChain.commands are ignored intentionally.

Array Form

{
  "commandChain.commands": [
    {
      "command": "commandChain.formatAndSave",
      "label": "Format And Save",
      "description": "Format the current file and save it",
      "sequence": [
        "editor.action.formatDocument",
        "workbench.action.files.save"
      ]
    }
  ]
}

Object Form

{
  "commandChain.commands": {
    "commandChain.duplicateLineTwice": {
      "label": "Duplicate Line Twice",
      "description": "Repeat a built-in VS Code command",
      "sequence": [
        {
          "command": "editor.action.copyLinesDownAction",
          "repeat": 2
        }
      ]
    }
  }
}

Running Command Chains

Named Command Chain

Define a chain in commandChain.commands, then call it through commandChain.execute:

{
  "key": "alt+x",
  "command": "commandChain.execute",
  "args": {
    "command": "commandChain.formatAndSave"
  }
}

Configured chains are also registered as commands under commandChain.*, and Command Chain: Execute Command Chain opens a quick pick when run without arguments.

Ad Hoc commandChain.execute Usage

{
  "key": "alt+y",
  "command": "commandChain.execute",
  "args": {
    "sequence": [
      "cursorDown",
      {
        "command": "type",
        "args": {
          "text": "done"
        }
      }
    ],
    "interval": 25
  }
}

Sequence Features

interval

Set interval on a named chain to wait between each sequence item:

{
  "commandChain.commands": {
    "commandChain.swapCharacters": {
      "interval": 30,
      "sequence": [
        "cursorLeftSelect",
        "editor.action.clipboardCutAction",
        "cursorRight",
        "editor.action.clipboardPasteAction"
      ]
    }
  }
}

repeat

{
  "commandChain.commands": {
    "commandChain.moveDownThree": {
      "sequence": [
        {
          "command": "cursorDown",
          "repeat": 3
        }
      ]
    }
  }
}

onSuccess

{
  "commandChain.commands": {
    "commandChain.formatThenReveal": {
      "sequence": [
        {
          "command": "editor.action.formatDocument",
          "onSuccess": [
            "workbench.files.action.showActiveFileInExplorer"
          ]
        }
      ]
    }
  }
}

onFail

{
  "commandChain.commands": {
    "commandChain.tryFormatWithFallback": {
      "sequence": [
        {
          "command": "editor.action.formatDocument",
          "onFail": [
            "workbench.action.openSettingsJson"
          ]
        }
      ]
    }
  }
}

Conditioned string expressions such as "first.command || second.command" are also supported inside a sequence.

variableSubstitution

{
  "commandChain.commands": {
    "commandChain.insertFileContext": {
      "sequence": [
        {
          "command": "type",
          "variableSubstitution": true,
          "args": {
            "text": "${fileBasename}:${lineNumber} ${selectedText}${pathSeparator}"
          }
        }
      ]
    }
  }
}

Supported placeholders include ${userHome}, ${workspaceFolder}, ${workspaceFolderBasename}, ${file}, ${fileWorkspaceFolder}, ${relativeFile}, ${relativeFileDirname}, ${fileBasename}, ${fileBasenameNoExtension}, ${fileDirname}, ${fileExtname}, ${cwd}, ${lineNumber}, ${selectedText}, ${pathSeparator}, ${env:*}, and ${config:*}.

Security Note

Command Chain executes VS Code command IDs that you configure. The extension itself does not add telemetry, network access, shell execution, or process spawning.

However, any configured chain can invoke built-in VS Code commands or commands contributed by other installed extensions, so the effective behavior depends on which command IDs you choose to run.

For lower-risk use, commandChain.commands is loaded only from user settings. Workspace and workspace-folder values are ignored.

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