Get the FREE Ultimate OpenClaw Setup Guide →
m

HealthKit Sync

Verified

@mneves75

npx machina-cli add skill @mneves75/healthkit-sync --openclaw
Files (1)
SKILL.md
4.5 KB

HealthKit Sync CLI

Securely sync Apple HealthKit data from iPhone to Mac over local network using mTLS.

When to Use This Skill

  • User asks about syncing health data from iPhone
  • User mentions healthsync CLI commands
  • User wants to fetch steps, heart rate, sleep, or workout data
  • User needs to pair a Mac with an iOS device
  • User asks about the iOS Health Sync project architecture
  • User mentions certificate pinning or mTLS patterns

CLI Quick Reference

Pairing Flow (First Time)

# 1. Discover devices on local network
healthsync discover

# 2. On iOS app: tap "Share" to generate QR code, then "Copy"
# 3. Scan QR from clipboard (Universal Clipboard)
healthsync scan

# Alternative: scan from image file
healthsync scan --file ~/Desktop/qr.png

Fetching Health Data

# Check connection status
healthsync status

# List enabled data types
healthsync types

# Fetch data as CSV (default)
healthsync fetch --start 2026-01-01T00:00:00Z --end 2026-12-31T23:59:59Z --types steps

# Fetch multiple types as JSON
healthsync fetch --start 2026-01-01T00:00:00Z --end 2026-12-31T23:59:59Z \
  --types steps,heartRate,sleepAnalysis --format json | jq

# Pipe to file
healthsync fetch --start 2026-01-01T00:00:00Z --end 2026-12-31T23:59:59Z \
  --types steps > steps.csv

Available Health Data Types

Activity: steps, distanceWalkingRunning, distanceCycling, activeEnergyBurned, basalEnergyBurned, exerciseTime, standHours, flightsClimbed, workouts

Heart: heartRate, restingHeartRate, walkingHeartRateAverage, heartRateVariability

Vitals: bloodPressureSystolic, bloodPressureDiastolic, bloodOxygen, respiratoryRate, bodyTemperature, vo2Max

Sleep: sleepAnalysis, sleepInBed, sleepAsleep, sleepAwake, sleepREM, sleepCore, sleepDeep

Body: weight, height, bodyMassIndex, bodyFatPercentage, leanBodyMass

Configuration

Config stored at ~/.healthsync/config.json (permissions: 0600):

{
  "host": "192.168.1.x",
  "port": 8443,
  "fingerprint": "sha256-certificate-fingerprint"
}

Token stored in macOS Keychain under service org.mvneves.healthsync.cli.

Security Architecture

Certificate Pinning

The CLI validates server certificates by SHA256 fingerprint (TOFU model):

  1. First pairing stores fingerprint from QR code
  2. Subsequent connections verify fingerprint matches
  3. Mismatch = connection rejected (MITM protection)

Local Network Only

Host validation restricts connections to:

  • localhost, *.local domains
  • Private IPv4: 192.168.*, 10.*, 172.16-31.*
  • IPv6 loopback: ::1, link-local: fe80::

Keychain Storage

Tokens never stored in config file - always in Keychain with:

  • kSecAttrAccessibleWhenUnlocked protection class
  • Service: org.mvneves.healthsync.cli
  • Account: token-{host}

Project Structure

ai-health-sync-ios-clawdbot/
├── iOS Health Sync App/          # Swift 6 iOS app
│   ├── Services/Security/        # CertificateService, KeychainStore, PairingService
│   ├── Services/HealthKit/       # HealthKitService, HealthSampleMapper
│   ├── Services/Network/         # NetworkServer (TLS), HTTPTypes
│   └── Services/Audit/           # AuditService (SwiftData)
└── macOS/HealthSyncCLI/          # Swift Package CLI

Troubleshooting

"No devices found":

  • Ensure iOS app is running with sharing enabled
  • Both devices must be on same Wi-Fi network
  • Check firewall isn't blocking mDNS (port 5353)

"Pairing code expired":

  • Generate new QR code on iOS app (codes expire in 5 minutes)

"Certificate mismatch":

  • Delete ~/.healthsync/config.json and re-pair
  • Server certificate may have been regenerated

"Connection refused":

  • iOS app server may not be running
  • Run healthsync status --dry-run to test without connecting

See Also

Source

git clone https://clawhub.ai/mneves75/healthkit-syncView on GitHub

Overview

Securely sync Apple HealthKit data from iPhone to Mac over a local network using mTLS. The skill covers healthsync CLI usage to fetch steps, heart rate, sleep, and workouts, pairing devices via QR, and understanding the iOS Health Sync architecture including certificate pinning, Keychain storage, and audit logging.

How This Skill Works

The healthsync CLI discovers devices on the local network, then pairs by scanning a QR code or image to establish a TLS-secured channel with certificate pinning. It queries HealthKit data types, returning CSV by default or JSON when requested, while tokens are stored in macOS Keychain and connections are validated to prevent MITM attacks.

When to Use It

  • You need to sync Apple HealthKit data from iPhone to Mac.
  • You’re using the healthsync CLI to fetch steps, heart rate, sleep, or workouts.
  • You want to pair a Mac with an iOS device over the local network.
  • You’re exploring the iOS Health Sync project architecture (mTLS, certificate pinning, Keychain, audit logging).
  • You’re troubleshooting connectivity or security patterns in HealthKit syncing.

Quick Start

  1. Step 1: Discover devices on the local network: healthsync discover.
  2. Step 2: Pair by scanning the iOS app QR code (healthsync scan) or using --file for an image.
  3. Step 3: Fetch data, e.g., healthsync fetch --start 2026-01-01T00:00:00Z --end 2026-12-31T23:59:59Z --types steps,heartRate.

Best Practices

  • Ensure both devices are on the same Wi‑Fi network before pairing.
  • When pairing, verify the TLS fingerprint and save it as the trusted fingerprint.
  • Keep the config.json private (0600) and store tokens in macOS Keychain (org.mvneves.healthsync.cli).
  • Before fetching, run healthsync status and healthsync types to confirm connectivity and data availability.
  • Prefer CSV for simple pipelines; use JSON with jq for complex parsing and filtering.

Example Use Cases

  • Pairing flow: healthsync discover; healthsync scan to exchange pairing information.
  • Check connection status: healthsync status.
  • Fetch data as CSV: healthsync fetch --start 2026-01-01T00:00:00Z --end 2026-12-31T23:59:59Z --types steps.
  • Fetch multiple types as JSON and pipe to jq: healthsync fetch --start 2026-01-01T00:00:00Z --end 2026-12-31T23:59:59Z --types steps,heartRate,sleepAnalysis --format json | jq
  • Pipe output to a file: healthsync fetch --start 2026-01-01T00:00:00Z --end 2026-12-31T23:59:59Z --types steps > steps.csv

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers