Health data hub workflow

Pulls iPhone health data over a cable into local storage and makes it queryable by AI without any cloud service.

#health data#iOS on-device#TDD#dual review#MCP#local-only
Health Data Hub

WorkflowHealth Data Hub

Everyday automation iPhone and a local MacBook, linked by cable

A home-made app reads the iPhone's Health data into a single SQLite file on the Mac. The receiver normally stays off: only when data is needed does the Mac start it, have the app sync over the cable, and shut it down again. Claude Code queries the data through MCP. No account, no cloud.

Challenge

  • Health data lives on the phone, so an AI cannot answer "how did my sleep relate to my weight last week?"
  • iOS rarely wakes apps in the background: measured on a real phone, twice in 33 hours
  • Signing, installing on the device and granting permissions make the road from code to daily use long and easy to stall

Approach

  • Rewrite the plan until a second model (Codex) rates it READY, then build test-first
  • Record every on-device check, and feed what it reveals back into the plan and the definition of done
  • Drop background push and switch to on-demand pulls: the Mac launches the app over the cable and collects the data

Outcome

  • Say "sync" when you need it and fresh data lands on the Mac in 2–3 seconds, ready to ask Claude about
  • Failed batches are resent; on the real phone we confirmed nothing was lost or duplicated
  • Started 2026-10-01, first public release on day 6; 77 commits and 773 Python tests

It covers 11 kinds of data, including weight, steps, heart rate, sleep and workouts. Whatever device wrote the data into Health (a scale, a watch), it is collected. Nothing is written back to Health.

Using it takes three steps, but getting there was a long road. "The full workflow" below draws all nine steps, from writing the plan to daily use, one diagram per step.

The full workflow

TaskWhoInputsOutputs
1. PlanMain sessionRefers to HealthKit docsPlan
2. Review planReviewerCodexPlanReview
3. Test-firstTDD agent teamTDD subagentsReview, Refers to HealthKit docsApp code
4. Sign & installBuild toolsxcodebuildApp codeSigned app
5. Test on deviceAuthorauthorSigned appOn-device log
6. PublishPublish scriptpublish.pyApp codePublic release
7. Pull on demandHealth MCP + iPhone apphealth-hub MCP + HealthKit appSigned appData batch
8. ReceiveMac receiverserver/run.shData batchSQLite
9. Query & answerHealth MCPhealth-hub MCPSQLiteAnswer
Health Data Hub

9 steps · 3 roles · 5 tools · 3 loops · 2026-10-01 – 11-13 · 77 commits

Get the plan reviewed, build test-first, prove it on the device, publish it, and let the Mac pull data from the phone only when needed.

  • Steps 1–6 build it; steps 7–9 use it. Daily use is just three steps
  • Three loops: plan review, bugs found on the device, failed syncs
  • Division of labour: the main session (Opus 5.5) plans and publishes, Codex reviews plans, a TDD agent team builds test-first, the author checks on the device
  • Data flows only between the iPhone and the Mac; nothing goes to a cloud

Project folders involved (4)

This workflow does not live in one folder: it runs across projects.

health-data-hub
The core: iPhone collector app, Mac receiver, MCP, plans and on-device logs
health-hub (public repo)
Public release: the repository cut by the publishing script with personal data stripped
family-health plugin
The author's family-health plugin bundles the health-hub MCP, so any project folder can call it
(private) medical records
A private records folder pulls data through the MCP and cross-checks it against the records
Plan

Step 1 · Main session

Planplan

Gather the plan and the reference docs first.

  • 31 official HealthKit documents go into a local library, so no API is written from guesswork
  • The plan lists the phases (receiver → iPhone app → background sync → release) and their definition of done
  • The iOS dev-environment steps became a Skill, so next time they are simply loaded

Claude CodeReference docs are handed over as a library and cited by the plan

OutputsPlan
Refers toHealthKit docs
Review plan

Step 2 · Reviewer

Review planplan review

