---
schema_version: "1"
id: b80ab69f88b3a29b24ffe550d4182e2790beca5b03ff7094dac6ac8b39e7f0d6
title: Generate a Basic Plugin
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/sfcliplugin/guides/get-started/gs-generate-plugin.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-cli-plugin/guide/gs-generate-plugin.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 283ea13192e293643ced96d1db4c4e8e313eef7a925fcc961535ee49f18b8ef2
products:
  - Salesforce CLI Plugin Developer Guide
  - salesforcedx
---
# Generate a Basic Plugin

Use the interactive plugin generator, which is itself a plugin, to create your own Salesforce CLI plugin.

1. Open a terminal (macOS, Linux) or command prompt (Windows) and change to the top-level directory where you want to generate your plugin. For example:

   ```bash
   cd /Users/astro/salesforce-plugins
   ```

2. Run the interactive command:

   ```bash
   sf dev generate plugin
   ```

   The Salesforce CLI plugin that contains the commands for generating new plugins, commands, and flags (`plugin-dev`) is "just in time" (JIT). This means that if you haven't explicitly installed the plugin, Salesforce CLI does it for you when you first run one of its commands.

   You're first prompted whether you're an internal Salesforce developer. The Salesforce CLI team uses this command to create plugins too! But answer `n` so you're not subject to our internal requirements. You're next prompted for information to populate your new plugin, such as its name, description, author, and percentage of code coverage you want. The command then clones either the [plugin-template-sf](https://github.com/salesforcecli/plugin-template-sf) or [plugin-template-sf-external](https://github.com/salesforcecli/plugin-template-sf-external) Github repo and installs the plugin's npm package dependencies using `yarn install`.

   After the `dev generate plugin` command completes, the new plugin contains an example `hello world` command. See [this section](#tour-the-generated-files) for a description of some of the generated files.

## Say Hello to the World

Let's see how to run the commands in your new plugin.

1. Change to the new plugin directory, which is the same as the name you provided to the `dev generate plugin` command.

   ```bash
   cd my-plugin
   ```

1. To run the commands of your in-development plugin from the top-level directory that your code lives in, precede the commands with `bin/dev.js`. For example, to run the sample `hello world` command:

   ```bash
   bin/dev.js hello world
   bin/dev.js hello world --name Astro
   ```

   To view the `--help` output for the command:

   ```bash
   bin/dev.js hello world --help
   ```

   As you create new commands, test them the same way. For example:

   ```bash
   bin/dev.js create webcart
   ```

1. When you’re ready to test drive your plugin, link your in-development plugin to Salesforce CLI. From the top-level plugin directory, such as `my-plugin`, run this command (be sure to include the period at the end!):

   ```bash
   sf plugins link .
   ```

   The command installs your plugin in Salesforce CLI by creating a symlink to your `my-plugin` directory. After you link your plugin, you can run your commands without using `bin/dev.js`. For example:

   ```bash
   sf hello world
   sf hello world -h
   ```

   If you see this warning message, don't worry. It's expected and everything is working just fine.

   ```bash
   Warning: my-plugin is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.
   ```

   This warning means that your plugin is written with ESM (officially called [ECMAScript modules](https://nodejs.org/api/esm.html)), which is what our templates use. We can't auto compile ESM while running a command, which means you must make sure that you compile your plugin after every change. We recommend running `yarn compile --watch` in a separate terminal so that all your changes are compiled every time you save a file.

   The `-h` flag, which displays a shorter version of help messages, is available only when you link or install the plugin. It's not available when using `bin/dev.js`.

   To see which plugins you've installed or linked, including your new plugin, run:

   ```bash
   sf plugins --core
   ```

   Your linked plugin is listed like this in the output:

   ```bash
   my-plugin 1.0.0 (link) /Users/astro/salesforce-plugins/my-plugin
   ```

   To unlink the plugin, run:

   ```bash
   sf plugins unlink .
   ```

## Tour the Generated Files

The `sf` plug-In Generator creates many files, some that support the entire plugin, some for the `hello world` command. This table describes a few of the main ones which you can use as templates when you start coding your own commands.

| **File**                            | **Description**                                                                                                                                                                                                                                                                                                                                           |
| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `package.json`                      | Npm file that describes package dependencies and versions.                                                                                                                                                                                                                                                                                                |
| `tsconfig.json`                     | Typescript file that specifies the root files and the compiler options required to compile the project.                                                                                                                                                                                                                                                   |
| `src/commands/hello/world.ts`       | Main TypeScript file that contains the code for the hello world command. The command imports and extends classes from [@salesforce/sf-plugins-core](https://github.com/salesforcecli/sf-plugins-core). When you add your own commands, you use the [SfCommand abstract class](https://github.com/salesforcecli/sf-plugins-core#sfcommand-abstract-class). |
| `messages/hello.world.md`           | Markdown file that contains the messages that make up the command help and errors.                                                                                                                                                                                                                                                                        |
| `test/commands/hello/world.test.ts` | Unit tests.                                                                                                                                                                                                                                                                                                                                               |
| `test/commands/hello/world.nut.ts`  | Complex integration, smoke, and end-to-end tests. Also known as NUTS (non-unit-tests.)                                                                                                                                                                                                                                                                    |
| `.github/workflows/*.yml`           | Sample [GitHub Actions](https://docs.github.com/en/actions) workflow files for testing, releasing, and publishing your plugin. See [this repo](https://github.com/salesforcecli/github-workflows) for how the Salesforce CLI developer team uses GitHub Actions.                                                                                          |
