Is Claude Code useful for data science?
Yes, for the coding side of data science. Claude Code reads your notebooks, scripts and SQL, runs Python in your own environment, fixes the errors it hits, and turns exploratory work into scripts and tests you can rerun. It does not replace your judgment on methods or results, so every number it reports still needs your review.
That split matters because data work is half code and half thinking. Claude Code is strong at the first half: loading messy files, writing pandas and SQL, debugging a KeyError three cells deep, and refactoring a long notebook into a module. The second half, deciding what question to ask and whether an answer holds up, stays with you. This guide covers what it can do, a workflow that keeps you in control, prompts to start from, and the guardrails worth setting before you point it at real data.
What can Claude Code do with notebooks and data files?
Claude Code is an agent that works in your project folder from the terminal, an IDE extension or the desktop app. For data work, a few built-in tools do most of the job. The tools reference documents each one:
- Reading notebooks. The Read tool returns
.ipynbfiles "with their outputs, including code, markdown, and visualizations." A notebook whose cells come to more than 256 KB returns an error, and a notebook file over 100 MB is refused with an error that tells Claude how to read a slice of cells with a shell command. - Editing notebooks. The NotebookEdit tool changes a notebook one cell at a time. It can replace a cell's source, insert a new code or markdown cell, or delete a cell.
- Running code. The Bash tool runs commands in your environment, so Claude can run a script, read the traceback and try again. It uses whatever Python, virtual environment and packages you have installed.
- Binary formats. Read refuses files it treats as binary, such as
.xlsxand.parquet. The error then points Claude to a skill for that type if one is available, or to a shell command or script that reads the format. - Charts. Read returns PNG, JPEG, GIF and WebP images as visual content, so Claude can save a plot to disk and look at it to check labels, scales and outliers.
- Databases. Through MCP servers, Claude can query a database directly, or it can use your own CLI tools.
On Pro, Max, Team and Enterprise plans, Claude Code can also publish results as artifacts: live, interactive web pages on claude.ai that you keep private or share. That suits a chart or a small dashboard you want a colleague to see without running your notebook.
What does a realistic data science workflow look like?
A workflow that holds up on real projects keeps Claude working in code and keeps you checking the outputs.
- Write down the ground rules. Run
/initto draft aCLAUDE.md, then add what Claude can't discover: how to activate the environment, where raw data lives, and that raw data is read-only. The CLAUDE.md guide covers the format. - Explore before editing. Start in plan mode (press
Shift+Tabuntil the status bar shows plan mode, or runclaude --permission-mode plan). Claude reads files and proposes a plan without changing anything. - Profile the data in code. Ask for a script that loads a sample, prints shape, types, missing values and value ranges, and saves a few diagnostic plots. Code you can rerun beats a one-off answer in the chat.
- Iterate with checks. Ask Claude to assert what it expects (row counts after joins, no duplicate keys, date ranges) so mistakes fail loudly instead of quietly skewing results.
- Promote notebook code. Once an analysis works, have Claude move the logic into functions in a module, add tests, and leave the notebook as a thin layer that calls them.
- Review the diff and the numbers. Read the changes, rerun the pipeline yourself, and spot-check a few results by hand before anything goes into a report.
A short CLAUDE.md for an analysis repo might look like this:
# Analysis repo
- Environment: run `uv run python ...`; never pip install globally.
- Raw data in data/raw/ is read-only. Write outputs to data/processed/.
- Work on data/sample/ unless I ask for the full dataset.
- Every transform gets a test in tests/. Run `uv run pytest` before saying a task is done.
- Report row counts before and after every join or filter.
Which prompts work well for data science?
Anthropic's prompt library gives two patterns that fit data work: give Claude a way to check its own work, and give it the artifact itself (the error, the log, the file) instead of your description of it. These prompts follow both. Replace the file names with your own.
Load data/sample/orders.csv, profile it (types, nulls, duplicates, value ranges) and save the profile as a markdown report in reports/. Flag anything that looks like a data quality problem.
This notebook fails at cell 14 with a KeyError on "customer_id". Find the cause, fix it in the earliest cell where it goes wrong, and rerun the notebook top to bottom to confirm.
Refactor analysis/churn.ipynb: move the cleaning and feature code into src/features.py as functions with docstrings, add pytest tests with small fixtures, and keep the notebook as calls to those functions.
Write a SQL query for monthly active users by plan for the last 12 months. Explain each join, then run it on the read-only database and compare the totals with the dashboard numbers in reports/mau.csv.
Fit a logistic regression for churn on the features in src/features.py. State the assumptions, check them in code, and report metrics on a held-out split. Do not tune on the test set.
For more, the data analysis prompts, SQL prompts and Python prompts collections are written to paste into an agent.
Which skills and MCP servers help?
Skills are folders with a SKILL.md file that Claude loads when a task matches. A few on this site fit data work:
| Need | Skill or server | What it adds |
|---|---|---|
| Python project setup | modern-python | uv, ruff, pytest and a clean project layout |
| Excel files | xlsx | Builds and edits spreadsheets with live formulas |
| PDF reports | Reads, merges, fills and creates PDFs | |
| Hugging Face datasets | huggingface-datasets and hf-cli | Dataset Viewer API and hf commands |
| Postgres | postgres best practices | Rules for indexes, pooling and locking |
| SQL databases | DBHub MCP server | Lets Claude query a relational database |
The Claude Code MCP docs show DBHub connected to PostgreSQL with a read-only user:
claude mcp add --transport stdio db -- npx -y @bytebase/dbhub \
--dsn "postgresql://readonly:pass@prod.db.com:5432/analytics"
Run /mcp afterward to confirm the server shows a checkmark. The same docs warn to verify you trust each server before connecting it, because servers that fetch external content can expose you to prompt injection.
How do you keep data safe while Claude Code works?
The data usage page is direct about what leaves your machine: "Claude Code runs locally. To interact with the LLM, Claude Code sends data over the network. This data includes all user prompts and model outputs." Anything Claude reads or prints becomes part of that conversation, so plan around it.
- Use samples. Point Claude at a sample or synthetic copy, and only run on full data once the code is right.
- Block folders it should never open. A
Readdeny rule such asRead(./data/pii/**)keeps Claude's file tools out, along with shell commands Claude Code recognizes, such ascat, that name the path. The permissions guide explains the syntax. - Protect raw data from edits. An
Edit(./data/raw/**)deny rule covers Claude's file-editing tools, recognized shell file commands such assedandtee, and redirects like> file. Anthropic's permissions docs say Read and Edit rules don't apply to a Python or Node script that opens files itself, which is how most data code works. For that, turn on the sandbox and add the folder to itsfilesystem.denyWritelist, since by default sandboxed commands can write anywhere in the working directory. - Use read-only credentials. A read-only database user means a bad query can't change data, whatever Claude intends.
- Check outputs, not just code. Code that runs can still be wrong. Spot-check joins, filters and aggregates against numbers you already trust.
Can Codex or Cursor do the same work?
Mostly, yes. The Codex CLI from OpenAI also works in your project folder, runs commands and edits files, and its local sandbox starts with network access off. Cursor's agent does the same from inside the editor: it can run terminal commands and edit code next to your open files. The workflow above carries over: written rules, plan first, code you can rerun, and your own review. See Codex vs Claude Code for how the two compare.
How do you reuse your best analysis prompts?
The prompts that work for your data, with your table names and quality checks, are worth keeping. Kipt stores prompts and Agent Skills as Markdown in a private GitHub repo you own, with {{name}} blanks for things like table or file names, and installs your skills into Claude Code or Codex with one npx skills add command. To turn one prompt into a skill right now, the free SKILL.md generator does it in the browser.