Skip to main content
Glama
bank3005-jpg

Garmin Nutrition Coach

by bank3005-jpg
README.md
<p align="center">
  <img src="assets/leanloop-cover.jpg" alt="LeanLoop for Garmin โ€” private AI nutrition & fitness coach (Garmin + Claude + Notion + Google Cloud)" width="100%">
</p>

**Turn Claude into your personal, data-driven health coach โ€” self-hosted, private, ~$0/month.**

[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![MCP](https://img.shields.io/badge/Protocol-MCP-blue)](https://modelcontextprotocol.io)
[![Cloud Run](https://img.shields.io/badge/Runs%20on-Google%20Cloud%20Run-4285F4?logo=googlecloud&logoColor=white)](https://cloud.google.com/run)
[![Python](https://img.shields.io/badge/Python-3.12-3776AB?logo=python&logoColor=white)](requirements.txt)

### Why LeanLoop?

Losing weight is a calorie deficit โ€” but a deficit run **blind** burns muscle, not just fat. Lose muscle and your daily burn (TDEE) drops, so you have to eat *even less* to keep losing. That's the slow-starvation spiral that makes most diets miserable and short-lived.

LeanLoop keeps you on the healthy side of that line by giving Claude three things at once:

- ๐Ÿฝ๏ธ **What you eat** โ€” snap a photo or just type it; calories **and macros** land in Notion, and every meal is kept with its time so you can see your real eating habits, not just a daily number.
- ๐Ÿ”ฅ **What you *actually* burn** โ€” your Garmin measures it live, every day (workouts, steps, all-day movement), so your deficit is based on your real body โ€” not a one-size-fits-all formula that's wrong for you.
- ๐ŸŒ™ **How you're recovering** โ€” sleep, HRV, stress and body battery feed the coaching, so "train hard or rest today?" fits the day you're actually having.

Because all of it already flows to Claude, there's **no more screenshotting dashboards into chat**. Just ask.

> *"Coach me today" ยท "How did I sleep?" ยท "Why did my run feel bad?" ยท "What are my eating patterns this week?" ยท* ๐Ÿ“ธ *[photo of lunch]*

## โœจ Features

| | Feature | What it does |
|---|---|---|
| ๐Ÿ“ธ | **Photo (or text) food logging** | Snap a meal or type it โ†’ calories & macros estimated and auto-saved to Notion, with the full per-meal history (time + item) kept on the day's page for habit analysis |
| ๐ŸŒ™ | **Automatic day close** | Every night your server pulls the finished day's true TDEE from Garmin and writes TDEE + workouts into your log (your deficit column recalculates itself instantly โ€” it's a Notion formula) โ€” self-heals 3 days back, colored sync tags show status at a glance |
| ๐Ÿ”ฅ | **Progress you can see** | Cumulative deficit (โ‰ˆ kg of fat) updated nightly right on your Notion food log |
| ๐Ÿƒ | **Coaching on real data** | One-call readiness verdicts, post-workout analysis (splits, HR zones, sleep context), weekly reviews, injury pattern tracking |
| ๐Ÿ‹๏ธ | **Strength tracking + progression** | Log lifts in plain speech (with optional **RIR**/effort) โ†’ a clean per-exercise table with volume + estimated 1RM; the coach reads your last session, sees the trend, and prescribes the next load like a trainer |
| ๐Ÿ“ˆ | **Second-by-second analysis** | FIT-file parsing: HR/pace/cadence streams + **aerobic decoupling** โ€” the endurance metric real coaches use |
| โš–๏ธ | **Calibration loop** | Every 2 weeks: logged deficit vs. actual weight change reveals your personal estimation bias, which corrects all future estimates |
| ๐Ÿ”„ | **Live-updating brain** | Coaching rules live in [`playbook.md`](playbook.md), fetched by your server at runtime โ€” improvements reach every user instantly, no reinstall |

## ๐Ÿš€ Install (no coding needed)

1. In Claude, create a **Project** and name it **LeanLoop** (this is where your coach will live).
2. In that Project, enable the **Notion** connector (Claude needs it to build your databases).
3. Open a chat inside the Project โ€” set the model to **Sonnet at Medium** effort for setup (lots of IDs to track; switch to Low for everyday use afterward) โ€” and paste:

```
Read https://github.com/bank3005-jpg/LeanLoop-for-Garmin/blob/stable/SETUP.md and set this up for me
```

Claude interviews you (goals, body stats), creates your Notion databases, walks you through the cloud steps, then adds your server as a second connector and loads the coaching rules into the Project. **45โ€“60 minutes, one time.** After setup, everyday food logging runs fine on **Sonnet Low**.

> โš ๏ธ **Requires Claude Pro (or Max/Team/Enterprise).** LeanLoop runs on **two custom connectors at once** โ€” Notion (your food/training/body logs) and your Garmin server (live wearable data). The **Free plan allows only one** custom connector, which isn't enough for the full loop. Pro also gives the usage headroom for daily photo food-logging. You do *not* need any paid Notion or Garmin plan โ€” their free tiers are fine.

**Prerequisites:** a Garmin watch ยท Notion account (free) ยท Google account with billing enabled (stays within free tier) ยท **Claude Pro** (or Max/Team โ€” needs two custom connectors at once; Free allows only one) ยท Windows or macOS computer for one step.

> ๐Ÿ“š **Docs:** [USAGE.md](USAGE.md) โ€” how to use it (what to say to your coach) ยท [SETUP.md](SETUP.md) โ€” install ยท [CONFIG-REFERENCE.md](CONFIG-REFERENCE.md) โ€” the Config "brain" ยท [SECURITY.md](SECURITY.md) โ€” keep your data safe ยท [CONTRIBUTING.md](CONTRIBUTING.md) โ€” fork / maintainer notes

## ๐Ÿ—๏ธ Architecture

```
Claude (any device, incl. phone)
   โ””โ”€โ”€ your Cloud Run server  โ† this repo, deployed to YOUR Google account
         โ”œโ”€โ”€ Garmin Connect   โ† your token, created on your own computer
         โ”œโ”€โ”€ your Notion      โ† food / training / body logs
         โ””โ”€โ”€ playbook.md      โ† coaching rules, served live from GitHub
   Cloud Scheduler โ†’ nightly close-day job + keep-warm pings
```

**Privacy by design:** everything runs in *your* accounts. No third party โ€” including this repo's author โ€” ever sees your data. The server is protected by a long random secret; Garmin credentials never pass through chat.

## ๐Ÿงฐ What's inside (21 lean MCP tools)

**Health** `get_wellness(metric)` โ€” sleep, HRV, stress, body battery, heart rate, SpO2, respiration, intensity minutes, hydration, blood pressure, body composition, training readiness/status ยท `get_daily_summary`
**Training** `get_activities` (recent or date range) ยท `get_activity(id, view)` โ€” summary, splits, HR zones, FIT streams, aerobic decoupling ยท `get_fitness(metric)` โ€” VO2max, race predictions, endurance/hill scores, lactate threshold, PRs, fitness age ยท `get_coach_snapshot` (one-call verdict data) ยท `analyze_activity` (one-call post-workout bundle) ยท `weekly_report` / `calibrate_report` (pre-computed reviews) ยท `traininglog_read` (Notion actuals: runs + weight lift tables)
**Body** `get_weight_history` ยท `add_body_composition` (**write** InBody/DEXA scans into Garmin)
**System** `foodlog_read` / `foodlog_upsert` (direct Notion food log, meal-by-meal history) ยท `get_config` / `foodlib_find` / `foodlib_upsert` / `exercise_find` (fast server-side Notion reads, dedup foods into your library) ยท `weightlog_upsert` (log a lift session) ยท `get_today` (server date/time โ€” anchor dated actions) ยท `get_playbook` (live coaching rules)

Few tools by design: a lean tool list keeps every chat's context small โ€” grouped tools with a `metric`/`view` parameter carry the same 35 capabilities at ~half the token overhead.

## ๐Ÿ”„ Updating

- **Coaching rules** โ€” update automatically (served live from this repo)
- **Server code** โ€” `git pull` + one deploy command, or enable a Cloud Build trigger on `stable` for fully automatic deploys
- Want to customize the code? **Fork** the repo and point your deployment at your fork

## ๐Ÿค– Using it with ChatGPT or OpenAI Codex (instead of Claude)

LeanLoop's brain is a **standard remote MCP server** โ€” it is *not* tied to Claude. Any MCP-capable client can connect to the exact same Cloud Run server and get the same 23 tools. Two confirmed paths (verified Aug 2026):

**ChatGPT โ€” Developer Mode** (Plus / Pro / Business / Enterprise / Edu, web app):
`Settings โ†’ Apps โ†’ Advanced โ†’ Developer Mode` โ†’ **add a remote MCP server** โ†’ paste your server URL (`https://<your-cloud-run-url>/<MCP_SECRET>/mcp`). ChatGPT supports Streamable HTTP + SSE with *OAuth-or-none*, so the secret-in-URL that LeanLoop already uses works as-is. Put the bootstrap (below) into a **Custom GPT**'s instructions.

**OpenAI Codex** (CLI or desktop):
`codex mcp add leanloop -- <streamable-http url>`, or add it to `~/.codex/config.toml` (a project-scoped `.codex/config.toml` also works). Codex supports remote **Streamable HTTP** MCP with bearer/none auth. Put the bootstrap into `AGENTS.md` / project config.

**Bootstrap** (the equivalent of the Claude-Project setup โ€” paste into the Custom GPT instructions / AGENTS.md):
> *At the start of any food / training / coaching conversation, call `get_playbook` (no args) and follow every rule it returns, and read `get_config` for the user's current targets. All coaching logic lives in those two tools โ€” never guess.*

**What ports 1:1 (zero changes):** the whole server, all 23 tools, your Garmin token, your Notion databases, the Cloud Run deployment, and the nightly cron. These are **model-agnostic** โ€” build them once, any AI uses them.

**What's different / to watch:**
- **You likely need only the ONE LeanLoop connector**, not a separate Notion one โ€” the server reads *and writes* your food / config / training logs in Notion **itself** (server-side, via its own token). A separate Notion MCP is only needed for occasional hand-editing of page structure.
- **The playbook is tuned to Claude's behaviour.** GPT models follow instructions a little differently โ€” expect to tweak some wording (e.g. the "always render the full food table" rules) until it behaves.
- **Photo food-logging** needs a client with vision โ€” ChatGPT has it.
- **Codex-only shortcut that skips Google Cloud:** because Codex runs code locally, you *can* run `main.py` as a **local stdio MCP server** (no Cloud Run at all) โ€” this removes the single hardest setup step. Trade-offs: no nightly auto-close cron (that needs an always-on host) and no phone access โ€” it only works while your computer + Codex are running. Great for trying it; Cloud Run is still better for daily hands-off use.

**Bottom line โ€” fully feasible.** The three genuinely fiddly one-time steps people worry about โ€” **Notion setup, Garmin token, cloud deploy** โ€” are *identical* on any platform, because they connect **your data**, not Claude specifically. Once they're done, pointing ChatGPT or Codex at the server is a ~2-minute config. The one-time steps are in [`SETUP.md`](SETUP.md). *(Community/experimental โ€” the maintainer builds on Claude; GPT/Codex paths may need small prompt tweaks.)*

## โ“ FAQ

**Is it really free?** Yes โ€” Cloud Run free tier covers personal use many times over. The setup guide includes guardrails so you stay in it.
**Does my data go anywhere?** No. Your server, your Garmin token, your Notion. Self-hosted means self-owned.
**What if Garmin changes their API?** The community library this builds on ([python-garminconnect](https://github.com/cyberjunky/python-garminconnect)) gets patched quickly; update with one `git pull` + deploy.
**Garmin China accounts?** Not supported (separate system).
**No watch some days?** The nightly job falls back to your formula baseline and tags the day `estimated`.

## ๐Ÿ’ฌ Why this exists

I'm not a programmer. I built LeanLoop together with Claude because I wanted to lose weight, get my confidence back, and just *feel better* โ€” and I couldn't find a tracker that coached me on my **real** data instead of generic formulas. It worked for me, so I'm sharing it.

I use LeanLoop every single day and keep refining it as I go. If you hit a problem or want a feature, **[open a thread in Discussions](https://github.com/bank3005-jpg/LeanLoop-for-Garmin/discussions)** โ€” I read everything.

## ๐Ÿ™ Credits

Built on [python-garminconnect](https://github.com/cyberjunky/python-garminconnect) by cyberjunky ยท [fitdecode](https://github.com/polyvertex/fitdecode) ยท [MCP](https://modelcontextprotocol.io) by Anthropic.

## โš ๏ธ Disclaimer

This is a personal tracking and coaching tool, **not medical advice or a medical device**. Calorie and macro estimates are approximations. Consult a healthcare professional for medical decisions, and stop training and seek care for any concerning symptoms.

## ๐Ÿ“„ License

[MIT](LICENSE) โ€” use it, fork it, share it.