This guide shows you how to connect Claude to your codebase so you can ask questions about your code directly in Slack. You'll be able to ask things like "What does the authentication module do?" or "Where is the payment retry logic?" and get accurate, grounded answers with citations to the relevant files. You'll need an Anthropic API key, a Slack workspace where you can install apps, and a codebase that Claude can access (via a connected repository or by indexing local files).

What You'll Need

  • An Anthropic API key (from console.anthropic.com)
  • A Slack workspace with permissions to install apps
  • Access to the codebase you want to query (local or remote repository)
  • Node.js (v18 or later) installed on your machine or server
  • A hosting option for the bot (local machine, VPS, or cloud service)

Step-by-Step

  1. Set up the Claude Slack app
    Go to api.slack.com/apps and click "Create New App." Choose "From an app manifest" and select your workspace. Copy the manifest below into the YAML tab, then replace your-bot-token and your-signing-secret placeholders with actual values after you generate them (steps 2-3). The manifest defines the bot's permissions and event subscriptions.
  2. Generate bot token and signing secret
    In your Slack app settings, go to "OAuth & Permissions" and click "Install to Workspace." Note the Bot User OAuth Token (starts with xoxb-). Then go to "Basic Information" and copy the Signing Secret. Store these securely.
  3. Configure event subscriptions
    In the Slack app settings, go to "Event Subscriptions." Enable it and set the Request URL to your server's endpoint (e.g., https://your-domain.com/slack/events). Under "Subscribe to bot events," add app_mention and message.im. Save changes.
  4. Prepare your codebase index
    Claude needs a searchable index of your code. Use a tool like claude-code (Anthropic's CLI) to generate an index of your repository. Run claude-code index in your project root. This creates a .claude-index file that maps symbols, functions, and file paths.
  5. Write the Slack bot script
    Create a new Node.js project and install dependencies: npm install @slack/bolt @anthropic-ai/sdk. Write a script that listens for mentions and direct messages, extracts the question, queries the Claude API with the codebase index as context, and posts the answer back.
  6. Add the codebase context
    When calling the Claude API, include the index file content as part of the system prompt. For example: system: "You are a helpful assistant with access to the following codebase index: " + indexContent. This lets Claude reference specific files and functions.
  7. Handle Slack events
    Use the Bolt framework to handle events. Example code:
    const { App } = require('@slack/bolt');
    const app = new App({ token: process.env.SLACK_BOT_TOKEN, signingSecret: process.env.SLACK_SIGNING_SECRET });
    app.event('app_mention', async ({ event, say }) => {
      const question = event.text.replace(/<@[^>]+>/, '').trim();
      const answer = await askClaude(question);
      await say({ text: answer, thread_ts: event.ts });
    });
      
    Replace askClaude with your API call function.
  8. Deploy the bot
    Run the script on a server that's publicly accessible (for Slack to send events). Use a process manager like PM2 or a cloud function. Set the Request URL in Slack to your deployed endpoint.
  9. Test in Slack
    Invite the bot to a channel, then mention it with a question like "@claude What does the user service do?" The bot should respond with an answer and file references.
  10. Refine and expand
    Add features like handling file uploads, supporting multiple repositories, or caching answers. Monitor usage and adjust the index as your code evolves.

Common Mistakes

  • Forgetting to update the index – The codebase index becomes stale quickly. Re-run claude-code index after significant changes.
  • Not scoping permissions – The bot might have access to too many channels. Restrict it to specific channels using Slack's app configuration.
  • Exposing sensitive code – If your repo contains secrets, they might be included in the index. Use .gitignore and configure the indexer to exclude sensitive files.
  • Ignoring Slack rate limits – Slack has rate limits on API calls. Implement retry logic with exponential backoff.
  • Not handling errors – If the Claude API times out, the bot should respond with a friendly error message rather than crashing.

Tips

  • Use threads – Always reply in a thread to keep channels tidy and avoid spamming.
  • Provide context – When asking, instruct users to be specific: "In the payment service, how is the refund handled?"
  • Cache frequent answers – Store responses for common questions to reduce API costs.
  • Log interactions – Keep logs of questions and answers to improve the index and identify gaps.
  • Test with edge cases – Try questions about deleted files, renamed functions, or ambiguous terms to see how the bot handles them.

Troubleshooting

  • Bot doesn't respond – Check the Slack event subscription URL is reachable. Use a tool like ngrok for local testing. Verify the bot token has the chat:write scope.
  • Answers are wrong or generic – The index might be outdated or incomplete. Re-index the codebase. Ensure the system prompt clearly instructs Claude to use the index and cite paths.
  • API errors (e.g., 401) – Check your Anthropic API key is valid and has sufficient credits. Verify the environment variable is set correctly.
  • Slack shows "Failed to post" – The bot might not be in the channel. Invite it explicitly. Also check that the signing secret matches.
  • Bot works locally but not in production – Ensure the production server has the correct environment variables and that the Slack Request URL is updated to the production endpoint.

Frequently Asked Questions

Do I need to upload my entire codebase to the cloud?

No. The index file contains only metadata (symbols, paths, descriptions), not the full source. However, if you use a cloud-hosted index, ensure it's encrypted and access-controlled.

Can I use this with a private repository?

Yes, as long as the server running the bot has access to the repository (e.g., via SSH keys). The index is generated locally, and only the index is sent to Claude.

How often should I update the index?

Ideally, after every merge to the main branch. You can automate this with a CI/CD hook that runs claude-code index and updates the file.

Does Claude understand multiple programming languages?

Yes, Claude is multilingual in code. The indexer supports most popular languages including Python, JavaScript, TypeScript, Java, Go, and Rust.

Can I restrict the bot to answer only about certain directories?

Yes. Modify the system prompt to say "Only answer questions about the /src directory" or filter the index content before sending.

What if the bot gives an answer that references a file that no longer exists?

That usually means the index is stale. Update the index and consider adding a check in the bot to verify file existence before responding.