Using environment variables with the Slack CLI
You can store and use environment variables with your Slack app by using a collection of Slack CLI commands and features. You can even access some pre-set environment variables!
Using the Slack CLI env commands
There are three Slack CLI subcommands that can be used to modify environment variables which are saved to the project's .env file.
slack env set
Use this to set an environment variable for the project. You can set the environment variable within the command, or run slack env set alone to go through an interactive interface.
slack env set MAGIC_PASSWORD abracadbra
slack env unset
Use this to remove variables for the project. You can unset environment variables within the command, or run slack env unset alone to view all environment variables and select which one to unset.
slack env unset MAGIC_PASSWORD
slack env list
Use this to view the variables set for this project
slack env list
Using CLI-provided variables
The Slack CLI provides an envelope of environment variables set automatically if these aren't available beforehand.
| Variable | Origin | Use |
|---|---|---|
SLACK_APP_TOKEN | Set after a successful app installation when using Socket Mode. | Authenticate with Slack API as the app. Required for Socket Mode connections and API calls. |
SLACK_BOT_TOKEN | Set after a successful app installation that requested bot scopes. | Authenticate with Slack API as the bot user. Used for making API calls on behalf of the app. |
SLACK_APP_PATH | Set when a custom start path is provided via slack run | Used to run from a non-root directory. |
SLACK_CLI_CUSTOM_FILE_PATH | Set to the same value as SLACK_APP_PATH when a custom start path is provided via slack run | Used to run from a non-root directory. |