Claude Skills Guide

Claude Code for Metabase Analytics Workflow Guide

Metabase is an open-source business intelligence tool that makes data querying accessible to teams without deep SQL expertise. When combined with Claude Code, you can create powerful analytics workflows that automate data exploration, generate insights, and streamline reporting. This guide shows you how to integrate Claude Code with Metabase effectively.

Understanding the Metabase-Code Integration

Claude Code can interact with Metabase through its REST API, enabling you to programmatically:

The integration works by having Claude Code make HTTP requests to your Metabase instance, passing queries and processing the returned data. This approach keeps your analytics infrastructure secure while giving you the power of natural language to drive data workflows.

Setting Up Your Metabase Connection

Before building workflows, configure Claude Code to communicate with your Metabase instance. You’ll need your Metabase URL and an API key.

Create a skill that handles the connection:

SKILL_METABASE_QUERY
---
description: Query Metabase and return formatted results
tools: [bash, read_file, write_file]
---

When asked to query Metabase or get data from Metabase:

1. Use curl to make requests to your Metabase instance
2. The base URL is stored in environment variable METABASE_URL
3. The API key is stored in METABASE_API_KEY
4. Format responses as clean markdown tables

Example query structure:
curl -X GET "${METABASE_URL}/api/card/{card_id}/query" \
  -H "X-Api-Key: ${METABASE_API_KEY}"

This skill template gives Claude Code the context it needs to make appropriate API calls when you request analytics data.

Querying Data with Claude Code

The most common workflow is asking Claude Code to retrieve specific data from Metabase. Here’s how to structure your queries effectively.

Direct Question Queries

When you know the question ID in Metabase, you can retrieve results directly:

# Get results from a specific question
curl -X GET "https://your-metabase.com/api/card/123/query" \
  -H "X-Api-Key: your-api-key" \
  -H "Content-Type: application/json"

Claude Code can then process these results, filter them, or transform them for specific needs. For example, you might ask Claude to “get last month’s sales data and calculate the week-over-week growth percentage.”

Native SQL Queries

For complex analyses, use Metabase’s native query functionality:

# Execute a native SQL query
curl -X POST "https://your-metabase.com/api/dataset" \
  -H "X-Api-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "native",
    "native": {
      "query": "SELECT date_trunc(\"week\", created_at) as week, count(*) as orders FROM orders GROUP BY 1 ORDER BY 1 DESC LIMIT 12"
    },
    "database": 1
  }'

This approach lets you use Metabase’s database connections while using Claude Code to construct and execute sophisticated queries.

Automating Recurring Analytics

One of the most valuable use cases is automating recurring analytical tasks. Set up scheduled queries that Claude Code can execute and process.

Daily Report Generation

Create a workflow that pulls key metrics each morning:

#!/bin/bash
# daily-metrics.sh - Run daily analytics

METABASE_URL="https://your-metabase.com"
METABASE_API_KEY="your-key"

# Get key metrics
revenue=$(curl -s -X GET "${METABASE_URL}/api/card/456/query" \
  -H "X-Api-Key: ${METABASE_API_KEY}" | jq -r '.data.rows[0][0]')

new_users=$(curl -s -X GET "${METABASE_URL}/api/card/789/query" \
  -H "X-Api-Key: ${METABASE_API_KEY}" | jq -r '.data.rows[0][0]')

echo "Revenue: $revenue"
echo "New Users: $new_users"

Schedule this with cron, and Claude Code can further process the output, comparing against benchmarks or formatting for team notifications.

Alert Detection

You can also build detection workflows that check for anomalies:

# Check if today's orders exceed threshold
orders_today=$(curl -s "${METABASE_URL}/api/card/111/query" \
  -H "X-Api-Key: ${METABASE_API_KEY}" | jq '.data.rows[0][0]')

threshold=1000
if [ "$orders_today" -gt "$threshold" ]; then
  echo "ALERT: Orders ($orders_today) exceed threshold ($threshold)"
  # Trigger notification
fi

Building Interactive Dashboards

Claude Code can help you construct Metabase dashboards programmatically. While the visual builder is intuitive, using the API allows for template-based dashboard creation.

Creating Questions via API

# Create a new question
curl -X POST "https://your-metabase.com/api/card" \
  -H "X-Api-Key: ${METABASE_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Weekly Active Users",
    "display": "line",
    "visualization_settings": {
      "graph.dimensions": ["created_at"],
      "graph.metrics": ["count"]
    },
    "dataset_query": {
      "type": "native",
      "native": {
        "query": "SELECT date_trunc(\"week\", created_at) as week, count(distinct user_id) as active_users FROM events GROUP BY 1"
      },
      "database": 1
    },
    "collection_id": 5
  }'

This enables you to generate questions from templates, useful when you need consistent metrics across different segments or time periods.

Best Practices for Production Workflows

When deploying Metabase-Claude integrations in production, follow these guidelines:

Security First: Never expose API keys in code repositories. Use environment variables or secret management systems. Rotate keys periodically and restrict API access to specific IP addresses when possible.

Error Handling: Implement retry logic for API calls, as network issues can occur. Set appropriate timeouts and log failures for debugging:

# With retry logic
for i in 1 2 3; do
  response=$(curl -s -w "%{http_code}" -o /tmp/result.json \
    "${METABASE_URL}/api/card/123/query" \
    -H "X-Api-Key: ${METABASE_API_KEY}")
  
  if [ "$response" = "200" ]; then
    break
  fi
  sleep 5
done

Rate Limiting: Metabase’s API has rate limits. Space out your requests and cache results when appropriate. For frequently accessed data, consider implementing a caching layer.

Version Compatibility: Metabase updates can change API endpoints. Test your integrations after upgrades and pin your automation to specific Metabase versions when stability is critical.

Advanced: Chaining Multiple Data Sources

For complex analytical workflows, you can pull from multiple Metabase questions or databases in sequence. Claude Code excels at this by processing intermediate results:

  1. Query a summary question (e.g., total sales by region)
  2. Identify underperforming regions
  3. Query detailed data for those regions
  4. Generate a formatted report with insights

This chaining approach lets you build sophisticated analytical pipelines that adapt based on the data encountered.

Conclusion

Integrating Claude Code with Metabase transforms your analytics workflow from manual exploration to automated, intelligent data processing. Start with simple query workflows, then build toward complex automated pipelines that deliver insights directly to your team. The combination of Metabase’s visual analytics and Claude Code’s natural language processing creates a powerful analytics stack accessible to the whole organization.

Remember to secure your API credentials, implement proper error handling, and gradually expand your automation as your workflows mature. With these practices in place, you’ll have a scalable analytics infrastructure that grows with your team’s needs.

Built by theluckystrike — More at zovo.one