Claude Code中英文系列教程18:在Slack里面使用Claude Code

3 阅读12分钟

Delegate coding tasks directly from your Slack workspace 直接从你的 Slack 工作区委派编码任务

Claude Code in Slack brings the power of Claude Code directly into your Slack workspace. When you mention @Claude with a coding task, Claude automatically detects the intent and creates a Claude Code session on the web, allowing you to delegate development work without leaving your team conversations. Claude Code for Slack 将 Claude Code 的强大功能直接带入您的 Slack 工作空间。当您在 Slack 频道中提及 @Claude 并提出编程任务时,Claude 会自动识别意图并在网页上创建一个 Claude Code 会话,让您无需离开团队对话即可分配开发工作。

This integration is built on the existing Claude for Slack app but adds intelligent routing to Claude Code on the web for coding-related requests. 这项集成基于现有的 Claude for Slack 应用,但为编程相关的请求增加了智能路由到 Claude Code 网页版的功能。

一,Use cases 用例 Bug investigation and fixes: Ask Claude to investigate and fix bugs as soon as they’re reported in Slack channels. Bug调查和修复:在 Slack 频道中报告问题后,立即让 Claude 进行调查和修复。

Quick code reviews and modifications: Have Claude implement small features or refactor code based on team feedback. 快速代码审查和修改:让 Claude 根据团队反馈实现小功能或重构代码。

Collaborative debugging: When team discussions provide crucial context (e.g., error reproductions or user reports), Claude can use that information to inform its debugging approach. 协作调试:当团队讨论提供了关键背景信息(例如错误复现或用户报告)时,Claude 可以利用这些信息来指导其调试方法。

Parallel task execution: Kick off coding tasks in Slack while you continue other work, receiving notifications when complete. 并行任务执行:在 Slack 中启动编码任务,同时继续其他工作,并在任务完成时接收通知。

二,Prerequisites 前提条件 Before using Claude Code in Slack, ensure you have the following: 在使用 Slack 中的 Claude Code 之前,请确保您已准备好以下内容:

1.Claude Plan
Claude 计划

Pro, Max, Team, or Enterprise with Claude Code access (premium seats) 专业版、Max 版、团队版或企业版,具有 Claude Code 访问权限(高级席位)

2.Claude Code on the web 网页版 Claude Code

Access to Claude Code on the web must be enabled 必须启用Claude Code on the web 访问权限

3.GitHub Account GitHub 账号

Connected to Claude Code on the web with at least one repository authenticated 已通过网页连接到 Claude Code,并至少认证了一个仓库

4.Slack Authentication Slack 认证

Your Slack account linked to your Claude account via the Claude app 您的 Slack 账户通过 Claude app连接到您的 Claude 账户

三, Setting up Claude Code in Slack 在 Slack 中设置 Claude Code

3.1 Install the Claude App in Slack 在 Slack 中安装 Claude 应用

A workspace administrator must install the Claude app from the Slack App Marketplace. Visit the Slack App Marketplace and click “Add to Slack” to begin the installation process. 工作区管理员必须从 Slack 应用市场安装 Claude 应用。访问 Slack 应用市场,点击“添加到 Slack”开始安装过程。

slack.com/marketplace…

3.2 Connect your Claude account 连接您的 Claude 账户

After the app is installed, authenticate your individual Claude account: 应用安装后,请验证您的个人 Claude 账户:

  1. Open the Claude app in Slack by clicking on “Claude” in your Apps section 在 Slack 中通过点击你的应用部分中的“Claude”来打开 Claude 应用

2.Navigate to the App Home tab 导航到应用主页标签

3.Click “Connect” to link your Slack account with your Claude account 点击“连接”将你的 Slack 账号与 Claude 账号关联

4.Complete the authentication flow in your browser 在浏览器中完成身份验证流程

3.3 Configure Claude Code on the web 配置 Claude Code on the web

Ensure your Claude Code on the web is properly configured: 确保您的网页版 Claude Code 已正确配置:

Visit claude.ai/code and sign in with the same account you connected to Slack 访问 claude.ai/code 并使用您连接到 Slack 的同一账户登录

Connect your GitHub account if not already connected 如果尚未连接,请连接您的 GitHub 账户

Authenticate at least one repository that you want Claude to work with 至少认证一个你希望 Claude 与之工作的仓库

3.4 Choose your routing mode 选择你的路由模式

After connecting your accounts, configure how Claude handles your messages in Slack. Navigate to the Claude App Home in Slack to find the Routing Mode setting. 连接好你的账户后,配置 Claude 如何在 Slack 中处理你的消息。前往 Slack 中的 Claude 应用主页找到路由模式设置。

有以下2种Mode(模式)

1,Code only 仅代码

Claude routes all @mentions to Claude Code sessions. Best for teams using Claude in Slack exclusively for development tasks. Claude 会将所有@提及路由到 Claude Code 会话中。最适合仅在 Slack 中使用 Claude 进行开发任务的团队。

2,Code + Chat 代码+聊天

Claude analyzes each message and intelligently routes between Claude Code (for coding tasks) and Claude Chat (for writing, analysis, and general questions). Best for teams who want a single @Claude entry point for all types of work. Claude 分析每条消息,并智能地在 Claude Code(用于编程任务)和 Claude Chat(用于写作、分析和一般问题)之间进行路由。最适合希望为所有类型工作设置单一 @Claude 入口的团队。

In Code + Chat mode, if Claude routes a message to Chat but you wanted a coding session, you can click “Retry as Code” to create a Claude Code session instead. Similarly, if it’s routed to Code but you wanted a Chat session, you can choose that option in that thread. 在 Code + Chat 模式下,如果 Claude 将消息路由到 Chat 但您希望进行编程会话,可以点击“重试为代码”来创建一个 Claude Code 会话。 类似地,如果它被路由到 Code 但您希望进行 Chat 会话,也可以在该线程中选择该选项。

四,How it works 工作原理

4.1 Automatic detection 自动检测

When you mention @Claude in a Slack channel or thread, Claude automatically analyzes your message to determine if it’s a coding task. If Claude detects coding intent, it will route your request to Claude Code on the web instead of responding as a regular chat assistant. 当你在 Slack 频道或线程中提到@Claude 时,Claude 会自动分析你的消息以确定是否是编程任务。如果 Claude 检测到编程意图,它将你的请求路由到网络上的 Claude Code,而不是作为普通聊天助手进行回应。

You can also explicitly tell Claude to handle a request as a coding task, even if it doesn’t automatically detect it. 你也可以明确告诉 Claude 将请求处理为编程任务,即使它没有自动检测到。

Claude Code in Slack only works in channels (public or private). It does not work in direct messages (DMs). Claude Code 在 Slack 中仅在频道(公开或私有)中工作。它不适用于直接消息(DMs)。

4.2 Context gathering 收集上下文

1.From threads: When you @mention Claude in a thread, it gathers context from all messages in that thread to understand the full conversation. 从线程中:当你在线程中@提及 Claude 时,它会从该线程的所有消息中收集上下文,以理解整个对话。

2.From channels: When mentioned directly in a channel, Claude looks at recent channel messages for relevant context. 从频道中:当在频道中直接提及时,Claude 会查看最近的频道消息以获取相关上下文。

This context helps Claude understand the problem, select the appropriate repository, and inform its approach to the task. 这个上下文帮助 Claude 理解问题,选择合适的仓库,并为其任务方法提供信息。

When @Claude is invoked in Slack, Claude is given access to the conversation context to better understand your request. Claude may follow directions from other messages in the context, so users should make sure to only use Claude in trusted Slack conversations. 当在 Slack 中@调用 Claude 时,Claude 会获得访问对话上下文的权利,以更好地理解你的请求。Claude 可能会遵循上下文中其他消息的指示,因此用户应确保只在受信任的 Slack 对话中使用 Claude。

