Skip to main content

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!

You may be looking for the Using environment variables with the Deno Slack SDK guide.

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.

VariableOriginUse
SLACK_APP_TOKENSet 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_TOKENSet 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_PATHSet when a custom start path is provided via slack runUsed to run from a non-root directory.
SLACK_CLI_CUSTOM_FILE_PATHSet to the same value as SLACK_APP_PATH when a custom start path is provided via slack runUsed to run from a non-root directory.