Devvit CLI
The Devvit CLI enables you to create, upload, and manage your apps. It's the bridge between your codebase and Reddit.
We collect usage metrics when you use the Devvit CLI. For more information, see Reddit’s Developer Terms and the Reddit Privacy Policy. You can opt out at any time by running npx devvit metrics off.
CLI Usage
devvit create icons
Bundles all SVG files in the /assets folder into a new file (src/icons.ts by default). Enabling you to import local SVG assets in your app code.
Usage
$ npx devvit create icons [output-file]
Optional argument
-
output-filePath to the output file. Defaults to
src/icons.ts.
Generating the SVG bundle file
$ npx devvit create icons
$ npx devvit create icons "src/my-icons.ts"
Using the SVG files in app code
import Icons from './my-icons.ts';
export const App = () => (
<img src={Icons['my-image.svg']} width={32} height={32} alt="" />
);
devvit help
Display help for devvit
Usage
$ npx devvit help
devvit install
Install an app from the Apps directory to a subreddit that you moderate. You can specify a version to install or default to @latest (the latest version).
Usage
$ npx devvit install <subreddit> [app-name]@[version]
Required arguments
-
subredditName of the installation subreddit. The "r/" prefix is optional.
Optional arguments
-
app-nameName of the app to install (defaults to current project).
-
versionSpecify the desired version (defaults to latest).
Examples
$ npx devvit install r/mySubreddit
$ npx devvit install mySubreddit my-app
$ npx devvit install r/mySubreddit [email protected]
$ npx devvit install r/mySubreddit @1.2.3
devvit list apps
To see a list of apps you've published
Usage
$ npx devvit list apps
devvit list installs
To see a list of all apps currently installed on a specified subreddit.
If no subreddit is specified, you'll get a list of all apps installed by you.
Usage
$ npx devvit list installs [subreddit]
Optional argument
-
subredditName of the subreddit to look up installations for. The "r/" prefix is optional.
Examples
$ npx devvit list installs
$ npx devvit list installs mySubreddit
$ npx devvit list installs r/mySubreddit
devvit login
Login to Devvit with your Reddit account in the browser.
Usage
$ npx devvit login [--copy-paste]
Optional argument
-
--copy-pasteIf present, user will copy-paste code from the browser instead of the localhost.
devvit logout
Logs the current user out of Devvit.
Usage
$ npx devvit logout
devvit logs
Stream logs for an installation within a specified subreddit. You can see 5,000 logs or up to 7 days of log events.
Usage
$ npx devvit logs <subreddit> [app-name] [-d <value>] [-j] [-s <value>] [--verbose]
Required arguments
-
subredditThe subreddit name. The "r/" prefix is optional.
Optional arguments
-
app-nameThe app name. Defaults to the app in the working directory.
-
-d <value>, --dateformat <value>Specify the format for rendering dates. Defaults to
MMM d HH:mm:ss(Jan 15 18:30:03). See more about format options here. -
-j, --jsonOutput JSON for each log line
-
-s <value>, --since <value>Specify how far back you want the log streaming to start. Defaults to a
0m(now) if omitted.Supported format:
ssecondsmminuteshhoursddayswweeks
For example
15s,2w1d, or30m. -
--verboseDisplays the log levels and timestamps when the logs were created.
Examples
$ npx devvit logs r/mySubreddit
$ npx devvit logs mySubreddit my-app
$ npx devvit logs mySubreddit my-app --since 15s
$ npx devvit logs mySubreddit my-app --verbose
devvit init
Initialize a new app. devvit new is retained as an alias.
Without an initialization code, this command opens the app-creation flow in your browser. Outside a Devvit project, the generated project is placed in a directory named after the new app. Inside an uninitialized Devvit project, the command initializes that directory. Use --force only to replace an app that has already been initialized.
Usage
$ npx devvit init [code] [--template <name>] [--force]
Optional arguments
-
codeInitialization code supplied by Reddit. If omitted, the CLI opens the browser flow to create the app and obtain a code.
-
--template <name>Select a project template without opening the template-selection prompt.
-
--forceInitialize a new app even when the current directory is already a Devvit app.
Examples
$ npx devvit init
$ npx devvit init <code>
$ npx devvit init --template <template-name>
devvit playtest
Installs your app to your test subreddit and starts a playtest session. A new version of your app is installed whenever you save changes to your app code, and logs are continuously streamed. Press ctrl+c to end the playtest session. Once ended, the latest installed version will remain unless you revert to a previous version using devvit install. For more information, see the playtest page.
Usage
$ npx devvit playtest [subreddit] [--debounce <milliseconds>] [logging options]
Optional arguments
-
subredditName of a test subreddit with less than 200 subscribers that you moderate. The "r/" prefix is optional.
-
--debounce <milliseconds>Debounce file-change handling by the specified number of milliseconds.
-
Logging options
playtestaccepts the same public log-formatting and filtering flags asdevvit logs, including--dateformat,--json,--log-runtime,--show-timestamps,--since, and--verbose.
If no subreddit is specified, the command will use the first available option from:
- DEVVIT_SUBREDDIT environment variable
- dev.subreddit field in devvit.json
- The playtest subreddit stored for your app
If none exist, a new playtest subreddit will be automatically created.
devvit settings list
List settings for your app. These settings exist at the global app-scope and are available to all instances of your app.
Usage
$ npx devvit settings list
devvit settings set
Create and update settings for your app. These settings will be added at the global app-scope.
Usage
$ npx devvit settings set <my-setting>
Example
$ npx devvit settings set my-feature-flag
devvit uninstall
Uninstall an app from a specified subreddit.
Usage
$ npx devvit uninstall <subreddit> [app-name]
Required argument
-
subredditName of the subreddit. The "r/" prefix is optional. Requires moderator permissions in the subreddit.
Optional argument
-
app-nameName of the app. Defaults to the app in the working directory.
Examples
$ npx devvit uninstall r/mySubreddit
$ npx devvit uninstall mySubreddit
$ npx devvit uninstall mySubreddit my-app
devvit update app
Update @devvit project dependencies to the currently installed CLI's version
Usage
$ npx devvit update app
devvit publish
Create a new app version, upload the app and its source for review, and submit a publish request.
Usage
$ npx devvit publish [--bump major|minor|patch | --version <version>] [--public] [--withdraw] [--copy-paste] [--verbose]
Optional arguments
-
--bump <option>Type of version bump:
major,minor, orpatch. Patch is the default. Cannot be combined with--version. -
--version <version>Explicit non-prerelease version number, such as
1.0.1. Cannot be combined with--bump. -
--publicSubmit the app for public review rather than the default unlisted review.
-
--withdrawWithdraw the app's most recent pending publish request. Cannot be combined with
--public. -
--copy-pasteCopy and paste the authentication code instead of opening a local browser callback.
-
--verboseEnable verbose logging.
devvit upload
Upload an app to the App directory. By default the app is private and visible only to you.
Usage
$ npx devvit upload [--bump major|minor|patch|prerelease | --version <version>] [--copy-paste] [--verbose]
Optional arguments
-
--bump <option>Type of version bump:
major,minor,patch, orprerelease. Cannot be combined with--version. -
--version <version>Explicit version number, such as
1.0.1. Cannot be combined with--bump. -
--copy-pasteCopy and paste the authentication code instead of opening a local browser callback.
-
--verboseEnable verbose logging.
devvit version
Get the version of the locally installed Devvit CLI.
Usage
$ npx devvit version
devvit view
Show details about an app version. The app defaults to the project in the working directory, and the version defaults to latest.
Usage
$ npx devvit view [app-name[@version]] [version] [--json]
The optional literal version subcommand prints only the resolved version number. To select an app version, append it to the app name with @.
Examples
$ npx devvit view
$ npx devvit view my-app
$ npx devvit view [email protected]
$ npx devvit view @1.2.3
$ npx devvit view [email protected] version
$ npx devvit view --json
devvit whoami
Display the currently logged in Reddit user.
Usage
$ npx devvit whoami
Updating the CLI
There are currently two ways to update the Devvit CLI, depending on how you installed it.
How do I know how I installed the CLI?
The easiest way to check how you installed the CLI is to run this command in your terminal:
npm list -g --depth=0
If you see a line that starts with devvit@, it means you have the CLI installed globally. If
not, you likely have it installed as a dev dependency in your project - you can check this by
looking for devvit in your project's package.json file under the devDependencies section.
(If you don't see it in either place, you may not have the CLI installed at all, in which case,
you can follow the quickstart guide to install it.)
1. If you installed the CLI as a dev dependency
This is the recommended way to install the CLI, as it ensures that your project uses a specific version of the CLI, and makes it substantially easier to both update the CLI, and know what version of the CLI you're using.
To update the CLI, run the following command in your project directory:
npm install --save-dev devvit@latest
(Or, if you're using a different package manager, use an equivalent command to update the devvit
package to the latest version, and save it as a development dependency. DO NOT save it as a
regular dependency - we don't need the CLI code uploaded with your app!)
2. If you installed the CLI globally
If you installed the CLI globally, ideally, you should uninstall the global version and install it as a dev dependency in your project instead. To do this, inside your project, run the following commands:
npm uninstall -g devvit
npm install --save-dev devvit@latest
If you still want to keep the CLI installed globally, you can update it by running the following command:
npm install -g devvit@latest
This will update the global version of the Devvit CLI to the latest version. However, please note that this is not recommended, as it can lead to inconsistencies between the CLI version used in your project and the global version. It's best to use the CLI as a dev dependency in your project to ensure that you're always using the same version across different environments.