A Slack bot that integrates with Claude Code SDK to provide AI-powered coding assistance directly in your Slack workspace.
- 🤖 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
- Node.js 18+ installed
- A Slack workspace where you can install apps
- Claude Code
git clone <your-repo>
cd claude-code-slack
npm install
- 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
- 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
After creating the app (either method), you need to:
- 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:write
scope - Copy the token (starts with
xapp-
)
- Go to "Basic Information"
- Copy the "Signing Secret"
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
# Development mode (with auto-reload)
npm run dev
# Production mode
npm run build
npm run prod
Before using Claude Code, you must set a working directory. This tells Claude where your project files are located.
Relative paths (if BASE_DIRECTORY is configured):
cwd project-name
Absolute paths:
cwd /path/to/your/project
or
set directory /path/to/your/project
cwd
or
get directory
- 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
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-website
cwd /absolute/path
→ uses absolute path directly
Simply send a direct message to the bot with your request:
@ClaudeBot Can you help me write a Python function to calculate fibonacci numbers?
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
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
Reply in a thread to maintain conversation context. The bot will remember previous messages in the thread.
You can upload files and images directly to any conversation:
- 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
- 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.
The bot supports MCP servers to extend Claude's capabilities with additional tools and resources.
-
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" } } } }
- View configured servers:
mcp
orservers
- Reload configuration:
mcp reload
- 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
Set these environment variables:
CLAUDE_CODE_USE_BEDROCK=1
# AWS credentials should be configured via AWS CLI or IAM roles
Set these environment variables:
CLAUDE_CODE_USE_VERTEX=1
# Google Cloud credentials should be configured
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
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
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
- 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
- Verify your Anthropic API key is valid
- Check Slack tokens haven't expired
- Ensure Socket Mode is enabled
The bot converts Claude's markdown to Slack's formatting. Some complex formatting may not translate perfectly.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT