What Claude Code does for data analysis
- Answers questions with SQL against a read-only role or replica, and shows the query with the answer.
- Cleans and analyses CSV exports with Python, and draws the charts.
- Writes a weekly metrics digest: what moved, by how much, and the likely reason.
- Flags anomalies, such as a drop in sign-ups or a spike in errors, before someone has to notice.
Claude Code features for data analysis
| Feature | What it does | How to start |
|---|---|---|
| Database CLI or MCP server | Queries your database or warehouse; give it a read-only role | psql, bq or your warehouse's MCP server via claude mcp add |
| Python in the session | Cleans CSVs, joins exports and draws charts | Ask for an analysis of a file in the working folder |
--json-schema | Returns the answer as JSON that matches your schema | claude -p ... --output-format json --json-schema |
| Scheduled tasks | A weekly digest without opening a session | /schedule weekly metrics digest on Monday at 9am |
How to set up Claude Code for data analysis
Connect the tools
Create a read-only database role and give Claude Code that connection, or your warehouse CLI signed in as a read-only user. For one-off analysis, put the CSV exports in the working folder.
-- Postgres: a read-only role for the agent CREATE ROLE analyst LOGIN PASSWORD '<password>'; GRANT pg_read_all_data TO analyst;Write the rules in CLAUDE.md
Claude Code reads CLAUDE.md at the start of every session,
claude -pruns included. Put the job's rules there, or in a skill under.claude/skills/if they're long. See the CLAUDE.md guide.## Data rules - Read-only: use the analytics role, never the app's database user. No INSERT, UPDATE, DELETE or schema changes. - Show the query or script behind every number. - Compare with the period before, and say when a change is within normal noise. - Don't export personal data; aggregate before you write anything down. - Weekly digest: the five numbers that matter, what moved, and one question worth asking next week.Run it without the interactive interface
claude -pruns one task and exits, so cron, CI or another tool can start it. Choose what it may do without asking with--allowedToolsor--permission-mode;--output-format jsonreturns the result with its cost.# Last week's numbers as JSON for a dashboard or a post claude -p "Compute last week's sign-ups, activation and revenue vs the week before" \ --output-format json --json-schema "$(cat metrics.schema.json)"Put it on a schedule
Make it a cloud scheduled task with
/schedule(Pro, Max, Ultra, Team and Enterprise), a desktop scheduled task, or/loopwhile a session stays open. See how to make Claude Code proactive.
Limits and safety
- Give it a read-only role. An agent with write access to the database can change it.
- It can misread what a column means. Write a short data dictionary and check its first answers.
- Large results cost context and usage. Query and aggregate before reading rows.
- Since Claude Code v2.1.302,
claude -pstarts in Manual mode: an action that needs approval is denied unless a rule allows it. Allow only the tools the job needs.
Claude Code or Codex for data analysis?
The rules carry over. Write them once in AGENTS.md and put @AGENTS.md in CLAUDE.md, and both agents read the same file.
Step by step for the other agent: data analysis with Codex.
| Claude Code | Codex | |
|---|---|---|
| Rules file | CLAUDE.md | AGENTS.md |
| Connect tools | claude mcp add | codex mcp add or config.toml |
| Run without you | claude -p | codex exec |
| Schedule | /schedule, desktop scheduled tasks, /loop | Scheduled tasks in the ChatGPT app, cron |
| Built in for data analysis | --json-schema structured output | --output-schema structured output |
Make data analysis someone's job
Commands run when someone remembers to run them. Crewmark turns your own Claude Code into an AI employee with a role, a goal in numbers, working hours and a heartbeat, so the work happens on schedule and shows up on a board.
Start from the role
The AI employee roles, with these rules in its brief.
Put the work on its board
Add the job as a recurring issue. The employee wakes on its heartbeat, does it and reports in a comment.
Related
The daily SEO report is a worked example of a recurring analytics job.
FAQ
Can Claude Code do data analysis?
Yes. It writes and runs SQL and Python, reads CSVs, draws charts and explains the results. Give it a read-only role and ask it to show the query behind every number.
How do I get structured output from Claude Code?
Run claude -p with --output-format json and --json-schema; the answer comes back in the structured_output field.
Is it safe to connect Claude Code to a production database?
Connect it to a read replica or with a read-only role, never the application's own user, and keep personal data aggregated.
Checked against Claude Code's and OpenAI's Codex documentation on November 13, 2026.