<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gary Zhang</title>
    <description>The latest articles on DEV Community by Gary Zhang (@garyzhang).</description>
    <link>https://dev.to/garyzhang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4284421%2F6a93d1d2-6da3-456c-a5e9-fcc7ba2396df.png</url>
      <title>DEV Community: Gary Zhang</title>
      <link>https://dev.to/garyzhang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/garyzhang"/>
    <language>en</language>
    <item>
      <title>How I give Claude Code 12 years of my Apple Health data</title>
      <dc:creator>Gary Zhang</dc:creator>
      <pubDate>Sat, 05 Dec 2026 10:29:05 +0000</pubDate>
      <link>https://dev.to/garyzhang/how-i-give-claude-code-12-years-of-my-apple-health-data-16lb</link>
      <guid>https://dev.to/garyzhang/how-i-give-claude-code-12-years-of-my-apple-health-data-16lb</guid>
      <description>&lt;p&gt;I have 12 years of Apple Health history on my iPhone: about 4.96 million records across 4,466 days of heart rate, HRV, sleep, steps, ECGs, and Apple Watch workouts.&lt;/p&gt;

&lt;p&gt;Most of my daily work happens on my Mac inside Obsidian and Claude Code. Recently I wanted my local AI setup to read that history so I could ask grounded questions about training, sleep, and recovery.&lt;/p&gt;

&lt;p&gt;Two walls showed up right away. macOS still has no Apple Health app, and tapping "Export All Health Data" on iPhone spits out a zip with a single &lt;code&gt;export.xml&lt;/code&gt; file. With 12 years of data, mine is huge. Editors choke on it, raw XML tags burn through an LLM context window fast, and the dump goes stale the minute you export it. I wrote up the quirks I hit while &lt;a href="https://gethealthdock.com/en/tools/apple-health-export-xml-too-large/" rel="noopener noreferrer"&gt;handling oversized Apple Health export.xml files&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Free Route for a One-Off Export
&lt;/h2&gt;

&lt;p&gt;If you only want to inspect your history once or feed a slice into Python, you don't need to install or buy anything.&lt;/p&gt;

&lt;p&gt;I put up a free &lt;a href="https://gethealthdock.com/en/tools/xml-to-csv/" rel="noopener noreferrer"&gt;browser-based Apple Health XML-to-CSV converter&lt;/a&gt; that parses &lt;code&gt;export.xml&lt;/code&gt; locally inside your browser tab. Your file stays on your computer and never gets uploaded to a server. Drop in &lt;code&gt;export.xml&lt;/code&gt;, export clean CSV tables, and pass whichever columns you want to a script or AI chat.&lt;/p&gt;

&lt;p&gt;Where manual exports broke down for me was daily friction. Exporting on iPhone, waiting for compression, AirDropping hundreds of megabytes to Mac, unzipping, and re-running a converter meant my folder stayed weeks behind whenever I wanted to ask about last night's sleep.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Built a Companion Sync App
&lt;/h2&gt;

&lt;p&gt;Full disclosure upfront: I built HealthDock, my own iPhone and Mac app pair, to automate this (pricing and system requirements are at the end).&lt;/p&gt;

&lt;p&gt;Depending on your setup, good options already exist. Anthropic added an official Apple Health integration in the Claude iPhone app (currently beta, US-only, for Pro and Max plans, and mobile-only). For local file sync, Health.md also syncs Apple Health from iPhone to Mac files.&lt;/p&gt;

&lt;p&gt;Because I work in the terminal on macOS, I wanted three specific things together: fast initial import for nearly five million historical records, automatic daily sync to a plain folder of Markdown and data files on my Mac with no account or server, and an auto-generated &lt;code&gt;context.md&lt;/code&gt; comparing recent days against my personal baselines so Claude Code can read a compact summary first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three Real-Device Bugs From Syncing 12 Years of Data
&lt;/h2&gt;

