Sidequery
Thanks, you're subscribed!

← Blog

Turn DuckDB + Claude Code into a Slack Data Agent

A Slack data agent lets anyone on your team query databases in plain English. Natural language SQL without the SQL. No dashboards, no waiting for the data team. Just ask a question, get a CSV.

Your data team is drowning in ad-hoc requests. "What were sales last week?" "How many users signed up yesterday?" "Can you pull the top customers by region?" Each question means context switching, writing a query, exporting a CSV, uploading to Slack. Rinse and repeat.

What if anyone could just ask?

@DataBot what were our top 10 products by revenue last month?

And get a CSV back in seconds. No SQL knowledge required. No waiting for the data team.

Don't want to self-host? sidequery.ai does this out of the box →

The Stack

We built duckdb-claude-slack, an open-source text-to-SQL Slack bot that runs on top of DuckDB with duckdb-acp, our extension that wraps Claude Code. Think of it as an AI database assistant that lives in your team's Slack. The extension gives Claude read-only database access via the Agent Client Protocol while blocking filesystem and shell access.

The architecture:

  1. User mentions the bot in Slack
  2. Bot spins up a DuckDB instance with the ACP extension loaded
  3. The extension exposes two tools to Claude: run_sql and final_query
  4. Claude explores the schema, writes SQL, iterates on errors
  5. Results come back as a CSV attachment

Setup

Prerequisites

  • uv installed
  • Claude Code installed and authenticated
  • A Slack workspace where you can create apps

Create the Slack App

Go to api.slack.com/apps and create a new app from manifest. Use this configuration:

display_information:
  name: DataBot
  description: Query databases with natural language
  background_color: "#1a1a1a"
features:
  bot_user:
    display_name: DataBot
    always_online: true
  app_home:
    home_tab_enabled: false
    messages_tab_enabled: true
    messages_tab_read_only_enabled: false
oauth_config:
  scopes:
    bot:
      - app_mentions:read
      - channels:history
      - chat:write
      - files:write
      - groups:history
      - im:history
      - mpim:history
settings:
  event_subscriptions:
    bot_events:
      - app_mention
      - message.im
  interactivity:
    is_enabled: true
  org_deploy_enabled: false
  socket_mode_enabled: true
  token_rotation_enabled: false

Get Your Tokens

  1. App Token: Go to Basic Information → App-Level Tokens → Generate Token. Give it connections:write scope. Save the xapp-... token.

  2. Bot Token: Go to OAuth & Permissions → Install to Workspace. Save the xoxb-... token.

Configure Environment

Create a .env file:

SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_APP_TOKEN=xapp-your-app-token

Run the Bot

Point it at your database:

uvx duckdb-claude-slack --db ~/data/analytics.duckdb

Or connect to a remote database with init SQL:

uvx duckdb-claude-slack --init-sql setup.sql

Where setup.sql might contain:

INSTALL postgres;
LOAD postgres;
ATTACH 'postgresql://user:pass@host:5432/db' AS prod (TYPE POSTGRES, READ_ONLY);

Usage

Mention the bot in any channel it's invited to:

@DataBot which customers haven't ordered in 90 days?

Claude will:

  1. Explore available tables and schemas
  2. Write and test queries
  3. Iterate if something fails
  4. Return results as a CSV attachment

For complex questions, it might take 10-30 seconds as Claude thinks through the problem.

CLI Options

--db PATH          Attach a DuckDB file
--db-name NAME     Custom name for attached database (defaults to filename)
--init-sql FILE    SQL file to run on startup
--bot-token TOKEN  Override SLACK_BOT_TOKEN
--app-token TOKEN  Override SLACK_APP_TOKEN

Security Model

The bot runs with strict sandboxing:

  • Read-only queries: No INSERT, UPDATE, DELETE, or DDL
  • No filesystem access: Claude cannot read local files
  • No shell access: No bash or system commands

Claude only sees what's in the database connection you provide.

Self-hosted vs Hosted

This open-source version is great for tinkering, small teams, or if you want full control. But it's intentionally minimal.

What you get self-hosting:

  • DuckDB + any database DuckDB can attach to
  • CSV exports
  • Full control over the runtime

What you don't get:

  • Charts and visualizations
  • Secure credential storage (you're managing .env files)
  • Native connectors (Snowflake, BigQuery, etc. require manual DuckDB extension setup)
  • Concurrent queries (one conversation at a time)
  • Uptime guarantees (if your machine sleeps, the bot sleeps)
  • Team management, audit logs, or access controls

sidequery.ai is the hosted version with all of the above built in. Same natural language interface, but with managed infrastructure, charts, secure OAuth connections to your data sources, and a web dashboard for when Slack isn't enough.

Try It

# Install and run
uvx duckdb-claude-slack --db your-data.duckdb

github.com/sidequery/duckdb-claude-slack