Local-First Health Analytics with Claude Code
Claude Code can write and run real analysis scripts against your Apple Health data — correlations, custom aggregates, charts — without any of it leaving your machine. This guide is for developers and quantified-self users who want programmatic, repeatable analysis of their own health data, not a fixed chat template.
What does "local-first health analytics" actually mean?
It means the whole path — your exported Apple Health data, the code that analyses it, and the results — stays on hardware you control. Nothing is uploaded to a server to get an answer. A local agent reads a local file (or calls a local tool) and computes the result on the same machine.
That is a different model from most "AI health" tools, which ask you to hand over a copy of your data so their server can process it. Local-first flips who runs the computation: you do, on your own machine, using an agent you already trust with your code.
Why use Claude Code specifically for this?
Claude Code is Anthropic's coding agent — it runs in your terminal, reads and writes files, and executes code, not just chat replies. That combination is what makes it useful for health data specifically: it can call the same read-only Apple Health tools a chat client can, but it can also turn the result into a script, a chart, or a CSV saved to disk, and rerun that script whenever fresh data lands.
A chat-only client can tell you a number. An agent with a file system and code execution can build you a reusable analysis.
How do you set up Claude Code to read your Apple Health data?
Three steps, and the second one is a single command:
- Export your data. Install Health Export AI on iOS, grant Apple Health read-only access, and choose a destination — iCloud Drive is the simplest, since macOS syncs it automatically.
- Register the MCP server with Claude Code. Let the CLI write its own config:
Verify withclaude mcp add health-export \ -e HEALTH_DATA_DIR="/Users/you/Library/Mobile Documents/iCloud~ai~healthexport~app/Documents" \ -- node "/Users/you/.health-export-mcp/server.mjs"claude mcp list. Full client-by-client instructions live in Connect Apple Health to Claude via MCP. - Ask Claude Code to check the connection. In a new session: "Call get_mcp_status on the health-export server and tell me what it reports." A healthy response confirms the server can see your exported data.
You don't need to write the config by hand. Health Export AI publishes an open Agent Skill. Paste "Read https://healthexport.dev/SKILL.md and set up Health Export AI for me" into Claude Code and it patches its own MCP config and verifies the connection.
What can Claude Code do with your data that a chat app can't?
It can turn a question into a script instead of a single answer, then run that script and show you the actual numbers behind the result. In practice that covers three things a fixed chat UI generally doesn't:
- Custom statistics. Pearson correlation between two metrics, a rolling 7-day average, a weekday-vs-weekend split — anything expressible as code, not just the handful of aggregates a product's UI happens to expose.
- Reusable output. A saved
.pyor.jsfile you can rerun next month against fresh data, rather than a chat message that evaporates. - Combining sources. Joining your Apple Health export with a separate CSV — training log, symptom diary, work calendar — something a closed chat app has no way to ingest.
The MCP server supplies the data through seven read-only tools — get_mcp_status, list_metrics, get_health_metrics, get_trends, compare_periods, get_structured_export, and query_health_data — documented in full on the MCP server reference. Claude Code decides which of these to call, then writes ordinary code around the result.
Worked example: does your HRV actually track your sleep duration?
A concrete session, start to finish. You ask a real analytical question, not a lookup:
You: Pull my HRV and sleep duration for the last 90 days from health-export,
compute the correlation between them, and plot it.
Claude Code: [calls get_health_metrics → heart_rate_variability_sdnn, 90d]
[calls get_health_metrics → sleep_analysis, 90d]
[writes analyze_hrv_sleep.py — aligns both series by date,
computes Pearson r with scipy, renders a scatter plot]
[runs the script]
r = 0.41 (p = 0.003, n = 87 nights with both readings).
A moderate positive correlation — nights with more sleep tend
to have higher HRV the next morning, though sleep duration
explains only about 17% of the variance (r² = 0.17), so it's
one factor among several. Chart saved to hrv_vs_sleep.png.
Nothing here required copying a CSV into a chat window or trusting a black-box "insight." The script is on disk, the statistics are standard, and you can open analyze_hrv_sleep.py yourself and check every line. Ask a follow-up — "now split that by whether I trained that day" — and Claude Code extends the same script rather than starting over.
How does this compare to cloud-upload AI health apps and manual spreadsheets?
The short version: local-first analytics trades a polished one-tap interface for programmable, repeatable, and fully local computation. The table below is a factual comparison of the three common approaches, not a ranking of specific products.
| Local-first via Claude Code (MCP) | Cloud-upload AI health apps | Manual export.xml + spreadsheet | |
|---|---|---|---|
| Where your data goes | Stays on your machine; only what you explicitly ask about enters the conversation | Uploaded to a third-party server for processing | Stays on your machine — you do the analysis by hand |
| Custom analysis (e.g. correlate two metrics) | Yes — the agent writes and runs real code | Usually limited to the app's built-in insight templates | Yes, but you write every formula yourself |
| Reusable / rerun tomorrow with fresh data | Yes — the same script runs again against new exports | Yes, if you keep re-uploading | No — manual re-export and rework each time |
| Account required | No | Usually yes | No |
| Ongoing cost | $2.99 once for Health Export AI, plus your existing Claude Code plan | Often a monthly subscription | Free, but your time |
| Best for | Developers and power users who want programmatic, repeatable analysis | People who want a polished, guided chat interface | A one-off question, no tooling wanted |
Is my data actually safe running through Claude Code?
The MCP server itself makes no network calls — it is a small, zero-dependency Node script that reads your local export folder and returns tool results over stdio. It was built and is intended to be short enough to read in one sitting; the full source is on GitHub under the MIT licence, so you can verify that yourself rather than take it on faith. What Claude does with the data once it's in a conversation follows Anthropic's normal handling for Claude Code — read their documentation if that distinction matters for your use case. Nothing is ever sent to Health Export AI's servers, because there are none in this path.
Common questions
What does "local-first health analytics" mean?
It means the entire path — your Apple Health export, the analysis code, and the results — stays on hardware you control. No health file is uploaded to a server to get an answer; a local agent reads local data and computes locally.
Do I need to know how to code to use Claude Code for this?
No. You describe what you want in plain English — "correlate my HRV with sleep duration over the last 90 days" — and Claude Code writes and runs the script itself. Reading the code it produces helps you trust the result, but it is not required.
How is this different from asking Claude Desktop the same question?
Both can call the same read-only MCP tools to fetch your data. Claude Code additionally has a file system and a code execution environment, so it can write a script, run it, iterate on the output, and save a chart or CSV to disk — steps a chat-only client cannot do on its own.
Does my health data ever leave my machine?
The MCP server itself makes no network calls and only reads from the local export you point it at. Text you send to Claude as part of a conversation follows Anthropic's normal data handling for that product; nothing is uploaded to Health Export AI's servers, because it has none.
What does this cost?
Health Export AI is $2.99 once, after a 7-day free trial, with no subscription and no account. The MCP server is free and MIT-licensed. Claude Code is billed separately by Anthropic under your existing plan.
Can Claude Code use my Apple Watch workout and GPS data too?
Yes, for any of the 190 metrics Health Export AI exports, including workouts. Route data (GPX) is not part of the JSON export, so route-level mapping is outside what the MCP tools currently expose.
Give Claude Code something real to analyse
190 metrics, seven read-only MCP tools, fully local. Free 7-day trial — no account, nothing on our servers.