Claude Code Slack Bot
Connect your local Claude Code agent with Slack
Ask AI about Claude Code Slack Bot
Powered by Claude Β· Grounded in docs
I know everything about Claude Code Slack Bot. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Claude Code Slack Bot
A Slack bot that integrates with Claude Code SDK to provide AI-powered coding assistance directly in your Slack workspace.
Features
- π€ Direct message support - chat with the bot privately
- π¬ Thread support - maintains conversation context within threads
- π Streaming responses - see Claude's responses as they're generated
- π Markdown formatting - code blocks and formatting are preserved
- π§ Session management - maintains conversation context across messages
- β‘ Real-time updates - messages update as Claude thinks
Prerequisites
- Node.js 18+ installed
- A Slack workspace where you can install apps
- Claude Code
Setup
1. Clone and Install
git clone <your-repo>
cd claude-code-slack
npm install
2. Create Slack App
Option A: Using App Manifest (Recommended)
- Go to api.slack.com/apps and click "Create New App"
- Choose "From an app manifest"
- Select your workspace
- Paste the contents of
slack-app-manifest.json(orslack-app-manifest.yaml) - Review and create the app
Option B: Manual Configuration
- Go to api.slack.com/apps and create a new app
- Choose "From scratch" and give your app a name
- Select the workspace where you want to install it
3. Configure Slack App
After creating the app (either method), you need to:
Generate Tokens
- Go to "OAuth & Permissions" and install the app to your workspace
- Copy the "Bot User OAuth Token" (starts with
xoxb-) - Go to "Basic Information" β "App-Level Tokens"
- Generate a token with
connections:writescope - Copy the token (starts with
xapp-)
Get Signing Secret
- Go to "Basic Information"
- Copy the "Signing Secret"
4. Configure Environment
Copy .env.example to .env and fill in your credentials:
cp .env.example .env
Edit .env:
# Slack App Configuration
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_APP_TOKEN=xapp-your-app-token
SLACK_SIGNING_SECRET=your-signing-secret
# Claude Code Configuration
# This is only needed if you don't use a Claude subscription
# ANTHROPIC_API_KEY=your-anthropic-api-key
# CLAUDE_CODE_USE_BEDROCK=1
# CLAUDE_CODE_USE_VERTEX=1
5. Run the Bot
# Development mode (with auto-reload)
npm run dev
# Production mode
npm run build
npm run prod
Usage
Setting Working Directory
Before using Claude Code, you must set a working directory. This tells Claude where your project files are located.
Set working directory:
Relative paths (if BASE_DIRECTORY is configured):
cwd project-name
Absolute paths:
cwd /path/to/your/project
or
set directory /path/to/your/project
Check current working directory:
cwd
or
get directory
Working Directory Scope
- Direct Messages: Working directory is set for the entire conversation
- Channels: Working directory is set for the entire channel (prompted when bot joins)
- Threads: Can override the channel/DM directory for a specific thread by mentioning the bot
Base Directory Configuration
You can configure a base directory in your .env file to use relative paths:
BASE_DIRECTORY=/Users/username/Code/
With this set, you can use:
cwd herd-websiteβ resolves to/Users/username/Code/herd-websitecwd /absolute/pathβ uses absolute path directly
Direct Messages
Simply send a direct message to the bot with your request:
@ClaudeBot Can you help me write a Python function to calculate fibonacci numbers?
In Channels
When you first add the bot to a channel, it will ask for a default working directory for that channel.
Mention the bot in any channel where it's been added:
@ClaudeBot Please review this code and suggest improvements
Thread-Specific Working Directories
You can override the channel's default working directory for a specific thread:
@ClaudeBot cwd different-project
@ClaudeBot Now help me with this specific project
Threads
Reply in a thread to maintain conversation context. The bot will remember previous messages in the thread.
File Uploads
You can upload files and images directly to any conversation:
Supported File Types:
- Images: JPG, PNG, GIF, WebP, SVG
- Text Files: TXT, MD, JSON, JS, TS, PY, Java, etc.
- Documents: PDF, DOCX (limited support)
- Code Files: Most programming languages
Usage:
- Upload a file by dragging and dropping or using the attachment button
- Add optional text to describe what you want Claude to do with the file
- Claude will analyze the file content and provide assistance
Note: Files are temporarily downloaded for processing and automatically cleaned up after analysis.
MCP (Model Context Protocol) Servers
The bot supports MCP servers to extend Claude's capabilities with additional tools and resources.
Setup MCP Servers
-
Create MCP configuration file:
cp mcp-servers.example.json mcp-servers.json -
Configure your servers in
mcp-servers.json:{ "mcpServers": { "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/files"] }, "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": { "GITHUB_TOKEN": "your-token" } } } }
MCP Commands
- View configured servers:
mcporservers - Reload configuration:
mcp reload
Available MCP Servers
- Filesystem: File system access (
@modelcontextprotocol/server-filesystem) - GitHub: GitHub API integration (
@modelcontextprotocol/server-github) - PostgreSQL: Database access (
@modelcontextprotocol/server-postgres) - Web Search: Search capabilities (custom servers)
All MCP tools are automatically allowed and follow the pattern: mcp__serverName__toolName
Advanced Configuration
Using AWS Bedrock
Set these environment variables:
CLAUDE_CODE_USE_BEDROCK=1
# AWS credentials should be configured via AWS CLI or IAM roles
Using Google Vertex AI
Set these environment variables:
CLAUDE_CODE_USE_VERTEX=1
# Google Cloud credentials should be configured
Development
Debug Mode
Enable debug logging by setting DEBUG=true in your .env file:
DEBUG=true
This will show detailed logs including:
- Incoming Slack messages
- Claude SDK request/response details
- Session management operations
- Message streaming updates
Project Structure
src/
βββ index.ts # Application entry point
βββ config.ts # Configuration management
βββ types.ts # TypeScript type definitions
βββ claude-handler.ts # Claude Code SDK integration
βββ slack-handler.ts # Slack event handling
βββ working-directory-manager.ts # Working directory management
βββ logger.ts # Logging utility
Available Scripts
npm run dev- Start in development mode with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Run the compiled JavaScriptnpm run prod- Run production build
Troubleshooting
Bot not responding
- Check that the bot is running (
npm run dev) - Verify all environment variables are set correctly
- Ensure the bot has been invited to the channel
- Check Slack app permissions are configured correctly
Authentication errors
- Verify your Anthropic API key is valid
- Check Slack tokens haven't expired
- Ensure Socket Mode is enabled
Message formatting issues
The bot converts Claude's markdown to Slack's formatting. Some complex formatting may not translate perfectly.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