Rewrite the plan until another model says READY.

  • Codex at its highest reasoning setting reviews for consistency, gaps, feasibility, ambiguity and ordering
  • The iPhone-app plan reached READY on round 7, background sync on round 9, on-demand sync on version 4
  • The rule came from the first phase, where tests turned out to pass the moment they were written

Common misconceptionOne pass is never enough: every rewrite exposes new holes

InputsPlan
OutputsReview
Test-first

Step 3 · TDD agent team

Test-firstTDD

Write the test first, see it fail, then make it pass.

  • The iPhone logic lives in a Swift package and the app is a thin shell, which keeps it testable
  • Cross-language contract tests: JSON produced by Swift is validated by Python, so the two ends cannot drift apart
  • Flaky race conditions and an off-by-one-ulp decimal were caught by tests and fixed
InputsReview
OutputsApp code
Refers toHealthKit docs
Sign & install

Step 4 · Build tools

Sign & installxcodebuild

Sign the app and install it on the iPhone.

  • The Xcode project is generated from a config file and never edited by hand
  • On the phone, Developer Mode must be on and the developer must be trusted
  • HealthKit has to be enabled for the app on the developer site, or the build fails

Common misconceptionAn app signed with a free developer account stops working after 7 days

InputsApp code
OutputsSigned app
Test on device

Step 5 · Author

Test on deviceprobe

Check what only a real device can tell, and write it down.

  • On first run a person grants Health access on the phone, then checks the connection and the full-history upload
  • Measured background wake-ups: 2 in 33 hours, 0 in 3.5 hours of charging
  • That rewrote the definition of done to "at least once a day, nothing lost or duplicated", signed off by the author
InputsSigned app
OutputsOn-device log
Publish

Step 6 · Publish script

Publishpublish.py

Cut the public release from the private tree, stripping personal data.

  • Public docs come in English, Traditional Chinese and Japanese
  • Every cut passes a privacy scan for device names, addresses and keys
  • The public tree must pass all tests on its own (it once failed on a test that read an unpublished doc)
InputsApp code
OutputsPublic release
Pull on demand

Step 7 · Health MCP + iPhone app

Pull on demandsync_now

Only when data is needed does the Mac wake the app over the cable.

  • It runs when you say "sync", or when a query finds the data more than 24 hours old (at most once per 12 hours)
  • Whether the cable is really connected is checked separately against the USB device list
  • An app cannot be launched while the phone is locked, so it stops and reports why

Common misconceptionIt used to open the app daily via a Shortcuts automation; this replaced it

InputsSigned app
OutputsData batch
Receive

Step 8 · Mac receiver

ReceivePOST /ingest

The receiver runs only when started, and closes once data is saved.

  • A batch counts as sent only after the Mac acknowledges it
  • Batches that fail stay in the app's queue and are resent as-is next time
  • One pull finishes in 2–3 seconds
InputsData batch
OutputsSQLite
Query & answer

Step 9 · Health MCP

Query & answerquery_samples

Claude answers by querying SQLite through MCP.

  • Questions like "how did I sleep last week?" are answered from local data
  • Weekly summaries come from the same tools
  • The data never leaves this Mac

Claude CodeRegistered as an MCP server, the same tools work from any project folder

InputsSQLite
OutputsAnswer

Loops and rework

  • NEEDS REVISION in plan review → step 1: Rewrite and resubmit; the background-sync plan reached READY on round 9
  • Bug on the device → step 3: What the device reveals (e.g. answering immediately when leaving the foreground) goes back into tests and is fixed
  • Send failure → step 7: It really happened once on the phone: the queued batch was resent on the next launch with no duplicates

Key points

Get the plan reviewed first. In the first build phase we found tests that went green the moment they were written, so from then on nothing was coded until Codex rated the plan READY. The background-sync plan was rewritten nine times.

Rewrite the definition of done to match the real device. Measured on a phone, iOS woke the app far too rarely, so "real time" gave way to "at least once a day, nothing lost, nothing duplicated", and finally to pulling data on demand.

Do not keep the receiver running. The Mac's receiving server starts only when data is needed and shuts down right after; the longer no port is open, the smaller the attack surface.