A Discord bot that runs Claude Code sessions on different projects based on Discord channel names. Each channel maps to a folder in your file system, allowing you to interact with Claude Code for different repositories through Discord.
- Install Bun and Claude Code CLI
- Create a Discord bot at Discord Developer Portal
- Clone and setup:
git clone <repository-url> cd claude-code-discord bun install
- Create
.env
file:DISCORD_TOKEN=your_discord_bot_token_here ALLOWED_USER_ID=your_discord_user_id_here BASE_FOLDER=/path/to/your/repos
- Run:
bun start
- Channel-based project mapping: Each Discord channel corresponds to a folder (e.g.,
#my-project
→/path/to/repos/my-project
) - Persistent sessions: Sessions are maintained per channel and automatically resume
- Real-time streaming: See Claude Code's tool usage and responses as they happen
- Activity logging: Shows up to 20 lines of activity including tool calls with parameters
- Slash commands: Use
/clear
to reset a session
- Go to the Discord Developer Portal
- Click "New Application"
- Give your application a name (e.g., "Claude Code Bot")
- Click "Create"
- In your application, go to the "Bot" section in the left sidebar
- Click "Add Bot"
- Under "Token", click "Copy" to copy your bot token (keep this secure!)
- Under "Privileged Gateway Intents", enable:
- Message Content Intent
- Click "Save Changes"
- Go to the "OAuth2" → "URL Generator" section
- Under "Scopes", select:
bot
applications.commands
- Under "Bot Permissions", select:
- Send Messages
- Use Slash Commands
- Read Message History
- Embed Links
- Copy the generated URL and open it in your browser
- Select your Discord server and authorize the bot
- Enable Developer Mode in Discord:
- Go to Discord Settings → Advanced → Enable "Developer Mode"
- Right-click on your username in any channel
- Click "Copy User ID"
- Save this ID - you'll need it for the configuration
# Clone the repository
git clone <repository-url>
cd claude-code-discord
# Install dependencies
bun install
Create a .env
file in the project root:
# Discord bot token from step 2
DISCORD_TOKEN=your_discord_bot_token_here
# Your Discord user ID from step 4
ALLOWED_USER_ID=your_discord_user_id_here
# Base folder containing your repositories
# Each Discord channel will map to a subfolder here
# Example: if BASE_FOLDER=/Users/you/repos and channel is #my-project
# The bot will operate in /Users/you/repos/my-project
BASE_FOLDER=/path/to/your/repos
Organize your repositories under the base folder with names matching your Discord channels:
/path/to/your/repos/
├── my-project/ # Maps to #my-project channel
├── another-repo/ # Maps to #another-repo channel
├── test-app/ # Maps to #test-app channel
└── experimental/ # Maps to #experimental channel
Important: Channel names in Discord should match folder names exactly (Discord will convert spaces to hyphens).
In your Discord server, create channels for each repository:
#my-project
#another-repo
#test-app
#experimental
# Start the bot
bun run src/index.ts
# Or use the npm script
bun start
Important: Do not use hot reload (bun --hot
) as it can cause issues with process management and spawn multiple Claude processes.
You should see:
Bot is ready! Logged in as Claude Code Bot#1234
Successfully registered application commands.
Type any message in a channel that corresponds to a repository folder. The bot will run Claude Code with your message as the prompt and stream the results.
- Any message: Runs Claude Code with your message as the prompt
- /clear: Resets the current channel's session (starts fresh next time)
You: hello
Bot: 🔧 LS (path: .)
🔧 Read (file_path: ./package.json)
Hello! I can see this is a Node.js project. What would you like to work on?
✅ Completed (3 turns)
- Each Discord channel maps to a folder:
#my-project
→/path/to/repos/my-project
- Sessions persist per channel and automatically resume
- Shows real-time tool usage and responses
- Only responds to the configured
ALLOWED_USER_ID
For detailed setup instructions, troubleshooting, and development information, see CONTRIBUTING.md.
This project is licensed under the MIT License.