Skip to main content

Overview

klaw provides native Slack integration, allowing your team to interact with AI agents directly in Slack channels and threads. This guide walks you through setting up and configuring the integration.

Prerequisites

  • klaw installed and configured
  • Slack workspace admin access
  • API key configured

Step 1: Create a Slack App

1

Go to Slack API

Visit api.slack.com/apps and click Create New App.
2

Choose creation method

Select From scratch and give your app a name (e.g., “klaw”) and select your workspace.
3

Enable Socket Mode

Go to Socket Mode in the sidebar and enable it. Generate an App-Level Token with connections:write scope. Save this as SLACK_APP_TOKEN.
4

Configure OAuth scopes

Go to OAuth & Permissions and add these Bot Token Scopes:
  • app_mentions:read - Receive @mentions
  • chat:write - Send messages
  • channels:history - Read channel messages
  • channels:read - View channel info
  • groups:history - Read private channel messages
  • groups:read - View private channel info
  • im:history - Read DMs
  • im:read - View DM info
  • im:write - Send DMs
  • users:read - View user info
5

Enable Events

Go to Event Subscriptions and enable events. Subscribe to these bot events:
  • app_mention - When someone @mentions the bot
  • message.channels - Messages in channels
  • message.groups - Messages in private channels
  • message.im - Direct messages
6

Install to Workspace

Go to Install App and click Install to Workspace. Save the Bot User OAuth Token as SLACK_BOT_TOKEN.

Step 2: Configure Environment

Set the required environment variables:
export SLACK_BOT_TOKEN=xoxb-...
export SLACK_APP_TOKEN=xapp-...
export ANTHROPIC_API_KEY=sk-ant-...  # Or your preferred provider
For permanent configuration, add to your shell profile or ~/.klaw/config.toml:
[channel.slack]
enabled = true
bot_token = "${SLACK_BOT_TOKEN}"
app_token = "${SLACK_APP_TOKEN}"

Step 3: Start klaw

Start the klaw platform with Slack integration:
klaw start
You should see:
╭─────────────────────────────────────────╮
│               klaw                      │
│        AI Employee Platform            │
╰─────────────────────────────────────────╯
Provider:  anthropic
Model:     claude-sonnet-4-20250514
Namespace: default/default

Slack bot active. Listening for messages...
Scheduler running. Cron jobs will execute automatically.

Press Ctrl+C to stop

Step 4: Invite the Bot

In Slack, invite your bot to channels:
  1. Go to the channel where you want the bot
  2. Type /invite @klaw (or your bot’s name)
  3. The bot is now active in that channel

Interacting with the Bot

@Mention the Bot

@klaw help me understand this error message

Thread Conversations

Start a thread and continue the conversation:
User: @klaw explain this code
Bot:  [Explanation in thread]
User: Can you refactor it?
Bot:  [Refactored code in same thread]
The bot maintains context within threads.

Route to Specific Agents

Use @agent syntax to route to specific agents:
@klaw @researcher find best practices for Go error handling
@klaw @coder implement those patterns

Setting Up Agents

Create agents for your Slack workspace:
# Create agents
klaw create agent coder \
  --model claude-sonnet-4-20250514 \
  --skills code-exec,git

klaw create agent researcher \
  --model claude-sonnet-4-20250514 \
  --skills web-search,browser

klaw create agent devops \
  --model claude-sonnet-4-20250514 \
  --skills docker,git
View your agents:
klaw get agents

Scheduled Tasks (Cron)

Set up automated tasks in Slack:

Create from CLI

klaw cron create daily-standup \
  --schedule "0 9 * * 1-5" \
  --agent reporter \
  --task "Generate daily standup summary from yesterday's activity"

Create from Slack

In Slack, tell the bot to create a cron job:
@klaw Create a cron job that runs every morning at 9am
to summarize the #engineering channel activity
The bot will use the cron_create tool automatically.

Manage Cron Jobs

klaw cron list
klaw cron enable daily-standup
klaw cron disable daily-standup

Channel-Specific Monitoring

Set up monitoring for specific channels:
@klaw Monitor this channel every 5 minutes and alert
if anyone mentions "urgent" or "production issue"
The bot will create a cron job that:
  1. Reads new messages from the channel
  2. Analyzes them based on your criteria
  3. Responds in threads when matches are found

Configuration Options

Namespace Binding

Bind Slack channels to specific namespaces:
apiVersion: klaw.sh/v1
kind: ChannelBinding
metadata:
  name: slack-engineering
  namespace: engineering
spec:
  channel: slack
  config:
    allowed_channels:
      - C0123456789  # #engineering
    default_agent: coder

Orchestrator Rules

Configure message routing:
[orchestrator]
mode = "hybrid"
default_agent = "coder"

[[orchestrator.rules]]
pattern = "(?i)(deploy|kubernetes|docker)"
agent = "devops"

[[orchestrator.rules]]
pattern = "(?i)(research|find|search)"
agent = "researcher"

Best Practices

Only invite the bot to channels where it’s needed. This reduces noise and improves response relevance.
Encourage users to start threads for conversations. This keeps channels clean and maintains context better.
Consider creating dedicated channels like #klaw-tasks or #ai-assistant for AI interactions.
For busy channels, consider rate limiting to prevent overwhelming the system.

Troubleshooting

  1. Check if the bot is invited to the channel
  2. Verify Socket Mode is enabled in Slack app settings
  3. Check klaw start output for errors
  4. Ensure tokens are correctly set
  1. Check your API provider’s status
  2. Consider using a faster model (Haiku for simple tasks)
  3. Reduce the number of tools/skills for faster processing
  1. Ensure channels:history scope is granted
  2. Check if the bot has access to the channel
  3. For private channels, add groups:history scope

Next Steps