{"slug": "how-to-give-claude-code-access-to-your-apple-health-data", "title": "How to give Claude Code access to your Apple Health data", "summary": "A developer built health4.ai, an open-source iOS app and MCP server that gives Claude Code and other AI agents access to Apple Health data. The app syncs HealthKit data to a user-controlled Postgres database, bypassing Apple's lack of a HealthKit REST API. The MCP server exposes 11 tools for querying health metrics, and the entire system keeps data on the user's own infrastructure.", "body_md": "Apple has no HealthKit REST API. Claude's native Apple Health connector only works on claude.ai web, not Claude Code. Here's how to fix that.\n\nApple's privacy design is the core issue. HealthKit data never leaves your device through a server-side API. There's no endpoint you can call from a script, a cloud function, or an AI agent. All HealthKit access goes through an on-device iOS app that the user has explicitly granted permission.\n\nThat's actually good for privacy. But it creates a real problem if you want to query your health data from Claude Code, Cursor, or any MCP client running outside the claude.ai web interface.\n\nThe existing workarounds have limits. Health Auto Export is a solid app, but its MCP server works over local TCP. Your Claude Code session on a Mac Studio can't reach it if your phone is on a different network, or if you're on a VPN. The built-in Apple Health connector in claude.ai is great for the web UI but doesn't expose anything to Claude Code or any other MCP client.\n\nThe only real solution is to build your own sync layer: an iOS app that reads HealthKit and pushes to a database you control, plus an MCP server that Claude can talk to.\n\nThat's what health4.ai is.\n\nThe architecture is straightforward:\n\n```\niPhone (HKObserverQuery) → Your Postgres database → FastMCP server → Any AI\n```\n\nThe iOS app registers `HKObserverQuery`\n\nobservers for every HealthKit metric type. When Apple Health receives new data (a completed workout, a new HRV reading, a sleep session), the observer fires and queues a sync. `BGTaskScheduler`\n\nhandles periodic background delivery. On first launch, a bulk backfill exports your entire HealthKit history — mine was around 5.6 million rows.\n\nData lands in a simple EAV schema: one row per `HKSample`\n\n, with `metric_type`\n\n, `value`\n\n, `unit`\n\n, `started_at`\n\n, `ended_at`\n\n, `source_device`\n\n, and a `metadata`\n\nJSONB column. New metric types never require a schema migration.\n\nThe MCP server is a Python FastMCP process running locally. It reads directly from Postgres (your credentials, your database) and exposes 11 tools that any MCP client can call.\n\n**You own the data.** health4.ai never receives or stores your health data. It flows from your iPhone to your Postgres database — you choose the provider.\n\n```\ngit clone https://github.com/jefflitt1/health4ai.git\ncd health4ai\n```\n\nPick the backend that fits you and run the schema:\n\n**Supabase (free tier works fine):**\n\n```\npsql \"$DATABASE_URL\" < web/public/schema.sql\n```\n\n**Neon (serverless Postgres):**\n\n```\npsql \"$DATABASE_URL\" < web/public/schema.sql\n```\n\n**Local Docker:**\n\n```\ndocker run -d --name health4ai-postgres \\\n  -e POSTGRES_PASSWORD=yourpassword -p 5432:5432 postgres:16\npsql \"postgresql://postgres:yourpassword@localhost:5432/postgres\" \\\n  < web/public/schema.sql\n```\n\nTestFlight link: **coming soon** — the app is in review. Sign in with your Postgres connection details and tap **Start Sync**.\n\n```\ncp mcp-server/.env.example mcp-server/.env\n```\n\nEdit `mcp-server/.env`\n\n:\n\n```\nDATABASE_URL=postgresql://...    # your Postgres connection string\nHEALTHKIT_USER_ID=your_user_id   # any string to identify your data\n```\n\nInstall dependencies:\n\n```\ncd mcp-server && pip install -r requirements.txt\n{\n  \"mcpServers\": {\n    \"health4ai\": {\n      \"command\": \"python\",\n      \"args\": [\"/path/to/health4ai/mcp-server/main.py\"],\n      \"env\": {\n        \"DATABASE_URL\": \"postgresql://...\",\n        \"HEALTHKIT_USER_ID\": \"your_user_id\"\n      }\n    }\n  }\n}\n```\n\nRestart Claude Code. Run `/mcp`\n\nto confirm. You should see `health4ai`\n\nwith 11 tools listed.\n\n**Works with Cursor too** — same config block in `~/.cursor/mcp.json`\n\n.\n\n**Fully local with Ollama:**\n\n```\nmcphost --model ollama/llama3.2 \\\n  --mcp-server \"health4ai:python /path/to/health4ai/mcp-server/main.py\"\n```\n\nYour data and the model both stay on-device. Nothing leaves your machine.\n\nHere are prompts that work well, along with which tool they trigger:\n\n**\"How did I sleep this week?\"** → `get_sleep`\n\n— per-night breakdown with Core, Deep, and REM stage durations.\n\n**\"Is my HRV trending up or down this month?\"** → `get_hrv_trend`\n\n— daily SDNN averages, 7-day rolling comparison, trend direction.\n\n**\"Give me a full health summary for the last 14 days.\"** → `get_health_summary`\n\n— steps, HRV, resting HR, sleep, workouts.\n\n**\"What does yesterday look like?\"** → `get_daily_snapshot`\n\n— everything recorded that day.\n\n**\"Is 42ms HRV good or bad for me?\"** → `get_metric_stats`\n\n— your personal baseline: min/max/mean, percentiles, good/poor-day thresholds.\n\n**\"Did my sleep improve after I started lifting?\"** → `compare_periods`\n\n— compare any metric between two date ranges with delta, % change, and a plain-English verdict.\n\n**\"Show me my resting heart rate trend over the past 2 years.\"** → `get_long_term_trend`\n\n— transparently switches to pre-aggregated monthly buckets beyond 180 days, so it's fast and complete regardless of data volume.\n\n[https://github.com/jefflitt1/health4ai](https://github.com/jefflitt1/health4ai) — MIT licensed. PRs welcome.\n\nIf you set it up and run into anything, open an issue. The main thing still pending is the public TestFlight link. Everything else is working.", "url": "https://wpnews.pro/news/how-to-give-claude-code-access-to-your-apple-health-data", "canonical_source": "https://dev.to/jglitt/how-to-give-claude-code-access-to-your-apple-health-data-3p76", "published_at": "2026-06-19 02:01:09+00:00", "updated_at": "2026-06-19 02:30:06.638628+00:00", "lang": "en", "topics": ["developer-tools", "ai-agents", "artificial-intelligence"], "entities": ["Apple", "HealthKit", "Claude Code", "health4.ai", "Postgres", "FastMCP", "Supabase", "Neon"], "alternates": {"html": "https://wpnews.pro/news/how-to-give-claude-code-access-to-your-apple-health-data", "markdown": "https://wpnews.pro/news/how-to-give-claude-code-access-to-your-apple-health-data.md", "text": "https://wpnews.pro/news/how-to-give-claude-code-access-to-your-apple-health-data.txt", "jsonld": "https://wpnews.pro/news/how-to-give-claude-code-access-to-your-apple-health-data.jsonld"}}