Skip to main content
The commandkit dev command starts a development server with hot module reloading (HMR), allowing you to see changes instantly without restarting your bot.

Basic Usage

Start the development server:
commandkit dev
This will:
  1. Build your project in development mode
  2. Start your Discord bot
  3. Watch for file changes
  4. Automatically reload commands and events
The development build is optimized for speed and includes source maps for debugging.

Command Options

Custom Config Path

Specify a custom config file:
commandkit dev --config ./configs/commandkit.js
commandkit dev -c ./custom-config.js
The default config path is ./commandkit.js in your project root.

Hot Module Reloading (HMR)

The development server includes intelligent hot reloading that updates your bot without a full restart:

What Gets Hot Reloaded?

When you modify files in src/app/commands/, the CLI:
  1. Detects the change
  2. Rebuilds the affected command
  3. Reloads all commands in your bot
  4. Keeps the bot connection alive
# Console output
Attempting to reload command(s) at src/app/commands/ping.ts
Successfully hot reloaded command(s) at src/app/commands/ping.ts

Development Commands

While the dev server is running, you can type these commands in the terminal:

r

Restart ServerManually restart the entire bot

rc

Reload CommandsForce reload all commands

re

Reload EventsForce reload all event handlers
# Type in terminal while dev server is running
r   # Restart the server
rc  # Reload all commands
re  # Reload all events
Use these manual commands when you want to force a reload without changing files.

Watched Directories

The CLI automatically watches these locations:
  • src/**/* - All source files
  • commandkit.js / commandkit.ts - Config file
  • commandkit.config.js / commandkit.config.ts - Alternative config names

Config File Changes

When you modify the CommandKit config file:
# Console output
It seems like commandkit config file was updated, 
please restart the server manually to apply changes.
Config changes require a manual restart. Press r in the terminal to restart.

Development Environment

Environment Variables

In development mode, the CLI automatically loads:
.env                 # Base variables
.env.local           # Local overrides
.env.development     # Development-specific
These environment variables are automatically injected:
process.env.NODE_ENV = 'development'
process.env.COMMANDKIT_BOOTSTRAP_MODE = 'development'
process.env.COMMANDKIT_IS_DEV = 'true'

Build Output

Development builds are written to .commandkit/ directory:
project/
├── .commandkit/        # Development build output
│   ├── index.js       # Entry point
│   ├── app.js         # Your main app
│   └── app/           # Commands and events
└── src/               # Your source code
The .commandkit/ directory is temporary and should be added to your .gitignore.

Anti-Crash Monitor

The development server includes an anti-crash monitor by default:
// Automatically catches uncaught exceptions
process.on('uncaughtException', (error) => {
  console.log('[CommandKit Anti-Crash Monitor] Uncaught Exception')
  console.log(error.stack)
})

// Automatically catches unhandled promise rejections
process.on('unhandledRejection', (reason) => {
  console.log('[CommandKit Anti-Crash Monitor] Unhandled promise rejection')
  console.log(reason.stack)
})
The anti-crash monitor prevents your bot from exiting during development. This is NOT recommended for production - use proper error handling instead.

Performance

The development server is optimized for fast rebuilds:
# Example console output
Bootstrapped CommandKit Development Environment in 234.56ms
Watching for changes in src directory

Development mode compilation took 1,234.56ms

Fast Rebuild Times

  • Initial build: ~1-2 seconds
  • Hot reload: ~100-300ms
  • Full restart: ~1-2 seconds

TypeScript Support

The CLI includes zero-config TypeScript support:
  • No tsconfig.json required (but respected if present)
  • Automatic type checking (disabled by default in dev mode)
  • Full JSX/TSX support with commandkit as JSX runtime
// Write JSX directly in your commands
import type { ChatInputCommand } from 'commandkit'

export const chatInput: ChatInputCommand = async (ctx) => {
  await ctx.interaction.reply(
    <Message>
      <Embed title="Hello World" color="Blue" />
    </Message>
  )
}

Debugging

Development builds include full source maps for debugging:

Using Chrome DevTools

node --inspect .commandkit/index.js

Using VSCode Debugger

Add this to .vscode/launch.json:
{
  "type": "node",
  "request": "launch",
  "name": "CommandKit Dev",
  "runtimeExecutable": "npx",
  "runtimeArgs": ["commandkit", "dev"],
  "console": "integratedTerminal"
}

Troubleshooting

If hot module reloading isn’t working:
  1. Check that you’re editing files in src/app/commands/ or src/app/events/
  2. Ensure file changes are being saved
  3. Try manually reloading with rc or re commands
  4. If still not working, restart with r
If your bot restarts frequently:
  1. Check for syntax errors in your code
  2. Look for circular dependencies
  3. Ensure you’re not modifying files outside of commands/events
  4. Check the console for specific error messages
If you’re seeing TypeScript errors:
  1. TypeScript type checking is disabled by default in dev mode
  2. Run commandkit build to see full type checking
  3. Install TypeScript if not present: npm install -D typescript
Config file changes require manual restart:
  1. Press r in the terminal to restart
  2. Or stop and restart commandkit dev

Next Steps

Production Builds

Learn how to build optimized bundles for deployment

Code Generators

Generate commands and events quickly

Build docs developers (and LLMs) love