/guides/discord-bot
Discord bot
Deploy free-claude-code as a Discord bot. Remote autonomous coding with tree-based threading and live progress streaming.
Discord bot
Control Claude Code remotely from Discord. Send coding tasks, watch live progress, and manage multiple concurrent sessions from anywhere.
Features
- Tree-based threading: Reply to any message to fork the conversation
- Session persistence: Conversations survive server restarts
- Live streaming: See thinking tokens, tool calls, and results in real time
- Unlimited sessions: Concurrency controlled by
PROVIDER_MAX_CONCURRENCY - Voice notes: Send voice messages; transcribed and processed as prompts
- Commands:
/stop,/clear,/statsfor session management
Prerequisites
You need:
- A Discord account
- Permission to create bots (any Discord account has this)
- free-claude-code installed and running
Step 1: Create a Discord bot
- Go to Discord Developer Portal
- Click “New Application” and name it (e.g., “Claude Code Bot”)
- Navigate to “Bot” in the left sidebar
- Click “Add Bot” and confirm
- Under “Privileged Gateway Intents”, enable:
- Message Content Intent (required to read messages)
- Click “Reset Token” and copy the new token
Step 2: Invite the bot to your server
- In the Developer Portal, go to “OAuth2” → “URL Generator”
- Select scopes:
bot
- Select bot permissions:
- Read Messages/View Channels
- Send Messages
- Manage Messages
- Read Message History
- Copy the generated URL and open it in your browser
- Select the server to add the bot to
Step 3: Get channel IDs
Enable Developer Mode in Discord:
- Discord Settings → Advanced → Enable Developer Mode
Get your channel IDs:
- Right-click the channel where the bot should operate
- Click “Copy Channel ID”
- Save this ID
Repeat for multiple channels if needed.
Step 4: Configure free-claude-code
Edit .env:
MESSAGING_PLATFORM="discord"
DISCORD_BOT_TOKEN="your_discord_bot_token_here"
ALLOWED_DISCORD_CHANNELS="123456789,987654321"
Replace the channel IDs with your copied values. Comma-separate multiple channels.
Configure the workspace where Claude will operate:
CLAUDE_WORKSPACE="./agent_workspace"
ALLOWED_DIR="C:/Users/yourname/projects"
CLAUDE_WORKSPACE is where the bot clones repos and writes files. ALLOWED_DIR restricts which directories Claude can access.
Step 5: Start the server
uv run uvicorn server:app --host 0.0.0.0 --port 8082
The bot will connect to Discord and appear online in your server.
Using the bot
Basic usage
Send a message in an allowed channel:
Write a Python script that downloads the front page of Hacker News and extracts all article titles
The bot will:
- Acknowledge the request
- Stream thinking tokens (if enabled)
- Execute tool calls (file reads, edits, bash commands)
- Return the final result
Threading
Reply to any bot message to continue that conversation branch:
> [Your original request]
↳ [Bot response]
↳ [Your reply: "Now make it save to a JSON file"]
This creates a tree structure. You can have multiple parallel conversations with the same bot in different threads.
Commands
| Command | Action |
|---|---|
/stop | Cancel the current task |
/stop (as reply) | Cancel the specific task you replied to |
/clear | Reset all sessions |
/clear (as reply) | Clear only the conversation branch |
/stats | Show provider usage and rate limits |
Voice notes
Send a voice message in Discord. The bot will:
- Download the audio
- Transcribe using configured Whisper backend
- Process the transcribed text as a normal prompt
Configure voice transcription:
VOICE_NOTE_ENABLED=true
WHISPER_DEVICE="cpu" # Options: cpu, cuda, nvidia_nim
WHISPER_MODEL="base" # Options: tiny, base, small, medium, large-v2, large-v3, large-v3-turbo
For NVIDIA NIM voice transcription:
WHISPER_DEVICE="nvidia_nim"
WHISPER_MODEL="openai/whisper-large-v3"
NVIDIA_NIM_API_KEY="nvapi-your-key"
Install voice extras:
uv sync --extra voice_local # Local Whisper
uv sync --extra voice # NVIDIA NIM voice
Session management
Sessions persist across server restarts. The bot stores conversation state in CLAUDE_WORKSPACE.
To clear all sessions:
/clear
To stop a running task:
/stop
Rate limiting
Configure Discord-specific rate limits:
MESSAGING_RATE_LIMIT=1
MESSAGING_RATE_WINDOW=1
This prevents the bot from sending more than 1 message per second, avoiding Discord rate limits.
Security
- Restrict channels: Use
ALLOWED_DISCORD_CHANNELSto limit where the bot operates - Set allowed directories:
ALLOWED_DIRprevents Claude from accessing files outside your workspace - Use authentication: Set
ANTHROPIC_AUTH_TOKENto require authentication for proxy access
Troubleshooting
Bot shows offline: Check the token is correct. Reset the token if needed.
Bot doesn’t respond: Verify MESSAGING_PLATFORM="discord" is set. Check logs for connection errors.
“Channel not allowed” errors: Add the channel ID to ALLOWED_DISCORD_CHANNELS.
Voice notes not working: Verify voice extras are installed and VOICE_NOTE_ENABLED=true.
Sessions lost on restart: Ensure CLAUDE_WORKSPACE is a persistent directory, not a temp folder.