Skip to content

Instantly share code, notes, and snippets.

@nickmerwin
Created February 28, 2026 18:05
Show Gist options
  • Select an option

  • Save nickmerwin/32703ab6bc4ca30f1fe776ae2ccdd1eb to your computer and use it in GitHub Desktop.

Select an option

Save nickmerwin/32703ab6bc4ca30f1fe776ae2ccdd1eb to your computer and use it in GitHub Desktop.
DataBody: Claude API payload & calorie discrepancy post-mortem (2026-02-27)

DataBody — Claude API Payload: Thread 877 (2026-02-27)

Last message sent at 2026-02-27 23:54 UTC (3:54 PM PST).
User: Apple private relay, timezone: America/Los_Angeles
This is the session showing the 1,357 (header) vs 1,170 (AI) calorie discrepancy.


Root Cause (discovered via post-mortem)

surplus_calories is time-dependent — it uses projected_total_burn = todays_actual_burn + projected_future_burn.
projected_future_burn shrinks as the day progresses (fewer hours remain).

At 22:50 UTC (first log): surplus ≈ +66 kcal → remaining = 1,412
At 23:54 UTC (second log): surplus = 0 kcal → remaining = 1,170
At dashboard reload (later): HealthKit synced more active calories → surplus = +121 → remaining = 1,357

The tool reported the correct value at the time of logging. The header showed the updated value after HealthKit sync.


User Context (at time of request)

Timezone:          America/Los_Angeles
Goal base:         2,022 kcal/day
Effective (Fri):   2,325 kcal  (base × 1.15, flexible weekends +15%)
Protein target:    185g
Carbs target:      172g
Fat target:        66g
TDEE (14-day avg): 2,442 kcal
Activity level:    light
Latest snapshot:   active_calories=48, basal_energy=709
Projected total burn at 23:54 UTC: ~1,416 kcal  (< TDEE 2,442 → surplus = 0)

System Prompt

The system prompt is split into two blocks (prompt caching):

Block 1 — Static instructions (cached)

============================================================
MANDATORY TOOL EXECUTION FOR FOOD LOGGING
============================================================

When the user asks you to log food, you MUST follow this exact sequence:
1. FIRST: Call the log_food tool with the food items
2. THEN: After receiving the tool result, summarize what was logged using the remaining_today values in the result

The log_food result includes updated remaining macros (remaining_today). Use those numbers directly.
The remaining_today object also includes calorie_target_today (flex-weekend-adjusted target),
burn_bonus_calories (extra calories earned from exercise above TDEE), and the formula is:
  remaining = calorie_target_today + burn_bonus_calories - total_consumed.
Do NOT call get_today_nutrition or get_health_summary after logging to verify —
those may reflect stale data and will cause you to report incorrect numbers.

... [full static instructions — tool descriptions, behavior rules, etc.]

Block 2 — Dynamic user context (not cached, computed fresh each request)

User context:
- Name: [user]
- Activity level: light
- Current date/time: Thursday, February 27, 2026 at 03:54 PM (America/Los_Angeles)
- Upcoming days:
    Thursday = February 27, 2026
    Friday = February 28, 2026
    ...

- Current Goal:
    Mode: CUT (fat loss)
    Daily targets: 2325 kcal, 185g protein, 172g carbs, 66g fat
    Flexible weekends: enabled (+15% on Fri/Sat/Sun, -11.2% on Mon-Thu).
      Today is a weekend (Fri/Sat/Sun), so the 2325 kcal target above is already
      adjusted from the base of 2022 kcal.
    ...

- Today's nutrition totals:
    Calories: 756 kcal
    Protein: ..., Carbs: ..., Fat: ...
    Remaining: 1,503 kcal, ...g protein, ...g carbs, ...g fat

- Energy balance:
    TDEE (14-day avg): 2442 kcal
    Today's basal (resting): 709 kcal
    Today's active energy: ~150 kcal  [value at 22:50 UTC]
    Today's actual burn: ~859 kcal
    Projected future burn: ~644 kcal
    Projected total burn: ~1503 kcal
    Calories to burn to earn bonus: 939 kcal  [no surplus yet at this time]

Messages Array Sent to API (for the last turn)

[
  {
    "role": "user",
    "content": "Log a string cheese and a small apple"
  },
  {
    "role": "assistant",
    "content": [
      {
        "type": "tool_use",
        "id": "toolu_hist_1_0",
        "name": "log_food",
        "input": {
          "items": [
            {
              "name": "String Cheese",
              "emoji": "🧀",
              "calories": 80,
              "fat_grams": 5,
              "carbs_grams": 1,
              "fiber_grams": 0,
              "serving_size": "28g",
              "protein_grams": 7,
              "serving_quantity": 1
            },
            {
              "name": "Apple, small",
              "emoji": "🍎",
              "calories": 77,
              "fat_grams": 0.2,
              "carbs_grams": 20,
              "fiber_grams": 3.6,
              "serving_size": "149g",
              "protein_grams": 0.4,
              "serving_quantity": 1
            }
          ],
          "meal_type": "snack"
        }
      }
    ]
  },
  {
    "role": "user",
    "content": [
      {
        "type": "tool_result",
        "tool_use_id": "toolu_hist_1_0",
        "content": "{\"tool\":\"log_food\",\"input\":{\"items\":[...],\"meal_type\":\"snack\"}}"
      }
    ]
  },
  {
    "role": "assistant",
    "content": "Logged! You have **1,412 kcal**, **99.5g protein**, **95.9g carbs**, and **32.3g fat** remaining today."
  },
  {
    "role": "user",
    "content": "Log 44 g of the same whey protein I had yesterday"
  }
]

Tool Results Returned to Claude

Tool 1: search_food_history result

{
  "results": [
    {
      "name": "Whey Protein Isolate Vanilla",
      "brand": "Whole Foods Market",
      "calories": 176,
      "protein_grams": 36.3,
      "carbs_grams": 4.4,
      "fat_grams": 0,
      "serving_size": "44g"
    },
    {
      "name": "Whey Protein",
      "brand": "Momentous",
      "...": "..."
    }
  ]
}

Tool 2: log_food result

{
  "action": "log_food",
  "success": true,
  "logged_items": [
    {
      "name": "Whey Protein Isolate Vanilla",
      "brand": "Whole Foods Market",
      "calories": 176,
      "protein_grams": 36.3,
      "carbs_grams": 4.4,
      "fat_grams": 0,
      "serving_size": "44g",
      "serving_quantity": 1
    }
  ],
  "total_calories": 176,
  "updated_daily_totals": {
    "calories": 1155,
    "protein_grams": 158.1,
    "carbs_grams": 100.9,
    "fat_grams": 33.7
  },
  "remaining_today": {
    "calories": 1170,
    "protein_grams": 26.9,
    "carbs_grams": 71.1,
    "fat_grams": 32.3,
    "calorie_target_base": 2022,
    "calorie_target_today": 2325,
    "burn_bonus_calories": 0
  }
}

Note: burn_bonus_calories: 0 here — surplus was 0 at 3:54 PM PST because projected_total_burn (~1,416 kcal) was well below TDEE (2,442 kcal). When the user later refreshed the dashboard, HealthKit had synced more active calories, pushing projected_total_burn above TDEE → surplus = +121 → remaining = 1,357.


Final Assistant Response (stored as message 2504)

I see two whey proteins from the past couple days — the Whole Foods Market Whey
Protein Isolate Vanilla (logged yesterday) and a Momentous one from the day before.
I'll go with yesterday's Whole Foods one — logging 44g now.

Logged 44g of Whole Foods Market Whey Protein Isolate Vanilla! You have 1,170 kcal,
26.9g protein, 71.1g carbs, and 32.3g fat remaining today.

This was correct at the time of logging. The 1,357 on the header was computed later with updated HealthKit data (more active calories synced = higher surplus).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment