{
    "tailapp": 2,
    "manifest": {
        "format": 2,
        "app_id": "claude-usage",
        "name": "Claude usage",
        "version": 1,
        "schema": "tailapps/v0",
        "exported_at": 1795564582,
        "from": "gallery",
        "connections": [],
        "files": {
            "app.json": "af8fc03839a2d49246e782940a17d6d2d555e20b6d05f4184091f1f14eff2db1"
        },
        "signature": "kPsFN1xIcG/tzznLRlvn58GX5WsqRIQDxnzq5B79XC1ctMyVem6sYInIe+DDiDz8yBtUHyUEL83ptS54ZdsvBA==",
        "key_id": "gallery-1"
    },
    "app": {
        "schema": "tailapps/v0",
        "app": "claude-usage",
        "name": "Claude usage",
        "description": "Your Claude plan's 5-hour and weekly limits, plus tokens and an estimated API cost by day, project and model, from Claude Code on your Mac. Syncs only these numbers to your iPhone.",
        "icon": "chart.bar",
        "version": 2,
        "permissions": [
            "script:usage.sh",
            "inbox:limits"
        ],
        "state": {
            "report": {
                "type": "object",
                "default": [],
                "sync": true
            },
            "plan": {
                "type": "object",
                "default": [],
                "sync": true
            },
            "five": {
                "type": "any",
                "default": null
            },
            "week": {
                "type": "any",
                "default": null
            },
            "cost": {
                "type": "any",
                "default": null
            },
            "level": {
                "type": "text",
                "default": "none"
            }
        },
        "sources": {
            "usage": {
                "script": "usage.sh",
                "every": 300,
                "on": "open",
                "timeout": 240,
                "platforms": [
                    "macos"
                ],
                "on_change": "publish"
            },
            "limits": {
                "inbox": "limits",
                "on_receive": "got_limits",
                "platforms": [
                    "macos"
                ]
            }
        },
        "scripts": {
            "usage.sh": "#!/bin/sh\n# Claude Code's token use for the last 7 days, read from its own logs (~/.claude/projects/**/*.jsonl).\n# Reads only, sends nothing. Prints one JSON object: today, week, days (for a chart), top projects and models.\n# Cost is an estimate at Anthropic API list prices (input, output, cache write = 1.25 x input, cache read);\n# on a Pro or Max plan nobody pays it, but it shows how much work the sessions did.\ndir=\"$HOME/.claude/projects\"\nif [ ! -d \"$dir\" ]; then\n  echo \"{\\\"found\\\":false,\\\"day\\\":\\\"$(date +%Y-%m-%d)\\\",\\\"today\\\":{\\\"tokens\\\":0,\\\"cost\\\":0},\\\"week\\\":{\\\"tokens\\\":0,\\\"cost\\\":0},\\\"days\\\":[],\\\"projects\\\":[],\\\"models\\\":[]}\"\n  exit 0\nfi\n# Files touched in the last 8 days; only lines that carry token counts go on to jq.\nfind \"$dir\" -type f -name '*.jsonl' -mtime -8 2>/dev/null | while IFS= read -r file; do\n  grep -F -h '\"output_tokens\"' \"$file\" 2>/dev/null\ndone | jq -R -c '\n  fromjson? | select(type == \"object\" and .type == \"assistant\" and (.message.usage | type) == \"object\")\n  | select((.message.model // \"\") != \"<synthetic>\")\n  | .message.usage as $u\n  | {\n      k: (if .message.id and .requestId then .message.id + \":\" + .requestId else \"line\" + (input_line_number | tostring) end),\n      t: ((.timestamp // \"\") | sub(\"\\\\.[0-9]+\"; \"\") | try fromdateiso8601 catch 0),\n      m: ((.message.model // \"unknown\") | sub(\"^claude-\"; \"\")),\n      p: ((.cwd // \"\") | split(\"/\") | map(select(. != \"\")) | last // \"unknown\"),\n      i: ($u.input_tokens // 0), o: ($u.output_tokens // 0),\n      w: ($u.cache_creation_input_tokens // 0), r: ($u.cache_read_input_tokens // 0)\n    }\n' | jq -s -c '\n  # $ per million tokens: [input, output, cache read]. Cache writes are 1.25 x input.\n  def price:\n    if test(\"fable-5-2|mythos-5-2\") then [8, 40, 0.2]\n    elif test(\"fable|mythos\") then [10, 50, 1]\n    elif test(\"opus-5-5\") then [4, 20, 0.2]\n    elif test(\"opus-5|opus-4-[5-9]\") then [5, 25, 0.5]\n    elif test(\"opus\") then [15, 75, 1.5]\n    elif test(\"sonnet-5-5\") then [2, 10, 0.1]\n    elif test(\"sonnet-5\") then [2, 10, 0.2]\n    elif test(\"haiku-5\") then [0.1, 0.5, 0.01]\n    elif test(\"haiku-4\") then [1, 5, 0.1]\n    elif test(\"haiku\") then [0.8, 4, 0.08]\n    else [3, 15, 0.3] end;\n  def cost: (.m | price) as $p | (.i * $p[0] + .w * $p[0] * 1.25 + .o * $p[1] + .r * $p[2]) / 1000000;\n  def tokens: .i + .o + .w + .r;\n  def total: { tokens: (map(tokens) | add // 0), cost: ((map(cost) | add // 0) * 10000 | round / 10000),\n               input: (map(.i) | add // 0), output: (map(.o) | add // 0), cache: (map(.w + .r) | add // 0), messages: length };\n  # The last 7 calendar days, counted from noon UTC on the local date of today, so a 23- or 25-hour day skips none.\n  ((now | strflocaltime(\"%Y-%m-%d\") | strptime(\"%Y-%m-%d\") | mktime) + 43200) as $noon\n  | [range(6; -1; -1) | ($noon - . * 86400)] as $stamps\n  | ($stamps | map(strftime(\"%Y-%m-%d\"))) as $week\n  | map(select(.t > 0) | . + { d: (.t | strflocaltime(\"%Y-%m-%d\")) } | select(.d as $d | $week | index($d)))\n  # Claude Code writes a line per content block of a reply, each with the usage so far: keep the fullest one.\n  | group_by(.k) | map(max_by(.o))\n  | . as $all\n  | ($week | last) as $today\n  | {\n      found: true,\n      day: $today,\n      today: ($all | map(select(.d == $today)) | total),\n      week: ($all | total),\n      days: [range(0; 7) as $n | { label: ($stamps[$n] | strftime(\"%a\")), value: ($all | map(select(.d == $week[$n]) | tokens) | add // 0) }],\n      projects: ($all | group_by(.p) | map({ name: .[0].p } + total | del(.input, .output, .cache, .messages)) | sort_by(-.cost) | .[0:5]),\n      models: ($all | group_by(.m) | map({ name: .[0].m } + total | del(.input, .output, .cache, .messages)) | sort_by(-.cost) | .[0:4])\n    }\n'\n"
        },
        "actions": {
            "publish": {
                "steps": [
                    {
                        "set": {
                            "report": "$args.value"
                        }
                    },
                    {
                        "set": {
                            "five": "$plan.five_hour.used_percentage",
                            "week": "$plan.seven_day.used_percentage",
                            "level": "none",
                            "cost": null
                        }
                    },
                    {
                        "if": "$plan.five_hour.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "five": null
                                }
                            }
                        ]
                    },
                    {
                        "if": "$plan.seven_day.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "week": null
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | map:{null:false, else:true}",
                        "then": [
                            {
                                "set": {
                                    "level": "good"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | map:{null:false, else:true}",
                        "then": [
                            {
                                "set": {
                                    "level": "good"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "warn"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "warn"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "bad"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "bad"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$level | map:{none:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "cost": "$report.today.cost"
                                }
                            }
                        ]
                    }
                ]
            },
            "got_limits": {
                "steps": [
                    {
                        "set": {
                            "plan": {
                                "five_hour": "$args.event.five_hour",
                                "seven_day": "$args.event.seven_day",
                                "at": "$now"
                            }
                        }
                    },
                    {
                        "set": {
                            "five": "$plan.five_hour.used_percentage",
                            "week": "$plan.seven_day.used_percentage",
                            "level": "none",
                            "cost": null
                        }
                    },
                    {
                        "if": "$plan.five_hour.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "five": null
                                }
                            }
                        ]
                    },
                    {
                        "if": "$plan.seven_day.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "week": null
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | map:{null:false, else:true}",
                        "then": [
                            {
                                "set": {
                                    "level": "good"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | map:{null:false, else:true}",
                        "then": [
                            {
                                "set": {
                                    "level": "good"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "warn"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "warn"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "bad"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "bad"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$level | map:{none:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "cost": "$report.today.cost"
                                }
                            }
                        ]
                    }
                ]
            },
            "recalc": {
                "steps": [
                    {
                        "set": {
                            "five": "$plan.five_hour.used_percentage",
                            "week": "$plan.seven_day.used_percentage",
                            "level": "none",
                            "cost": null
                        }
                    },
                    {
                        "if": "$plan.five_hour.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "five": null
                                }
                            }
                        ]
                    },
                    {
                        "if": "$plan.seven_day.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "week": null
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | map:{null:false, else:true}",
                        "then": [
                            {
                                "set": {
                                    "level": "good"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | map:{null:false, else:true}",
                        "then": [
                            {
                                "set": {
                                    "level": "good"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "warn"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "warn"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$five | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "bad"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$week | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "level": "bad"
                                }
                            }
                        ]
                    },
                    {
                        "if": "$level | map:{none:true, else:false}",
                        "then": [
                            {
                                "set": {
                                    "cost": "$report.today.cost"
                                }
                            }
                        ]
                    }
                ]
            }
        },
        "cards": [
            {
                "id": "main",
                "layout": {
                    "column": [
                        {
                            "section": "Plan limits",
                            "children": [
                                {
                                    "row": [
                                        {
                                            "text": "5 hours",
                                            "size": "s"
                                        },
                                        {
                                            "progress": "$five | times:0.01",
                                            "style": "bar",
                                            "tone": "$five | tone:{bad:'>=90', warn:'>=70', else:'good'}",
                                            "grow": true
                                        },
                                        {
                                            "text": "{$five | round}%",
                                            "size": "s",
                                            "emphasis": "strong"
                                        },
                                        {
                                            "timer": "$plan.five_hour.resets_at",
                                            "mode": "until",
                                            "format": "short",
                                            "size": "s"
                                        }
                                    ],
                                    "align": "center",
                                    "gap": "s",
                                    "when": "$five | map:{null:false, else:true}"
                                },
                                {
                                    "row": [
                                        {
                                            "text": "Week",
                                            "size": "s"
                                        },
                                        {
                                            "progress": "$week | times:0.01",
                                            "style": "bar",
                                            "tone": "$week | tone:{bad:'>=90', warn:'>=70', else:'good'}",
                                            "grow": true
                                        },
                                        {
                                            "text": "{$week | round}%",
                                            "size": "s",
                                            "emphasis": "strong"
                                        },
                                        {
                                            "timer": "$plan.seven_day.resets_at",
                                            "mode": "until",
                                            "format": "short",
                                            "size": "s"
                                        }
                                    ],
                                    "align": "center",
                                    "gap": "s",
                                    "when": "$week | map:{null:false, else:true}"
                                },
                                {
                                    "text": "From Claude Code's status line, checked {$plan.at | ago}. Each limit resets after the time on the right.",
                                    "size": "xs",
                                    "emphasis": "subtle",
                                    "when": "$level | map:{none:false, else:true}"
                                },
                                {
                                    "text": "Your plan's limits show once Claude Code's status line runs the TailApps script (/tailapps:claude-cards sets it up). Pro and Max plans only.",
                                    "size": "xs",
                                    "emphasis": "subtle",
                                    "when": "$level | map:{none:true, else:false}"
                                }
                            ]
                        },
                        {
                            "section": "Estimated API cost",
                            "children": [
                                {
                                    "grid": [
                                        {
                                            "stat": "$report.today.cost | currency:'USD':'full'",
                                            "label": "Today"
                                        },
                                        {
                                            "stat": "$report.week.cost | currency:'USD':'full'",
                                            "label": "Last 7 days"
                                        }
                                    ],
                                    "columns": 2
                                },
                                {
                                    "chart": "$report.days",
                                    "kind": "bar",
                                    "height": "s",
                                    "when": "$report.week.tokens"
                                },
                                {
                                    "text": "{$report.today.tokens | compact} tokens today \u00b7 {$report.week.tokens | compact} in 7 days",
                                    "size": "s",
                                    "emphasis": "subtle",
                                    "when": "$report.day"
                                },
                                {
                                    "text": "No Claude Code logs in ~/.claude/projects on this Mac yet.",
                                    "size": "s",
                                    "emphasis": "subtle",
                                    "when": "$report.found | map:{false:true, else:false}"
                                },
                                {
                                    "text": "Waiting for your Mac to read Claude Code's logs.",
                                    "size": "s",
                                    "emphasis": "subtle",
                                    "when": "$report.day | map:{null:true, else:false}"
                                },
                                {
                                    "text": "Estimated at API list prices; on a Pro or Max plan you don't pay this.",
                                    "size": "xs",
                                    "emphasis": "subtle",
                                    "when": "$report.day"
                                },
                                {
                                    "text": "Read {$meta.usage.updated | ago}",
                                    "size": "xs",
                                    "emphasis": "subtle",
                                    "platforms": [
                                        "macos"
                                    ],
                                    "when": "$meta.usage.updated"
                                }
                            ]
                        },
                        {
                            "section": "Top projects",
                            "when": "$report.projects",
                            "children": [
                                {
                                    "list": "$report.projects",
                                    "limit": 5,
                                    "item": {
                                        "cell": "$item.name",
                                        "subtitle": "{$item.tokens | compact} tokens",
                                        "trailing": "{$item.cost | currency:'USD':'full'}"
                                    }
                                }
                            ]
                        },
                        {
                            "section": "Models",
                            "collapsible": true,
                            "collapsed": true,
                            "when": "$report.models",
                            "children": [
                                {
                                    "list": "$report.models",
                                    "limit": 4,
                                    "item": {
                                        "cell": "$item.name",
                                        "subtitle": "{$item.tokens | compact} tokens",
                                        "trailing": "{$item.cost | currency:'USD':'full'}"
                                    }
                                }
                            ]
                        }
                    ],
                    "gap": "m"
                }
            }
        ],
        "views": {
            "menubar": {
                "icon": "chart.bar",
                "label": "{$five | map:{null:'', else:'5h '}}{$five | round}{$five | map:{null:'', else:'% '}}{$week | map:{null:'', else:'wk '}}{$week | round}{$week | map:{null:'', else:'%'}}{$cost | currency:'USD':'full'}{$cost | map:{null:'', else:' today'}}",
                "label_icon": "chart.bar",
                "in_menu": "row",
                "card": "main",
                "label_tone": "$level | tone:{good:'good', warn:'warn', bad:'bad', else:'neutral'}"
            },
            "floating": {
                "card": "main",
                "width": "default"
            }
        },
        "on_sync": "recalc",
        "alarms": {
            "five_hour_reset": {
                "at": "$plan.five_hour.resets_at",
                "action": "recalc"
            },
            "week_reset": {
                "at": "$plan.seven_day.resets_at",
                "action": "recalc"
            }
        }
    },
    "app_json": "{\n  \"schema\": \"tailapps/v0\",\n  \"app\": \"claude-usage\",\n  \"name\": \"Claude usage\",\n  \"description\": \"Your Claude plan's 5-hour and weekly limits, plus tokens and an estimated API cost by day, project and model, from Claude Code on your Mac. Syncs only these numbers to your iPhone.\",\n  \"icon\": \"chart.bar\",\n  \"version\": 2,\n  \"permissions\": [\n    \"script:usage.sh\",\n    \"inbox:limits\"\n  ],\n  \"state\": {\n    \"report\": {\n      \"type\": \"object\",\n      \"default\": {},\n      \"sync\": true\n    },\n    \"plan\": {\n      \"type\": \"object\",\n      \"default\": {},\n      \"sync\": true\n    },\n    \"five\": {\n      \"type\": \"any\",\n      \"default\": null\n    },\n    \"week\": {\n      \"type\": \"any\",\n      \"default\": null\n    },\n    \"cost\": {\n      \"type\": \"any\",\n      \"default\": null\n    },\n    \"level\": {\n      \"type\": \"text\",\n      \"default\": \"none\"\n    }\n  },\n  \"sources\": {\n    \"usage\": {\n      \"script\": \"usage.sh\",\n      \"every\": 300,\n      \"on\": \"open\",\n      \"timeout\": 240,\n      \"platforms\": [\n        \"macos\"\n      ],\n      \"on_change\": \"publish\"\n    },\n    \"limits\": {\n      \"inbox\": \"limits\",\n      \"on_receive\": \"got_limits\",\n      \"platforms\": [\n        \"macos\"\n      ]\n    }\n  },\n  \"scripts\": {\n    \"usage.sh\": \"#!/bin/sh\\n# Claude Code's token use for the last 7 days, read from its own logs (~/.claude/projects/**/*.jsonl).\\n# Reads only, sends nothing. Prints one JSON object: today, week, days (for a chart), top projects and models.\\n# Cost is an estimate at Anthropic API list prices (input, output, cache write = 1.25 x input, cache read);\\n# on a Pro or Max plan nobody pays it, but it shows how much work the sessions did.\\ndir=\\\"$HOME/.claude/projects\\\"\\nif [ ! -d \\\"$dir\\\" ]; then\\n  echo \\\"{\\\\\\\"found\\\\\\\":false,\\\\\\\"day\\\\\\\":\\\\\\\"$(date +%Y-%m-%d)\\\\\\\",\\\\\\\"today\\\\\\\":{\\\\\\\"tokens\\\\\\\":0,\\\\\\\"cost\\\\\\\":0},\\\\\\\"week\\\\\\\":{\\\\\\\"tokens\\\\\\\":0,\\\\\\\"cost\\\\\\\":0},\\\\\\\"days\\\\\\\":[],\\\\\\\"projects\\\\\\\":[],\\\\\\\"models\\\\\\\":[]}\\\"\\n  exit 0\\nfi\\n# Files touched in the last 8 days; only lines that carry token counts go on to jq.\\nfind \\\"$dir\\\" -type f -name '*.jsonl' -mtime -8 2>/dev/null | while IFS= read -r file; do\\n  grep -F -h '\\\"output_tokens\\\"' \\\"$file\\\" 2>/dev/null\\ndone | jq -R -c '\\n  fromjson? | select(type == \\\"object\\\" and .type == \\\"assistant\\\" and (.message.usage | type) == \\\"object\\\")\\n  | select((.message.model // \\\"\\\") != \\\"<synthetic>\\\")\\n  | .message.usage as $u\\n  | {\\n      k: (if .message.id and .requestId then .message.id + \\\":\\\" + .requestId else \\\"line\\\" + (input_line_number | tostring) end),\\n      t: ((.timestamp // \\\"\\\") | sub(\\\"\\\\\\\\.[0-9]+\\\"; \\\"\\\") | try fromdateiso8601 catch 0),\\n      m: ((.message.model // \\\"unknown\\\") | sub(\\\"^claude-\\\"; \\\"\\\")),\\n      p: ((.cwd // \\\"\\\") | split(\\\"/\\\") | map(select(. != \\\"\\\")) | last // \\\"unknown\\\"),\\n      i: ($u.input_tokens // 0), o: ($u.output_tokens // 0),\\n      w: ($u.cache_creation_input_tokens // 0), r: ($u.cache_read_input_tokens // 0)\\n    }\\n' | jq -s -c '\\n  # $ per million tokens: [input, output, cache read]. Cache writes are 1.25 x input.\\n  def price:\\n    if test(\\\"fable-5-2|mythos-5-2\\\") then [8, 40, 0.2]\\n    elif test(\\\"fable|mythos\\\") then [10, 50, 1]\\n    elif test(\\\"opus-5-5\\\") then [4, 20, 0.2]\\n    elif test(\\\"opus-5|opus-4-[5-9]\\\") then [5, 25, 0.5]\\n    elif test(\\\"opus\\\") then [15, 75, 1.5]\\n    elif test(\\\"sonnet-5-5\\\") then [2, 10, 0.1]\\n    elif test(\\\"sonnet-5\\\") then [2, 10, 0.2]\\n    elif test(\\\"haiku-5\\\") then [0.1, 0.5, 0.01]\\n    elif test(\\\"haiku-4\\\") then [1, 5, 0.1]\\n    elif test(\\\"haiku\\\") then [0.8, 4, 0.08]\\n    else [3, 15, 0.3] end;\\n  def cost: (.m | price) as $p | (.i * $p[0] + .w * $p[0] * 1.25 + .o * $p[1] + .r * $p[2]) / 1000000;\\n  def tokens: .i + .o + .w + .r;\\n  def total: { tokens: (map(tokens) | add // 0), cost: ((map(cost) | add // 0) * 10000 | round / 10000),\\n               input: (map(.i) | add // 0), output: (map(.o) | add // 0), cache: (map(.w + .r) | add // 0), messages: length };\\n  # The last 7 calendar days, counted from noon UTC on the local date of today, so a 23- or 25-hour day skips none.\\n  ((now | strflocaltime(\\\"%Y-%m-%d\\\") | strptime(\\\"%Y-%m-%d\\\") | mktime) + 43200) as $noon\\n  | [range(6; -1; -1) | ($noon - . * 86400)] as $stamps\\n  | ($stamps | map(strftime(\\\"%Y-%m-%d\\\"))) as $week\\n  | map(select(.t > 0) | . + { d: (.t | strflocaltime(\\\"%Y-%m-%d\\\")) } | select(.d as $d | $week | index($d)))\\n  # Claude Code writes a line per content block of a reply, each with the usage so far: keep the fullest one.\\n  | group_by(.k) | map(max_by(.o))\\n  | . as $all\\n  | ($week | last) as $today\\n  | {\\n      found: true,\\n      day: $today,\\n      today: ($all | map(select(.d == $today)) | total),\\n      week: ($all | total),\\n      days: [range(0; 7) as $n | { label: ($stamps[$n] | strftime(\\\"%a\\\")), value: ($all | map(select(.d == $week[$n]) | tokens) | add // 0) }],\\n      projects: ($all | group_by(.p) | map({ name: .[0].p } + total | del(.input, .output, .cache, .messages)) | sort_by(-.cost) | .[0:5]),\\n      models: ($all | group_by(.m) | map({ name: .[0].m } + total | del(.input, .output, .cache, .messages)) | sort_by(-.cost) | .[0:4])\\n    }\\n'\\n\"\n  },\n  \"actions\": {\n    \"publish\": {\n      \"steps\": [\n        {\n          \"set\": {\n            \"report\": \"$args.value\"\n          }\n        },\n        {\n          \"set\": {\n            \"five\": \"$plan.five_hour.used_percentage\",\n            \"week\": \"$plan.seven_day.used_percentage\",\n            \"level\": \"none\",\n            \"cost\": null\n          }\n        },\n        {\n          \"if\": \"$plan.five_hour.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"five\": null\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$plan.seven_day.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"week\": null\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | map:{null:false, else:true}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"good\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | map:{null:false, else:true}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"good\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"warn\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"warn\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"bad\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"bad\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$level | map:{none:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"cost\": \"$report.today.cost\"\n              }\n            }\n          ]\n        }\n      ]\n    },\n    \"got_limits\": {\n      \"steps\": [\n        {\n          \"set\": {\n            \"plan\": {\n              \"five_hour\": \"$args.event.five_hour\",\n              \"seven_day\": \"$args.event.seven_day\",\n              \"at\": \"$now\"\n            }\n          }\n        },\n        {\n          \"set\": {\n            \"five\": \"$plan.five_hour.used_percentage\",\n            \"week\": \"$plan.seven_day.used_percentage\",\n            \"level\": \"none\",\n            \"cost\": null\n          }\n        },\n        {\n          \"if\": \"$plan.five_hour.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"five\": null\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$plan.seven_day.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"week\": null\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | map:{null:false, else:true}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"good\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | map:{null:false, else:true}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"good\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"warn\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"warn\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"bad\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"bad\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$level | map:{none:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"cost\": \"$report.today.cost\"\n              }\n            }\n          ]\n        }\n      ]\n    },\n    \"recalc\": {\n      \"steps\": [\n        {\n          \"set\": {\n            \"five\": \"$plan.five_hour.used_percentage\",\n            \"week\": \"$plan.seven_day.used_percentage\",\n            \"level\": \"none\",\n            \"cost\": null\n          }\n        },\n        {\n          \"if\": \"$plan.five_hour.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"five\": null\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$plan.seven_day.resets_at | times:-1 | add:$now | tone:{bad:'>=0', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"week\": null\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | map:{null:false, else:true}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"good\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | map:{null:false, else:true}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"good\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"warn\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | tone:{bad:'>=70', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"warn\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$five | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"bad\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$week | tone:{bad:'>=90', else:'good'} | map:{bad:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"level\": \"bad\"\n              }\n            }\n          ]\n        },\n        {\n          \"if\": \"$level | map:{none:true, else:false}\",\n          \"then\": [\n            {\n              \"set\": {\n                \"cost\": \"$report.today.cost\"\n              }\n            }\n          ]\n        }\n      ]\n    }\n  },\n  \"cards\": [\n    {\n      \"id\": \"main\",\n      \"layout\": {\n        \"column\": [\n          {\n            \"section\": \"Plan limits\",\n            \"children\": [\n              {\n                \"row\": [\n                  {\n                    \"text\": \"5 hours\",\n                    \"size\": \"s\"\n                  },\n                  {\n                    \"progress\": \"$five | times:0.01\",\n                    \"style\": \"bar\",\n                    \"tone\": \"$five | tone:{bad:'>=90', warn:'>=70', else:'good'}\",\n                    \"grow\": true\n                  },\n                  {\n                    \"text\": \"{$five | round}%\",\n                    \"size\": \"s\",\n                    \"emphasis\": \"strong\"\n                  },\n                  {\n                    \"timer\": \"$plan.five_hour.resets_at\",\n                    \"mode\": \"until\",\n                    \"format\": \"short\",\n                    \"size\": \"s\"\n                  }\n                ],\n                \"align\": \"center\",\n                \"gap\": \"s\",\n                \"when\": \"$five | map:{null:false, else:true}\"\n              },\n              {\n                \"row\": [\n                  {\n                    \"text\": \"Week\",\n                    \"size\": \"s\"\n                  },\n                  {\n                    \"progress\": \"$week | times:0.01\",\n                    \"style\": \"bar\",\n                    \"tone\": \"$week | tone:{bad:'>=90', warn:'>=70', else:'good'}\",\n                    \"grow\": true\n                  },\n                  {\n                    \"text\": \"{$week | round}%\",\n                    \"size\": \"s\",\n                    \"emphasis\": \"strong\"\n                  },\n                  {\n                    \"timer\": \"$plan.seven_day.resets_at\",\n                    \"mode\": \"until\",\n                    \"format\": \"short\",\n                    \"size\": \"s\"\n                  }\n                ],\n                \"align\": \"center\",\n                \"gap\": \"s\",\n                \"when\": \"$week | map:{null:false, else:true}\"\n              },\n              {\n                \"text\": \"From Claude Code's status line, checked {$plan.at | ago}. Each limit resets after the time on the right.\",\n                \"size\": \"xs\",\n                \"emphasis\": \"subtle\",\n                \"when\": \"$level | map:{none:false, else:true}\"\n              },\n              {\n                \"text\": \"Your plan's limits show once Claude Code's status line runs the TailApps script (/tailapps:claude-cards sets it up). Pro and Max plans only.\",\n                \"size\": \"xs\",\n                \"emphasis\": \"subtle\",\n                \"when\": \"$level | map:{none:true, else:false}\"\n              }\n            ]\n          },\n          {\n            \"section\": \"Estimated API cost\",\n            \"children\": [\n              {\n                \"grid\": [\n                  {\n                    \"stat\": \"$report.today.cost | currency:'USD':'full'\",\n                    \"label\": \"Today\"\n                  },\n                  {\n                    \"stat\": \"$report.week.cost | currency:'USD':'full'\",\n                    \"label\": \"Last 7 days\"\n                  }\n                ],\n                \"columns\": 2\n              },\n              {\n                \"chart\": \"$report.days\",\n                \"kind\": \"bar\",\n                \"height\": \"s\",\n                \"when\": \"$report.week.tokens\"\n              },\n              {\n                \"text\": \"{$report.today.tokens | compact} tokens today \u00b7 {$report.week.tokens | compact} in 7 days\",\n                \"size\": \"s\",\n                \"emphasis\": \"subtle\",\n                \"when\": \"$report.day\"\n              },\n              {\n                \"text\": \"No Claude Code logs in ~/.claude/projects on this Mac yet.\",\n                \"size\": \"s\",\n                \"emphasis\": \"subtle\",\n                \"when\": \"$report.found | map:{false:true, else:false}\"\n              },\n              {\n                \"text\": \"Waiting for your Mac to read Claude Code's logs.\",\n                \"size\": \"s\",\n                \"emphasis\": \"subtle\",\n                \"when\": \"$report.day | map:{null:true, else:false}\"\n              },\n              {\n                \"text\": \"Estimated at API list prices; on a Pro or Max plan you don't pay this.\",\n                \"size\": \"xs\",\n                \"emphasis\": \"subtle\",\n                \"when\": \"$report.day\"\n              },\n              {\n                \"text\": \"Read {$meta.usage.updated | ago}\",\n                \"size\": \"xs\",\n                \"emphasis\": \"subtle\",\n                \"platforms\": [\n                  \"macos\"\n                ],\n                \"when\": \"$meta.usage.updated\"\n              }\n            ]\n          },\n          {\n            \"section\": \"Top projects\",\n            \"when\": \"$report.projects\",\n            \"children\": [\n              {\n                \"list\": \"$report.projects\",\n                \"limit\": 5,\n                \"item\": {\n                  \"cell\": \"$item.name\",\n                  \"subtitle\": \"{$item.tokens | compact} tokens\",\n                  \"trailing\": \"{$item.cost | currency:'USD':'full'}\"\n                }\n              }\n            ]\n          },\n          {\n            \"section\": \"Models\",\n            \"collapsible\": true,\n            \"collapsed\": true,\n            \"when\": \"$report.models\",\n            \"children\": [\n              {\n                \"list\": \"$report.models\",\n                \"limit\": 4,\n                \"item\": {\n                  \"cell\": \"$item.name\",\n                  \"subtitle\": \"{$item.tokens | compact} tokens\",\n                  \"trailing\": \"{$item.cost | currency:'USD':'full'}\"\n                }\n              }\n            ]\n          }\n        ],\n        \"gap\": \"m\"\n      }\n    }\n  ],\n  \"views\": {\n    \"menubar\": {\n      \"icon\": \"chart.bar\",\n      \"label\": \"{$five | map:{null:'', else:'5h '}}{$five | round}{$five | map:{null:'', else:'% '}}{$week | map:{null:'', else:'wk '}}{$week | round}{$week | map:{null:'', else:'%'}}{$cost | currency:'USD':'full'}{$cost | map:{null:'', else:' today'}}\",\n      \"label_icon\": \"chart.bar\",\n      \"in_menu\": \"row\",\n      \"card\": \"main\",\n      \"label_tone\": \"$level | tone:{good:'good', warn:'warn', bad:'bad', else:'neutral'}\"\n    },\n    \"floating\": {\n      \"card\": \"main\",\n      \"width\": \"default\"\n    }\n  },\n  \"on_sync\": \"recalc\",\n  \"alarms\": {\n    \"five_hour_reset\": {\n      \"at\": \"$plan.five_hour.resets_at\",\n      \"action\": \"recalc\"\n    },\n    \"week_reset\": {\n      \"at\": \"$plan.seven_day.resets_at\",\n      \"action\": \"recalc\"\n    }\n  }\n}\n",
    "files": []
}