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:writescope - 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 .envEdit .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 prodBefore 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
When you set or check the working directory, the bot will display:
- Directory path
- Process ID (PID)
- Hostname
- 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-websitecwd /absolute/pathβ uses absolute path directly
The bot supports 3 permission modes for tool execution:
| Mode | Command | Description |
|---|---|---|
| π approval | approval on |
All tool executions require user approval (default) |
| π bypass | bypass on |
All tools execute without approval |
| π€ auto | auto on |
Tools execute automatically, only dangerous operations are blocked |
mode
In auto mode, the following dangerous operations are automatically blocked:
- File deletion:
rm -rf *,rm -rf /,rm ~, etc. - Git destructive operations:
git push --force,git reset --hard,git clean -fd - Permission changes:
sudo,chmod 777,chown -R - Remote code execution:
curl ... | sh,wget ... | bash - Environment variable exposure:
env,printenv,cat .env - Process operations:
kill -9,pkill,killall - Package publishing:
npm publish,yarn publish - Writing outside working directory
Share sessions between your PC terminal and Slack.
session
This displays:
- Session ID
- Working directory
- Process ID
- Hostname
- Resume command for your PC
session <session-id>
From Slack to PC:
- Run
sessionin Slack - Copy the displayed resume command
- Run it in your PC terminal:
cd /path/to/project && claude --resume <session-id>
From PC to Slack:
- Start
claudein your terminal - Copy the session ID from
~/.claude/projects/<project-dir>/ - In Slack:
session <session-id>
Note: Sessions are stored per working directory. You must run claude --resume from the same directory where the session was created.
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:
mcporservers - 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
| Command | Description |
|---|---|
cwd /path |
Set working directory |
cwd |
Show current working directory |
approval on |
Enable approval mode (default) |
bypass on |
Enable bypass mode |
auto on |
Enable auto mode |
mode |
Show current permission mode |
session |
Show session info |
session <id> |
Attach external session |
mcp |
Show MCP servers |
mcp reload |
Reload MCP configuration |
Set these environment variables:
CLAUDE_CODE_USE_BEDROCK=1
# AWS credentials should be configured via AWS CLI or IAM rolesSet these environment variables:
CLAUDE_CODE_USE_VERTEX=1
# Google Cloud credentials should be configuredEnable debug logging by setting DEBUG=true in your .env file:
DEBUG=trueThis 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