How do I let an AI agent read my sleep and HRV data?

Updated

Give the agent HealthSQL: it keeps your Apple Health record in a local SQLite database where the nights view has one row per night (minutes asleep, deep, REM, core and awake, when you fell asleep and woke) and the daily view has each day's heart rate variability and resting heart rate. The agent reads them with SQL, from a shell or over MCP.

HealthSQL is an iPhone app and a command-line tool that copy your whole Apple Health record into a local SQLite database on your computer, so AI agents can query it with SQL or MCP. Setup takes one command on your Mac: setup.

What the agent gets

Night N is the night that ends on the morning of day N; a stage that starts at 18:00 or later belongs to the next day's night. Every view and column: schema reference.

Queries the agent can run

The last two weeks of sleep:

SELECT night, asleep_min, deep_min, rem_min, awake_min, fell_asleep, woke FROM nights ORDER BY night DESC LIMIT 14

HRV and resting heart rate, this week against the four weeks before:

SELECT CASE WHEN day >= date('now', '-7 day') THEN 'last 7 days' ELSE 'the 4 weeks before' END AS period,
       round(avg(hrv_ms), 1) AS hrv_ms, round(avg(resting_hr), 1) AS resting_hr
FROM daily WHERE day >= date('now', '-35 day') GROUP BY period

Sleep against the next morning's HRV:

SELECT day, asleep_min, deep_min, hrv_ms, resting_hr FROM daily
WHERE day >= date('now', '-60 day') AND asleep_min IS NOT NULL ORDER BY day

Nights after a late workout:

SELECT w.day, w.activity, time(w.start_local) AS started, n.asleep_min, n.deep_min
FROM workouts w JOIN nights n ON n.night = date(w.day, '+1 day')
WHERE time(w.start_local) >= '19:00' ORDER BY w.day DESC LIMIT 20

Questions to ask

Where the numbers come from

HealthSQL is not a medical device. An agent can describe what your data shows; questions about your health belong with a clinician.

Questions

Which agents can do this?

Any agent with a shell or MCP: Claude Code, Codex, Cursor, Claude Desktop, local models, or an always-on agent that sends you a morning summary.

My HRV column is empty. Why?

hrv_ms holds Apple Health's own HRV. If no device writes HRV to Health, the column stays empty, because unknown is not zero.

Can I see one device's sleep?

Yes: nights_by_source has a row for each source, and WHERE source_name LIKE '%Oura%' (or your device's name) picks one.