Purpose
The
health-data skill provides deterministic helpers to read and summarize Apple Health backup exports. The bundled
health-data.sh script understands the zipped export Apple Health lets you download and can also work against the unzipped folder with
export.xml. Use this skill when you need to inspect record types, compute totals (steps, distance, sleep), or extract JSON for further analysis without sending the sensitive XML off-box.
Safety
- - Apple Health exports contain PII/PHI (biometric, sleep, location, heart-rate, etc.). Never publish the raw XML, upload the zip, or paste any values into third-party services without explicit consent and legal review.
- The script only reads data locally and cleans up its temporary extraction. Keep the exported zip/folder on disk-free space you control and delete it when the analysis is done.
- Running
summary or export-json now emits a runtime PHI warning banner to stderr; treat every derived artifact as PHI/PII unless you have an explicit legal/research justification. - The
export-json command streams records instead of slurping them, warns on stderr after emitting 100,000 records without --limit, and supports --out <file> so you can save the JSON to a file created with 600 permissions instead of dumping to stdout. - Request explicit confirmation before writing any derived health reports if the values are later shared with others (medical, legal, or employment contexts).
Quick start
CODEBLOCK0
Commands
list-types
Prints every
<Record type="..."> identifier in the export, sorted by frequency. Use this to understand which categories (steps, workouts, heart rate, etc.) are available before you dig into payloads.
summary
Reports:
- - total record count and date coverage
- step count and walking/running distance sums (meters by default)
- counts of sleep analysis categories (asleep/in-bed)
- top five data sources by record volume
This command relies on xmlstarlet to query the XML so it stays fast even on large exports.
export-json [--limit N] [--out ]
Pulls the requested record type into JSON so you can pipe it to
jq, Python, or other tools. The command emits a runtime PHI warning banner on stderr, streams records instead of slurping them, warns after 100,000 emitted records when
--limit is omitted, and supports
--out <file> to save the JSON to a file created with 600 permissions. Supply
--limit to avoid overwhelming the reader (default: unlimited). Examples:
CODEBLOCK1
CODEBLOCK2
Advanced filtering
Because the output from
export-json is valid JSON, use
jq for additional insights:
CODEBLOCK3
Combine jq selectors (like map(select(.unit == "count"))) to focus on specific fields without writing additional parsing logic.
Examples
- - "What record types did my Health export include?" → INLINECODE18
- "Show me step totals and sleep breakdown for my export" → INLINECODE19
- "I want the raw step records for the last week" →
health-data.sh export-json HKQuantityTypeIdentifierStepCount ~/path/to/export.zip --limit 100 and pipe through INLINECODE21 - "Save a slice of the export to a local file" → INLINECODE22
Troubleshooting
- -
no such file or directory: Ensure the export path points to either applehealthexport/export.xml or the zipped export produced by Apple Health. zip ... does not contain export.xml: Re-export from the Health app—sometimes partial exports omit the XML if interrupted.- Missing dependencies: Install
xmlstarlet, jq, and unzip via Homebrew (brew install xmlstarlet jq unzip).
目的
health-data技能提供确定性辅助工具,用于读取和汇总Apple Health备份导出数据。内置的health-data.sh脚本可解析Apple Health允许下载的压缩导出文件,也能处理包含export.xml的解压文件夹。当需要检查记录类型、计算总量(步数、距离、睡眠)或提取JSON进行进一步分析,且无需将敏感XML文件传出设备时,可使用此技能。
安全性
- - Apple Health导出数据包含PII/PHI(生物特征、睡眠、位置、心率等)。未经明确同意和法律审查,切勿发布原始XML、上传压缩包或将任何值粘贴至第三方服务。
- 脚本仅本地读取数据并清理临时提取文件。请将导出的压缩包/文件夹保存在您控制的可释放磁盘空间,分析完成后立即删除。
- 运行summary或export-json命令时,现会在stderr输出运行时PHI警告横幅;除非有明确的法律/研究依据,否则请将所有衍生产物视为PHI/PII。
- export-json命令采用流式处理而非一次性加载记录,在未使用--limit参数输出10万条记录后会在stderr发出警告,并支持--out 参数将JSON保存至权限为600的文件,而非直接输出到stdout。
- 若后续与他人(医疗、法律或就业场景)共享任何衍生健康报告,需先请求明确确认。
快速开始
bash
列出出现频率最高的HealthKit记录类型
health-data/health-data.sh list-types ~/Downloads/export.zip
汇总范围、总量和常见数据源
health-data/health-data.sh summary ~/Downloads/export.zip
获取步数的JSON记录(可使用jq进一步过滤)
health-data/health-data.sh export-json HKQuantityTypeIdentifierStepCount ~/Downloads/export.zip --limit 20
或保存至受限文件(600权限)而非输出到stdout
health-data/health-data.sh export-json HKQuantityTypeIdentifierStepCount ~/Downloads/export.zip --limit 20 --out ~/Documents/steps.json
命令
list-types <导出路径>
按频率排序输出导出文件中所有
标识符。用于在深入分析数据前了解可用的类别(步数、锻炼、心率等)。
summary <导出路径>
报告内容:
- - 总记录数和日期覆盖范围
- 步数计数和步行/跑步距离总和(默认单位为米)
- 睡眠分析类别计数(入睡/卧床)
- 按记录量排序的前五大数据源
此命令依赖xmlstarlet查询XML,即使处理大型导出文件也能保持快速。
export-json <记录类型> <导出路径> [--limit N] [--out <文件>]
将请求的记录类型提取为JSON,便于通过管道传递给jq、Python或其他工具。该命令在stderr输出运行时PHI警告横幅,采用流式处理而非一次性加载记录,未使用--limit参数时在输出10万条记录后发出警告,并支持--out 参数将JSON保存至权限为600的文件。使用--limit参数可避免输出过多(默认无限制)。示例:
bash
health-data/health-data.sh export-json HKCategoryTypeIdentifierSleepAnalysis ~/Downloads/export.zip --limit 5
bash
health-data/health-data.sh export-json HKQuantityTypeIdentifierStepCount ~/Downloads/export.zip --limit 20 --out ~/Documents/step-records.json
高级过滤
由于export-json的输出是有效的JSON,可使用jq进行进一步分析:
bash
health-data/health-data.sh export-json HKQuantityTypeIdentifierStepCount ~/Downloads/export.zip --limit 50 \
| jq [.[] | {value, startDate}]
结合jq选择器(如map(select(.unit == count)))可聚焦特定字段,无需编写额外解析逻辑。
示例
- - 我的健康导出包含哪些记录类型? → health-data.sh list-types ~/path/to/export.zip
- 显示我导出数据中的步数总量和睡眠分解 → health-data.sh summary ~/path/to/export.zip
- 我想要上周的原始步数记录 → health-data.sh export-json HKQuantityTypeIdentifierStepCount ~/path/to/export.zip --limit 100 并通过管道传递给 jq .[].startDate | select(startswith(2026-03))
- 将导出数据的一部分保存到本地文件 → health-data.sh export-json HKQuantityTypeIdentifierStepCount ~/path/to/export.zip --limit 50 --out ~/Documents/step-records.json
故障排除
- - no such file or directory:确保导出路径指向applehealthexport/export.xml或Apple Health生成的压缩导出文件。
- zip ... does not contain export.xml:从健康应用重新导出——有时中断的部分导出会遗漏XML文件。
- 缺少依赖:通过Homebrew安装xmlstarlet、jq和unzip(brew install xmlstarlet jq unzip)。