4.3 Session flow 会话流程

  1. Initiation: You @mention Claude with a coding request 启动:您通过@提及 Claude 并发送编程请求

  2. Detection: Claude analyzes your message and detects coding intent 检测:Claude 分析您的消息并检测编程意图

  3. Session creation: A new Claude Code session is created on claude.ai/code 会话创建:在 claude.ai/code 上创建一个新的 Claude Code 会话

  4. Progress updates: Claude posts status updates to your Slack thread as work progresses 进度更新:Claude 会随着工作的进展,在您的 Slack 聊天线程中发布状态更新

  5. Completion: When finished, Claude @mentions you with a summary and action buttons 完成:当工作完成后,Claude 会 @ 提及您,并提供摘要和操作按钮

  6. Review: Click “View Session” to see the full transcript, or “Create PR” to open a pull request 审阅:点击“查看会话”以查看完整记录,或“创建 PR”以打开拉取请求

五,User interface elements 用户界面元素

5.1 App Home 应用主页

The App Home tab shows your connection status and allows you to connect or disconnect your Claude account from Slack. 应用主页标签显示您的连接状态,并允许您将 Claude 账户连接到 Slack 或断开连接。

5.2 Message actions 消息操作

View Session: Opens the full Claude Code session in your browser where you can see all work performed, continue the session, or make additional requests. 查看会话:在您的浏览器中打开完整的 Claude Code 会话,您可以在其中查看所有已完成的工作,继续会话或发起新的请求。

Create PR: Creates a pull request directly from the session’s changes. 创建 PR:直接从会话的更改创建拉取请求。

Retry as Code: If Claude initially responds as a chat assistant but you wanted a coding session, click this button to retry the request as a Claude Code task. 以代码方式重试:如果 Claude 最初作为聊天助手响应,但您想要一个编码会话,请点击此按钮将请求重试为 Claude Code 任务。

Change Repo: Allows you to select a different repository if Claude chose incorrectly. 更改仓库:允许您选择不同的仓库,如果 Claude 选择错误。

5.3 Repository selection 仓库选择

Claude automatically selects a repository based on context from your Slack conversation. If multiple repositories could apply, Claude may display a dropdown allowing you to choose the correct one. Claude 根据您在 Slack 对话中的上下文自动选择一个仓库。如果多个仓库可能适用,Claude 可能会显示一个下拉菜单,让您选择正确的仓库。

六 Access and permissions 访问和权限

6.1 User-level access 用户级别的访问

1.Claude Code Sessions Claude Code 会话:

Each user runs sessions under their own Claude account 每个用户在自己的 Claude 账户下运行会话

2.Usage & Rate Limits 使用与速率限制

Sessions count against the individual user’s plan limits 会话次数会占用个人用户的计划限额

3.Repository Access 仓库访问

Users can only access repositories they’ve personally connected 用户只能访问他们已个人连接的仓库

  1. Session History 会话历史

Sessions appear in your Claude Code history on claude.ai/code 会话会出现在 claude.ai/code 上您的 Claude Code 历史记录中

6.2 Workspace admin permissions 工作区管理员权限

Slack workspace administrators control whether the Claude app can be installed in the workspace. Individual users then authenticate with their own Claude accounts to use the integration. Slack 工作区管理员控制是否可以在工作区安装 Claude 应用。然后个人用户使用自己的 Claude 账户进行身份验证以使用集成。

七,What’s accessible where 在哪里可以访问什么

1.In Slack: You’ll see status updates, completion summaries, and action buttons. The full transcript is preserved and always accessible. 在 Slack:你会看到状态更新、完成摘要和操作按钮。完整的会议记录被保留,并且始终可以访问。

