commands for sf plugin development

Usage no npm install needed!

<script type="module">
  import salesforcePluginDev from 'https://cdn.skypack.dev/@salesforce/plugin-dev';



NPM CircleCI Downloads/week License


sf plugins install @salesforce/plugin-dev@x.y.z


Generate a new sf plugin

sf dev generate plugin

This will generate a new sf plugin based on our plugin template.

Generate a new sf command in your plugin

sf dev generate command --name create:awesome:stuff

This will generate the following:

  • a new sf command
  • a markdown file that will be used for all your command's message (e.g. command summary, flag descriptions, examples, error messages, etc...)
  • a .nut test file (See docs for Non-Unit-Tests)
  • a unit test file (if the --unit flag is provided)

Generate a hook that will be used for existing sf commands

sf dev generate hook --event sf:env:list

This will generate a sf hook that can be used to extend the functionality of an existing sf command. For example, if you want a new environment type to be shown in sf env list.


Please report any issues at https://github.com/forcedotcom/cli/issues


  1. Please read our Code of Conduct
  2. Create a new issue before starting your project so that we can keep track of what you are trying to add/fix. That way, we can also offer suggestions or let you know if there is already an effort in progress.
  3. Fork this repository.
  4. Build the plugin locally
  5. Create a topic branch in your fork. Note, this step is recommended but technically not required if contributing using a fork.
  6. Edit the code in your fork.
  7. Write appropriate tests for your changes. Try to achieve at least 95% code coverage on any new code. No pull request will be accepted without unit tests.
  8. Sign CLA (see CLA below).
  9. Send us a pull request when you are done. We'll review your code, suggest any needed changes, and merge it in.


External contributors will be required to sign a Contributor's License Agreement. You can do so by going to https://cla.salesforce.com/sign-cla.


To build the plugin locally, make sure to have yarn installed and run the following commands:

# Clone the repository
git clone git@github.com:salesforcecli/plugin-dev

# Install the dependencies and compile
yarn && yarn build

To use your plugin, run using the local ./bin/dev or ./bin/dev.cmd file.

# Run using local run file.
./bin/dev hello world

There should be no differences when running via the Salesforce CLI or using the local run file. However, it can be useful to link the plugin to do some additional testing or run your commands from anywhere on your machine.

# Link your plugin to the sf cli
sf plugins link .
# To verify
sf plugins


sf dev generate command

Generate a new sf command.

  $ sf dev generate command --name <value> [--force] [--nuts] [--unit]

  --force         Overwrite existing files.
  --name=<value>  (required) Name of the new command. Must be separated by colons.
  --[no-]nuts     Generate a NUT test file for the command.
  --[no-]unit     Generate a unit test file for the command.

  Generate a new sf command.

  This will generate a basic hello world command, a .md file for messages, and test files.

  $ sf dev generate command --name my:command

sf dev generate hook

Generate a new sf hook.

  $ sf dev generate hook --event sf:env:list|sf:env:display|sf:deploy|sf:logout [--force]

  --event=<option>  (required) Event to run hook on.
                    <options: sf:env:list|sf:env:display|sf:deploy|sf:logout>
  --force           Overwrite existing files.

  Generate a new sf hook.

  This will generate a basic hook, add the hook to the package.json, and a generate a test file.

  $ sf dev generate hook --event sf:env:display

sf dev generate library

Generate a new library.

  $ sf dev generate library

  Generate a new library.

  This will clone the template repo 'forcedotcom/library-template' and update package properties

  $ sf dev generate library

sf dev generate plugin

Generate a new sf plugin.

  $ sf dev generate plugin

  Generate a new sf plugin.

  This will clone the template repo 'salesforcecli/plugin-template-sf' and update package properties

  $ sf dev generate plugin

sf dev hook HOOK

Run a hook. For testing purposes only.

  $ sf dev hook [HOOK] [--json] [-p <value>]

  HOOK  Name of hook to execute.

  -p, --plugin=<value>  Specific plugin from which to execute hook

  --json  Format output as json.

  Execute a hook by name:

    $ sf dev hook sf:env:list

  Execute a hook by name in a specific plugin:

    $ sf dev hook sf:env:list --plugin env