&lt;p&gt;Getting a prototype running was quick. Making 12 years of real HealthKit history sync reliably—especially with the iPhone locked—took most of the debugging.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Bluetooth Topped Out at 17–28 KB/s on Bulk History
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; My first build sent everything over Bluetooth Low Energy to keep pairing simple. On a real iPhone unlocked in the foreground, transfer speed sat at 17–28 KB/s. Moving ~1.85 GB of raw data (~263 MB compressed) would have taken 2 to 3 hours.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it happened:&lt;/strong&gt; BLE handles small daily updates well, yet its narrow bandwidth struggles with hundreds of megabytes of historical samples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How I fixed it:&lt;/strong&gt; I split transport into two paths: direct local network (LAN / Wi-Fi) transfer for the initial full-history import, and Bluetooth solely for small daily incremental syncs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Export your real multi-year dataset and do the bandwidth math before picking a transport. Testing on 50 dummy rows hides bulk bottlenecks; separate initial backfill from daily incremental sync early.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Cutting LAN Sync From 23.3 Minutes to 7m 33s—After Fixing Duplicates
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; The first LAN version finished in 23.3 minutes with noticeable pauses, and reconciling total sample counts afterward showed extra rows on the Mac—silent duplicates had slipped in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it happened:&lt;/strong&gt; Device logs pointed to three issues: per-batch overhead scaled with the count of remaining files, the Mac paused 15 to 38 seconds exporting files mid-transfer, and retries generated random segment &lt;code&gt;uuid&lt;/code&gt;s so retransmitted chunks got inserted twice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How I fixed it:&lt;/strong&gt; I switched to deterministic segment IDs so retries became idempotent, removed the per-batch scan of remaining files, and deferred file export until the transfer finished. Full sync dropped to 7 minutes 33 seconds with zero duplicate ECGs or workout routes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Reconcile row counts before optimizing speed. Audit retry idempotency—especially random chunk IDs—until source and destination totals match to the record, then tune throughput.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Screen-Locked iOS Killed 100,000-Row Batches 36 Times Straight
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happened:&lt;/strong&gt; Daily sync needs to work with your phone in your pocket. With the screen locked and batch size set to 100,000 records, 36 background attempts over 15 minutes failed—every single one. Shrinking batches to 100 records worked while locked right away.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it happened:&lt;/strong&gt; When locked, iOS wakes the app briefly on Bluetooth events and suspends it again almost immediately. A 100-row payload fit into the send buffer right away; 100,000 rows got cut off mid-write every time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How I fixed it:&lt;/strong&gt; I packaged payloads on iPhone to roughly 120 KB per batch (splitting 100,000 records into 28 batches), requested background execution time during active sessions, and moved transfer I/O onto a dedicated thread. On the locked-screen retest, everything finished cleanly in 14.6 minutes with zero duplicates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaway:&lt;/strong&gt; Foreground runs prove very little for iOS background sync—always test on a physical phone with the screen locked. Keep chunks small enough that each brief wake window commits durable progress before adding retry logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  What &lt;code&gt;context.md&lt;/code&gt; Looks Like for Claude Code
&lt;/h2&gt;

&lt;p&gt;Feeding millions of CSV lines straight into an LLM wastes tokens. Alongside the raw data files, the Mac app writes a compact &lt;code&gt;context.md&lt;/code&gt; tailored for &lt;a href="https://gethealthdock.com/en/tools/apple-health-to-claude/" rel="noopener noreferrer"&gt;giving Claude structured Apple Health context&lt;/a&gt;. Here is the layout using placeholders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;# Health Context Summary
&lt;/span&gt;Updated: &amp;lt;YYYY-MM-DD&amp;gt; | Span: &amp;lt;start_year&amp;gt;–&amp;lt;end_year&amp;gt; (&amp;lt;total_days&amp;gt; days)

&lt;span class="gu"&gt;## Recent vs. Personal Baseline
&lt;/span&gt;&lt;span class="k"&gt;- &lt;/span&gt;Resting HR: &amp;lt;recent_avg&amp;gt; bpm (baseline: &amp;lt;baseline_avg&amp;gt; bpm)
&lt;span class="k"&gt;- &lt;/span&gt;HRV (SDNN): &amp;lt;recent_avg&amp;gt; ms (baseline: &amp;lt;baseline_avg&amp;gt; ms)
&lt;span class="k"&gt;- &lt;/span&gt;Sleep: &amp;lt;recent_avg&amp;gt; hr (baseline: &amp;lt;baseline_avg&amp;gt; hr)
&lt;span class="k"&gt;- &lt;/span&gt;Steps: &amp;lt;recent_avg&amp;gt; / day (baseline: &amp;lt;baseline_avg&amp;gt; / day)

&lt;span class="gu"&gt;## Unusual Days (Recent)
&lt;/span&gt;&lt;span class="k"&gt;- &lt;/span&gt;&amp;lt;YYYY-MM-DD&amp;gt;: HRV below personal baseline for consecutive days
&lt;span class="k"&gt;- &lt;/span&gt;&amp;lt;YYYY-MM-DD&amp;gt;: Outdoor Run logged (&amp;lt;duration_min&amp;gt; min, &amp;lt;distance_km&amp;gt; km)

&lt;span class="gu"&gt;## Long-Term Trends &amp;amp; Raw Files
&lt;/span&gt;&lt;span class="k"&gt;- &lt;/span&gt;Multi-year trend notes, with detailed data files alongside
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two real examples from my own logs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;One Sunday I went hiking and accidentally recorded an Outdoor Run on my Apple Watch: 153 minutes, 9.83 km. That evening Claude Code calculated my pace at 15.6 min/km and asked whether I had actually been hiking.&lt;/li&gt;
&lt;li&gt;During a weekly review, it noticed my HRV stayed below my personal baseline for three consecutive days and reminded me to prioritize recovery.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;HealthDock only organizes personal data so you can review patterns; it does not offer medical advice or diagnosis.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Privacy Boundary
&lt;/h2&gt;

&lt;p&gt;Syncing between iPhone and Mac runs directly over Bluetooth and local Wi-Fi with no server and no account. Your files stay on your Mac disk, where you can read them offline in Obsidian or scripts. Whether you paste &lt;code&gt;context.md&lt;/code&gt; or CSV slices into a cloud AI like Claude Code or ChatGPT is entirely your choice—at that step, whatever text you send goes to that AI provider.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclosure
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://gethealthdock.com" rel="noopener noreferrer"&gt;HealthDock&lt;/a&gt; is my own closed-source commercial app, on the App Store for iOS 17+ and macOS 14+. The Mac app is free; the iPhone app has a 7-day free trial, then $4.99/year or $14.99 once (US prices). Not available in the EU.&lt;/p&gt;

</description>
      <category>ios</category>
      <category>ai</category>
      <category>sideprojects</category>
      <category>healthkit</category>
    </item>
  </channel>
</rss>