2.On the web: The complete Claude Code session with full conversation history, all code changes, file operations, and the ability to continue the session or create pull requests. 在网页上:完整的 Claude Code 会话,包含完整的对话历史、所有代码更改、文件操作,以及继续会话或创建拉取请求的能力。

八,Best practices 最佳实践

8.1 Writing effective requests 编写有效的请求

Be specific: Include file names, function names, or error messages when relevant. 说明具体:在相关情况下,请包含文件名、函数名或错误信息。

Provide context: Mention the repository or project if it’s not clear from the conversation. 提供背景信息:如果对话中不明显,请提及仓库或项目。

Define success: Explain what “done” looks like—should Claude write tests? Update documentation? Create a PR? 定义成功标准:解释“完成”的状态——Claude 是否需要编写测试?更新文档?创建 PR?

Use threads: Reply in threads when discussing bugs or features so Claude can gather the full context. 使用线程:在讨论错误或功能时,请使用线程回复,以便 Claude 能够收集完整背景信息。

8.2 When to use Slack vs. web 何时使用 Slack 还是 网页

1.Use Slack when: Context already exists in a Slack discussion, you want to kick off a task asynchronously, or you’re collaborating with teammates who need visibility. 使用 Slack 的情况:当 Slack 讨论中已存在上下文、你想异步启动任务,或与需要了解情况的同学协作时。

2.Use the web directly when: You need to upload files, want real-time interaction during development, or are working on longer, more complex tasks. 直接使用网页的情况:当你需要上传文件、希望在开发过程中进行实时互动,或处理更长时间、更复杂的任务时。

九,Troubleshooting 故障排除

9.1 Sessions not starting 会话未启动

1.Verify your Claude account is connected in the Claude App Home 请确认您的 Claude 账户在 Claude 应用主页中已连接

2.Check that you have Claude Code on the web access enabled 检查您是否已启用 Claude Code 的网页访问功能

3.Ensure you have at least one GitHub repository connected to Claude Code 确保您至少有一个 GitHub 仓库已连接到 Claude Code

9.2 Repository not showing 仓库未显示 1.Connect the repository in Claude Code on the web at claude.ai/code 在 claude.ai/code 的 Claude Code 网页版中连接仓库

2.Verify your GitHub permissions for that repository 验证该仓库的 GitHub 权限

3.Try disconnecting and reconnecting your GitHub account 尝试断开并重新连接 GitHub 账户

9.3 Wrong repository selected 选错了仓库

1.Click the “Change Repo” button to select a different repository 点击“更换仓库”按钮选择其他仓库

  1. Include the repository name in your request for more accurate selection 在请求中包含仓库名称以便更准确地选择

9.4 Authentication errors 认证错误 1.Disconnect and reconnect your Claude account in the App Home 在应用主页断开并重新连接您的 Claude 账户

2.Ensure you’re signed into the correct Claude account in your browser 确保您在浏览器中登录了正确的 Claude 账户

3.Check that your Claude plan includes Claude Code access 检查您的 Claude 计划是否包含 Claude Code 访问权限

9.5 Session expiration 会话过期 1.Sessions remain accessible in your Claude Code history on the web 会话仍可通过网页访问 Claude Code 历史记录

2.You can continue or reference past sessions from claude.ai/code 您可以从 claude.ai/code 继续或参考过去的会话

十,Current limitations 当前限制 GitHub only: Currently supports repositories on GitHub. GitHub 仅限:目前仅支持 GitHub 上的存储库。

One PR at a time: Each session can create one pull request. 一次一个 PR:每个会话可以创建一个拉取请求。

Rate limits apply: Sessions use your individual Claude plan’s rate limits. 适用速率限制:会话使用您个人 Claude 计划的速率限制。

Web access required: Users must have Claude Code on the web access; those without it will only get standard Claude chat responses. 需要网页访问权限:用户必须 有Claude Code on the web 权限;没有访问权限的用户将只能获得标准 Claude 聊天回复。