Skip to content

Instantly share code, notes, and snippets.

@mikelane
Created December 12, 2025 21:19
Show Gist options
  • Select an option

  • Save mikelane/9bf3053b5608df5858d299d636a48e8f to your computer and use it in GitHub Desktop.

Select an option

Save mikelane/9bf3053b5608df5858d299d636a48e8f to your computer and use it in GitHub Desktop.
Claude Code Metrics Setup: Prometheus + Grafana dashboards for tracking AI coding productivity
{
"uid": "claude-engineering-economics",
"title": "Claude Code - Engineering Economics",
"tags": [
"claude",
"productivity",
"roi",
"economics"
],
"timezone": "browser",
"schemaVersion": 38,
"refresh": "15s",
"time": {
"from": "now-1h",
"to": "now"
},
"annotations": {
"list": []
},
"templating": {
"list": [
{
"name": "hourly_rate",
"label": "Your Hourly Rate ($)",
"type": "textbox",
"current": {
"value": "130",
"text": "130"
},
"options": [
{
"value": "130",
"text": "130"
}
]
},
{
"name": "dev_lines_per_hour",
"label": "Avg Dev Lines/Hour",
"type": "textbox",
"current": {
"value": "75",
"text": "75"
},
"options": [
{
"value": "75",
"text": "75"
}
]
}
]
},
"panels": [
{
"id": 100,
"title": "Output Efficiency",
"type": "row",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"collapsed": false
},
{
"id": 1,
"title": "Lines of Code",
"description": "Total lines generated in time window",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 0,
"y": 1
},
"targets": [
{
"expr": "sum(sum_over_time(claude_code_lines_of_code_count_total[$__range]))",
"legendFormat": "Lines",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "short",
"decimals": 0
}
},
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 2,
"title": "API Cost",
"description": "Total API cost in time window",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 4,
"y": 1
},
"targets": [
{
"expr": "sum(increase(claude_code_cost_usage_USD_total[$__range]))",
"legendFormat": "Cost",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
},
"unit": "currencyUSD",
"decimals": 2
}
},
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 3,
"title": "Lines per Dollar",
"description": "Code output per dollar of API cost",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 8,
"y": 1
},
"targets": [
{
"expr": "sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / sum(increase(claude_code_cost_usage_USD_total[$__range]))",
"legendFormat": "Lines/$",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "yellow",
"value": null
},
{
"color": "green",
"value": 100
},
{
"color": "super-light-green",
"value": 500
}
]
},
"unit": "short",
"decimals": 0
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 4,
"title": "Cost per Line",
"description": "API cost per line of code (in cents)",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 12,
"y": 1
},
"targets": [
{
"expr": "(sum(increase(claude_code_cost_usage_USD_total[$__range])) / sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])))",
"legendFormat": "cents/line",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "yellow",
"value": 1
},
{
"color": "red",
"value": 5
}
]
},
"unit": "currencyUSD",
"decimals": 4
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 5,
"title": "Lines per Hour",
"description": "Code output velocity",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 16,
"y": 1
},
"targets": [
{
"expr": "sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / ($__range_s / 3600)",
"legendFormat": "lines/hr",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "yellow",
"value": null
},
{
"color": "green",
"value": 500
},
{
"color": "super-light-green",
"value": 2000
}
]
},
"unit": "short",
"decimals": 0
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 6,
"title": "Output per Minute",
"description": "Real-time output rate",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 20,
"y": 1
},
"targets": [
{
"expr": "sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / ($__range_s / 60)",
"legendFormat": "lines/min",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "purple",
"value": null
}
]
},
"unit": "short",
"decimals": 1
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 101,
"title": "Team Equivalence",
"type": "row",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 5
},
"collapsed": false
},
{
"id": 10,
"title": "Equivalent Dev Hours",
"description": "Hours a developer would need at $dev_lines_per_hour lines/hr",
"type": "stat",
"gridPos": {
"h": 5,
"w": 6,
"x": 0,
"y": 6
},
"targets": [
{
"expr": "sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / $dev_lines_per_hour",
"legendFormat": "Dev Hours",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
},
"unit": "h",
"decimals": 1
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 11,
"title": "Equivalent Team Size",
"description": "Number of devs needed to match this output in same time",
"type": "gauge",
"gridPos": {
"h": 5,
"w": 6,
"x": 6,
"y": 6
},
"targets": [
{
"expr": "(sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / $dev_lines_per_hour) / ($__range_s / 3600)",
"legendFormat": "Team Size",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "super-light-green",
"value": 5
},
{
"color": "light-blue",
"value": 20
}
]
},
"unit": "short",
"min": 0,
"max": 50,
"decimals": 1
}
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"showThresholdLabels": true,
"showThresholdMarkers": true
}
},
{
"id": 12,
"title": "Equivalent Output Value",
"description": "What this output would cost at your hourly rate",
"type": "stat",
"gridPos": {
"h": 5,
"w": 6,
"x": 12,
"y": 6
},
"targets": [
{
"expr": "(sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / $dev_lines_per_hour) * $hourly_rate",
"legendFormat": "Output Value",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "currencyUSD",
"decimals": 0
}
},
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 13,
"title": "Velocity Multiplier",
"description": "How many X faster than a single developer",
"type": "stat",
"gridPos": {
"h": 5,
"w": 6,
"x": 18,
"y": 6
},
"targets": [
{
"expr": "(sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / ($__range_s / 3600)) / $dev_lines_per_hour",
"legendFormat": "Velocity X",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "yellow",
"value": null
},
{
"color": "green",
"value": 5
},
{
"color": "super-light-green",
"value": 20
}
]
},
"unit": "x",
"decimals": 1
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 102,
"title": "Your Investment & ROI",
"type": "row",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 11
},
"collapsed": false
},
{
"id": 20,
"title": "Your Time Invested",
"description": "Your active interaction time with Claude",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 0,
"y": 12
},
"targets": [
{
"expr": "sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range])) / 3600",
"legendFormat": "Your Hours",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "orange",
"value": null
}
]
},
"unit": "h",
"decimals": 2
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 21,
"title": "Your Time Cost",
"description": "Value of your time at $hourly_rate/hr",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 4,
"y": 12
},
"targets": [
{
"expr": "(sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range])) / 3600) * $hourly_rate",
"legendFormat": "Your Cost",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "orange",
"value": null
}
]
},
"unit": "currencyUSD",
"decimals": 2
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 22,
"title": "Net Value Created",
"description": "Output Value - Your Time Cost (your productivity profit)",
"type": "stat",
"gridPos": {
"h": 4,
"w": 8,
"x": 0,
"y": 16
},
"targets": [
{
"expr": "((sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / $dev_lines_per_hour) * $hourly_rate) - ((sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range])) / 3600) * $hourly_rate)",
"legendFormat": "Net Value",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "green",
"value": 0
}
]
},
"unit": "currencyUSD",
"decimals": 0
}
},
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 23,
"title": "Time ROI",
"description": "Output value / Your time cost",
"type": "gauge",
"gridPos": {
"h": 4,
"w": 6,
"x": 12,
"y": 12
},
"targets": [
{
"expr": "((sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / $dev_lines_per_hour) * $hourly_rate) / ((sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range])) / 3600) * $hourly_rate)",
"legendFormat": "ROI",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "yellow",
"value": 1
},
{
"color": "green",
"value": 5
},
{
"color": "super-light-green",
"value": 20
}
]
},
"unit": "x",
"min": 0,
"max": 100,
"decimals": 1
}
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"showThresholdLabels": true,
"showThresholdMarkers": true
}
},
{
"id": 24,
"title": "Hours Saved",
"description": "Dev hours equivalent minus your time",
"type": "stat",
"gridPos": {
"h": 4,
"w": 8,
"x": 16,
"y": 16
},
"targets": [
{
"expr": "(sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / $dev_lines_per_hour) - (sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range])) / 3600)",
"legendFormat": "Hours Saved",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "green",
"value": 0
}
]
},
"unit": "h",
"decimals": 1
}
},
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 103,
"title": "Max Plan Economics",
"type": "row",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 20
},
"collapsed": false
},
{
"id": 30,
"title": "API Value Generated",
"description": "What you'd pay at API rates",
"type": "stat",
"gridPos": {
"h": 5,
"w": 6,
"x": 0,
"y": 21
},
"targets": [
{
"expr": "sum(increase(claude_code_cost_usage_USD_total[$__range]))",
"legendFormat": "API Value",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "currencyUSD",
"decimals": 2
}
},
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 31,
"title": "Max Plan Cost (pro-rated)",
"description": "$200/mo = $6.67/day pro-rated to time window",
"type": "stat",
"gridPos": {
"h": 5,
"w": 6,
"x": 6,
"y": 21
},
"targets": [
{
"expr": "6.67 * ($__range_s / 86400)",
"legendFormat": "Max Cost",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
},
"unit": "currencyUSD",
"decimals": 2
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 32,
"title": "Max Plan ROI",
"description": "API value / Pro-rated subscription cost",
"type": "gauge",
"gridPos": {
"h": 5,
"w": 6,
"x": 12,
"y": 21
},
"targets": [
{
"expr": "sum(increase(claude_code_cost_usage_USD_total[$__range])) / (6.67 * ($__range_s / 86400))",
"legendFormat": "Max ROI",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "yellow",
"value": 1
},
{
"color": "green",
"value": 5
},
{
"color": "super-light-green",
"value": 20
}
]
},
"unit": "x",
"min": 0,
"max": 100,
"decimals": 1
}
},
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"showThresholdLabels": true,
"showThresholdMarkers": true
}
},
{
"id": 33,
"title": "Max Plan Savings",
"description": "API value - Pro-rated subscription cost",
"type": "stat",
"gridPos": {
"h": 5,
"w": 6,
"x": 18,
"y": 21
},
"targets": [
{
"expr": "sum(increase(claude_code_cost_usage_USD_total[$__range])) - (6.67 * ($__range_s / 86400))",
"legendFormat": "Savings",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "green",
"value": 0
}
]
},
"unit": "currencyUSD",
"decimals": 2
}
},
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 104,
"title": "Velocity Over Time",
"type": "row",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 26
},
"collapsed": false
},
{
"id": 40,
"title": "Lines per Hour Over Time",
"description": "Code output velocity trend",
"type": "timeseries",
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 27
},
"targets": [
{
"expr": "sum(rate(claude_code_lines_of_code_count_total[5m])) * 3600",
"legendFormat": "Lines/Hour",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "lines/hour",
"axisPlacement": "auto",
"drawStyle": "line",
"fillOpacity": 20,
"gradientMode": "opacity",
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
}
},
"unit": "short"
}
},
"options": {
"legend": {
"calcs": [
"mean",
"max"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
}
},
{
"id": 41,
"title": "Cumulative Value Generated",
"description": "Running total of equivalent output value",
"type": "timeseries",
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 27
},
"targets": [
{
"expr": "(sum(claude_code_lines_of_code_count_total) / $dev_lines_per_hour) * $hourly_rate",
"legendFormat": "Output Value ($)",
"refId": "A"
},
{
"expr": "sum(claude_code_cost_usage_USD_total)",
"legendFormat": "API Cost ($)",
"refId": "B"
}
],
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "USD",
"axisPlacement": "auto",
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "opacity",
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
}
},
"unit": "currencyUSD"
}
},
"options": {
"legend": {
"calcs": [
"last"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
}
},
{
"id": 25,
"title": "Savings vs Hiring Team",
"description": "What you saved vs hiring devs: Team Cost - (Your Time + Max Plan)",
"type": "stat",
"gridPos": {
"h": 4,
"w": 8,
"x": 8,
"y": 16
},
"targets": [
{
"expr": "((sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / $dev_lines_per_hour) * $hourly_rate) - (((sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range])) / 3600) * $hourly_rate) + (6.67 * ($__range_s / 86400)))",
"legendFormat": "Savings",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "green",
"value": 0
}
]
},
"unit": "currencyUSD",
"decimals": 0
}
},
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
},
{
"id": 26,
"title": "Your Total Cost",
"description": "Your Time Cost + Pro-rated Max Plan",
"type": "stat",
"gridPos": {
"h": 4,
"w": 4,
"x": 8,
"y": 12
},
"targets": [
{
"expr": "((sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range])) / 3600) * $hourly_rate) + (6.67 * ($__range_s / 86400))",
"legendFormat": "Total Cost",
"refId": "A"
}
],
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "orange",
"value": null
}
]
},
"unit": "currencyUSD",
"decimals": 2
}
},
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"textMode": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
}
}
}
]
}
{
"id": 1,
"panels": [
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 100,
"panels": [],
"title": "",
"type": "row"
},
{
"description": "Total Claude Code sessions tracked",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "none"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 0,
"y": 1
},
"id": 1,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "count(count by (session_id)(claude_code_token_usage_tokens_total))",
"refId": "A"
}
],
"title": "Sessions",
"type": "stat"
},
{
"description": "Total commits made via Claude Code",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
},
"unit": "none"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 4,
"y": 1
},
"id": 2,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_commit_count_total)",
"refId": "A"
}
],
"title": "Commits Made",
"type": "stat"
},
{
"description": "Time Claude spent actively working",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "purple",
"value": null
}
]
},
"unit": "s"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 8,
"y": 1
},
"id": 3,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_active_time_seconds_total{type=\"cli\"})",
"refId": "A"
}
],
"title": "Active Time (CLI)",
"type": "stat"
},
{
"description": "Time you spent interacting with Claude",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "orange",
"value": null
}
]
},
"unit": "s"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 12,
"y": 1
},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_active_time_seconds_total{type=\"user\"})",
"refId": "A"
}
],
"title": "Active Time (You)",
"type": "stat"
},
{
"description": "Total API cost in USD",
"fieldConfig": {
"defaults": {
"decimals": 2,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "yellow",
"value": 10
},
{
"color": "red",
"value": 50
}
]
},
"unit": "currencyUSD"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 16,
"y": 1
},
"id": 5,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_cost_usage_USD_total)",
"refId": "A"
}
],
"title": "Total Cost",
"type": "stat"
},
{
"description": "Lines of code accepted from Claude suggestions",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "semi-dark-green",
"value": null
}
]
},
"unit": "none"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 20,
"y": 1
},
"id": 6,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(sum_over_time(claude_code_lines_of_code_count_total[$__range]))",
"legendFormat": "Lines Accepted",
"refId": "A"
}
],
"title": "Lines of Code",
"type": "stat"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 5
},
"id": 101,
"panels": [],
"title": "Token Stats",
"type": "row"
},
{
"description": "Tokens sent to Claude",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "light-blue",
"value": null
}
]
},
"unit": "short"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 0,
"y": 6
},
"id": 10,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_token_usage_tokens_total{type=\"input\"})",
"refId": "A"
}
],
"title": "Input Tokens",
"type": "stat"
},
{
"description": "Tokens generated by Claude",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "light-orange",
"value": null
}
]
},
"unit": "short"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 4,
"y": 6
},
"id": 11,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_token_usage_tokens_total{type=\"output\"})",
"refId": "A"
}
],
"title": "Output Tokens",
"type": "stat"
},
{
"description": "Tokens read from cache (saves money!)",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "semi-dark-green",
"value": null
}
]
},
"unit": "short"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 8,
"y": 6
},
"id": 12,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_token_usage_tokens_total{type=\"cacheRead\"})",
"refId": "A"
}
],
"title": "Cache Read",
"type": "stat"
},
{
"description": "Tokens written to cache",
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "light-purple",
"value": null
}
]
},
"unit": "short"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 12,
"y": 6
},
"id": 13,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_token_usage_tokens_total{type=\"cacheCreation\"})",
"refId": "A"
}
],
"title": "Cache Creation",
"type": "stat"
},
{
"description": "Percentage of input served from cache",
"fieldConfig": {
"defaults": {
"mappings": [],
"max": 100,
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "yellow",
"value": 50
},
{
"color": "green",
"value": 80
}
]
},
"unit": "percent"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 16,
"y": 6
},
"id": 14,
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"targets": [
{
"expr": "sum(claude_code_token_usage_tokens_total{type=\"cacheRead\"}) / (sum(claude_code_token_usage_tokens_total{type=\"cacheRead\"}) + sum(claude_code_token_usage_tokens_total{type=\"input\"})) * 100",
"refId": "A"
}
],
"title": "Cache Efficiency",
"type": "gauge"
},
{
"description": "Average cost per 1000 output tokens",
"fieldConfig": {
"defaults": {
"decimals": 4,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "yellow",
"value": 0.05
},
{
"color": "red",
"value": 0.1
}
]
},
"unit": "currencyUSD"
}
},
"gridPos": {
"h": 4,
"w": 4,
"x": 20,
"y": 6
},
"id": 15,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"textMode": "auto"
},
"targets": [
{
"expr": "sum(claude_code_cost_usage_USD_total) / sum(claude_code_token_usage_tokens_total{type=\"output\"}) * 1000",
"refId": "A"
}
],
"title": "Cost per 1K Output",
"type": "stat"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 10
},
"id": 102,
"panels": [],
"title": "Breakdowns",
"type": "row"
},
{
"description": "Distribution of token usage by type",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
}
}
},
"gridPos": {
"h": 8,
"w": 8,
"x": 0,
"y": 11
},
"id": 20,
"options": {
"legend": {
"displayMode": "table",
"placement": "right",
"values": [
"value",
"percent"
]
},
"pieType": "donut",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"expr": "sum by (type) (claude_code_token_usage_tokens_total)",
"legendFormat": "{{type}}",
"refId": "A"
}
],
"title": "Tokens by Type",
"type": "piechart"
},
{
"description": "Token usage broken down by model",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
}
}
},
"gridPos": {
"h": 8,
"w": 8,
"x": 8,
"y": 11
},
"id": 21,
"options": {
"legend": {
"displayMode": "table",
"placement": "right",
"values": [
"value",
"percent"
]
},
"pieType": "donut",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"expr": "sum by (model) (claude_code_token_usage_tokens_total)",
"legendFormat": "{{model}}",
"refId": "A"
}
],
"title": "Tokens by Model",
"type": "piechart"
},
{
"description": "API cost broken down by model",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"decimals": 2,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "yellow",
"value": 5
},
{
"color": "red",
"value": 20
}
]
},
"unit": "currencyUSD"
}
},
"gridPos": {
"h": 8,
"w": 8,
"x": 16,
"y": 11
},
"id": 22,
"options": {
"displayMode": "gradient",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"showUnfilled": true
},
"targets": [
{
"expr": "sum by (model) (claude_code_cost_usage_USD_total)",
"legendFormat": "{{model}}",
"refId": "A"
}
],
"title": "Cost by Model",
"type": "bargauge"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 19
},
"id": 103,
"panels": [],
"title": "Time Tracking",
"type": "row"
},
{
"description": "CLI processing time vs User interaction time",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"unit": "s"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 20
},
"id": 30,
"options": {
"legend": {
"displayMode": "table",
"placement": "right",
"values": [
"value",
"percent"
]
},
"pieType": "donut",
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"expr": "sum by (type) (claude_code_active_time_seconds_total)",
"legendFormat": "{{type}}",
"refId": "A"
}
],
"title": "Active Time Distribution",
"type": "piechart"
},
{
"description": "CLI time / User time - higher = Claude doing more work",
"fieldConfig": {
"defaults": {
"decimals": 0,
"mappings": [],
"max": 2500,
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "yellow",
"value": 50
},
{
"color": "green",
"value": 200
},
{
"color": "super-light-green",
"value": 500
}
]
},
"unit": "x"
}
},
"gridPos": {
"h": 8,
"w": 8,
"x": 12,
"y": 20
},
"id": 31,
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"showThresholdLabels": true,
"showThresholdMarkers": true
},
"targets": [
{
"expr": "sum(claude_code_active_time_seconds_total{type=\"cli\"}) / sum(claude_code_active_time_seconds_total{type=\"user\"})",
"refId": "A"
}
],
"title": "Productivity Ratio",
"type": "gauge"
},
{
"description": "Highest productivity ratio in time window",
"fieldConfig": {
"defaults": {
"decimals": 0,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "super-light-green",
"value": null
}
]
},
"unit": "x"
}
},
"gridPos": {
"h": 8,
"w": 4,
"x": 20,
"y": 20
},
"id": 36,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "center",
"reduceOptions": {
"calcs": [
"max"
]
},
"textMode": "value_and_name"
},
"targets": [
{
"expr": "max_over_time((sum(claude_code_active_time_seconds_total{type=\"cli\"}) / sum(claude_code_active_time_seconds_total{type=\"user\"}))[$__range:])",
"legendFormat": "Peak",
"refId": "A"
}
],
"title": "Peak Leverage",
"type": "stat"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 28
},
"id": 104,
"panels": [],
"title": "Time Series",
"type": "row"
},
{
"description": "Token consumption rate by type",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "tokens/sec",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 15,
"gradientMode": "opacity",
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
}
},
"unit": "short"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 29
},
"id": 40,
"options": {
"legend": {
"calcs": [
"mean",
"max"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"expr": "sum by (type) (rate(claude_code_token_usage_tokens_total[5m]))",
"legendFormat": "{{type}}",
"refId": "A"
}
],
"title": "Token Usage Over Time",
"type": "timeseries"
},
{
"description": "Token consumption rate by model",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "tokens/sec",
"axisPlacement": "auto",
"drawStyle": "line",
"fillOpacity": 15,
"gradientMode": "opacity",
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
}
},
"unit": "short"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 29
},
"id": 41,
"options": {
"legend": {
"calcs": [
"mean",
"max"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"expr": "sum by (model) (rate(claude_code_token_usage_tokens_total[5m]))",
"legendFormat": "{{model}}",
"refId": "A"
}
],
"title": "Token Usage by Model Over Time",
"type": "timeseries"
},
{
"description": "API cost accumulation rate",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "$/5min",
"axisPlacement": "auto",
"drawStyle": "line",
"fillOpacity": 20,
"gradientMode": "scheme",
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
}
},
"unit": "currencyUSD"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 37
},
"id": 42,
"options": {
"legend": {
"calcs": [
"mean",
"sum"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"expr": "sum by (model) (rate(claude_code_cost_usage_USD_total[5m])) * 300",
"legendFormat": "{{model}}",
"refId": "A"
}
],
"title": "Cost Over Time",
"type": "timeseries"
},
{
"description": "CLI and User activity rate",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "activity rate",
"axisPlacement": "auto",
"drawStyle": "line",
"fillOpacity": 20,
"gradientMode": "opacity",
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
}
},
"unit": "short"
}
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 37
},
"id": 43,
"options": {
"legend": {
"calcs": [
"mean",
"max"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "multi",
"sort": "desc"
}
},
"targets": [
{
"expr": "sum by (type) (rate(claude_code_active_time_seconds_total[5m]))",
"legendFormat": "{{type}}",
"refId": "A"
}
],
"title": "Active Time Over Time",
"type": "timeseries"
}
],
"refresh": "15s",
"schemaVersion": 38,
"tags": [
"claude",
"productivity",
"ai",
"development"
],
"time": {
"from": "now-24h",
"to": "now"
},
"timezone": "browser",
"title": "Claude Code Metrics",
"uid": "claude-code-metrics",
"version": 12
}
{"id":2,"panels":[{"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":0},"id":1,"panels":[],"title":"","type":"row"},{"description":"Total spend over selected period","fieldConfig":{"defaults":{"decimals":2,"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"green","value":null},{"color":"yellow","value":25},{"color":"red","value":100}]},"unit":"currencyUSD"}},"gridPos":{"h":6,"w":6,"x":0,"y":1},"id":10,"options":{"colorMode":"value","graphMode":"area","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(increase(claude_code_cost_usage_USD_total[$__range]))","legendFormat":"Cost","refId":"A"}],"title":"Total Cost","type":"stat"},{"description":"Number of Claude Code sessions","fieldConfig":{"defaults":{"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"blue","value":null}]},"unit":"none"}},"gridPos":{"h":6,"w":6,"x":6,"y":1},"id":11,"options":{"colorMode":"value","graphMode":"area","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"count(count by (session_id)(increase(claude_code_token_usage_tokens_total[$__range]) \u003e 0))","legendFormat":"Sessions","refId":"A"}],"title":"Sessions","type":"stat"},{"description":"CLI active time - your productivity gain","fieldConfig":{"defaults":{"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"super-light-green","value":null}]},"unit":"s"}},"gridPos":{"h":6,"w":6,"x":12,"y":1},"id":12,"options":{"colorMode":"value","graphMode":"area","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(increase(claude_code_active_time_seconds_total{type=\"cli\"}[$__range]))","legendFormat":"CLI Time","refId":"A"}],"title":"Time Saved (Est.)","type":"stat"},{"description":"Time you spent interacting","fieldConfig":{"defaults":{"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"orange","value":null}]},"unit":"s"}},"gridPos":{"h":6,"w":6,"x":18,"y":1},"id":13,"options":{"colorMode":"value","graphMode":"area","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range]))","legendFormat":"Your Time","refId":"A"}],"title":"Your Time Invested","type":"stat"},{"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":7},"id":99,"panels":[],"title":"Max Plan Value","type":"row"},{"description":"What this usage would cost at standard API rates","fieldConfig":{"defaults":{"decimals":2,"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"green","value":null}]},"unit":"currencyUSD"}},"gridPos":{"h":5,"w":6,"x":0,"y":8},"id":60,"options":{"colorMode":"value","graphMode":"area","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(claude_code_cost_usage_USD_total)","legendFormat":"API Value","refId":"A"}],"title":"API Value Received","type":"stat"},{"description":"$200/mo = $6.67/day, pro-rated to time window","fieldConfig":{"defaults":{"decimals":2,"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"orange","value":null}]},"unit":"currencyUSD"}},"gridPos":{"h":5,"w":6,"x":6,"y":8},"id":61,"options":{"colorMode":"value","graphMode":"none","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"6.67 * (time() - (time() - $__range_s)) / 86400","legendFormat":"Max Cost","refId":"A"}],"title":"Max Cost (pro-rated)","type":"stat"},{"description":"API value / Max cost - how much more you're getting","fieldConfig":{"defaults":{"decimals":1,"mappings":[],"max":10,"min":0,"thresholds":{"mode":"absolute","steps":[{"color":"red","value":null},{"color":"yellow","value":1},{"color":"green","value":2},{"color":"super-light-green","value":5}]},"unit":"x"}},"gridPos":{"h":5,"w":6,"x":12,"y":8},"id":62,"options":{"reduceOptions":{"calcs":["lastNotNull"]},"showThresholdLabels":true,"showThresholdMarkers":true},"targets":[{"expr":"sum(claude_code_cost_usage_USD_total) / (6.67 * $__range_s / 86400)","legendFormat":"ROI","refId":"A"}],"title":"Max ROI","type":"gauge"},{"description":"Lines of code per dollar of your Max subscription","fieldConfig":{"defaults":{"decimals":0,"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"red","value":null},{"color":"yellow","value":10},{"color":"green","value":50}]},"unit":"none"}},"gridPos":{"h":5,"w":6,"x":18,"y":8},"id":63,"options":{"colorMode":"value","graphMode":"none","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / (6.67 * $__range_s / 86400)","legendFormat":"Lines/Max$","refId":"A"}],"title":"Lines per Max $","type":"stat"},{"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":13},"id":100,"panels":[],"title":"Productivity","type":"row"},{"description":"CLI time / Your time - higher = more AI leverage","fieldConfig":{"defaults":{"decimals":1,"mappings":[],"max":60,"min":0,"thresholds":{"mode":"absolute","steps":[{"color":"red","value":null},{"color":"yellow","value":5},{"color":"green","value":15},{"color":"super-light-green","value":30}]},"unit":"x"}},"gridPos":{"h":6,"w":8,"x":0,"y":14},"id":20,"options":{"reduceOptions":{"calcs":["lastNotNull"]},"showThresholdLabels":true,"showThresholdMarkers":true},"targets":[{"expr":"sum(increase(claude_code_active_time_seconds_total{type=\"cli\"}[$__range])) / sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[$__range]))","legendFormat":"Leverage","refId":"A"}],"title":"Leverage Ratio","type":"gauge"},{"description":"% of input served from cache","fieldConfig":{"defaults":{"mappings":[],"max":100,"min":0,"thresholds":{"mode":"absolute","steps":[{"color":"red","value":null},{"color":"yellow","value":50},{"color":"green","value":80}]},"unit":"percent"}},"gridPos":{"h":6,"w":8,"x":8,"y":14},"id":21,"options":{"reduceOptions":{"calcs":["lastNotNull"]},"showThresholdLabels":false,"showThresholdMarkers":true},"targets":[{"expr":"sum(increase(claude_code_token_usage_tokens_total{type=\"cacheRead\"}[$__range])) / (sum(increase(claude_code_token_usage_tokens_total{type=\"cacheRead\"}[$__range])) + sum(increase(claude_code_token_usage_tokens_total{type=\"input\"}[$__range]))) * 100","legendFormat":"Cache %","refId":"A"}],"title":"Cache Efficiency","type":"gauge"},{"description":"How much it costs per hour of Claude working","fieldConfig":{"defaults":{"decimals":2,"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"green","value":null},{"color":"yellow","value":50},{"color":"red","value":100}]},"unit":"currencyUSD"}},"gridPos":{"h":6,"w":8,"x":16,"y":14},"id":22,"options":{"colorMode":"value","graphMode":"none","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(increase(claude_code_cost_usage_USD_total[$__range])) / (sum(increase(claude_code_active_time_seconds_total{type=\"cli\"}[$__range])) / 3600)","legendFormat":"$/hr","refId":"A"}],"title":"Cost per Hour of AI Work","type":"stat"},{"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":20},"id":101,"panels":[],"title":"Output","type":"row"},{"description":"Total lines changed","fieldConfig":{"defaults":{"decimals":0,"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"semi-dark-green","value":null}]},"unit":"none"}},"gridPos":{"h":5,"w":6,"x":0,"y":21},"id":30,"options":{"colorMode":"value","graphMode":"area","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(sum_over_time(claude_code_lines_of_code_count_total[$__range]))","legendFormat":"Lines Accepted","refId":"A"}],"title":"Lines of Code","type":"stat"},{"description":"Commits made via Claude","fieldConfig":{"defaults":{"decimals":0,"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"blue","value":null}]},"unit":"none"}},"gridPos":{"h":5,"w":6,"x":6,"y":21},"id":31,"options":{"colorMode":"value","graphMode":"area","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(increase(claude_code_commit_count_total[$__range]))","legendFormat":"Commits","refId":"A"}],"title":"Commits","type":"stat"},{"description":"All tokens used (input + output)","fieldConfig":{"defaults":{"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null}]},"unit":"short"}},"gridPos":{"h":5,"w":6,"x":12,"y":21},"id":32,"options":{"colorMode":"value","graphMode":"area","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(increase(claude_code_token_usage_tokens_total{type=~\"input|output\"}[$__range]))","legendFormat":"Tokens","refId":"A"}],"title":"Total Tokens","type":"stat"},{"description":"Code output efficiency","fieldConfig":{"defaults":{"decimals":0,"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"red","value":null},{"color":"yellow","value":50},{"color":"green","value":100}]},"unit":"none"}},"gridPos":{"h":5,"w":6,"x":18,"y":21},"id":33,"options":{"colorMode":"value","graphMode":"none","justifyMode":"center","reduceOptions":{"calcs":["lastNotNull"]},"textMode":"value_and_name"},"targets":[{"expr":"sum(sum_over_time(claude_code_lines_of_code_count_total[$__range])) / sum(claude_code_cost_usage_USD_total)","legendFormat":"Lines/$","refId":"A"}],"title":"Lines per Dollar","type":"stat"},{"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":26},"id":102,"panels":[],"title":"Daily Trends","type":"row"},{"description":"Cost per day","fieldConfig":{"defaults":{"color":{"mode":"palette-classic"},"custom":{"axisCenteredZero":false,"axisColorMode":"text","axisLabel":"","axisPlacement":"auto","barAlignment":0,"drawStyle":"bars","fillOpacity":80,"gradientMode":"scheme","lineWidth":1,"pointSize":5,"showPoints":"never","spanNulls":false,"stacking":{"group":"A","mode":"none"}},"thresholds":{"mode":"absolute","steps":[{"color":"green","value":null},{"color":"yellow","value":10},{"color":"red","value":25}]},"unit":"currencyUSD"}},"gridPos":{"h":8,"w":12,"x":0,"y":27},"id":40,"options":{"legend":{"calcs":["sum","mean"],"displayMode":"list","placement":"bottom"},"tooltip":{"mode":"single"}},"targets":[{"expr":"sum(increase(claude_code_cost_usage_USD_total[1d]))","legendFormat":"Daily Cost","refId":"A"}],"title":"Daily Cost","type":"timeseries"},{"description":"Time spent per day (CLI vs User)","fieldConfig":{"defaults":{"color":{"mode":"palette-classic"},"custom":{"axisCenteredZero":false,"axisColorMode":"text","axisLabel":"","axisPlacement":"auto","drawStyle":"bars","fillOpacity":80,"gradientMode":"opacity","lineWidth":1,"pointSize":5,"showPoints":"never","spanNulls":false,"stacking":{"group":"A","mode":"none"}},"unit":"s"}},"gridPos":{"h":8,"w":12,"x":12,"y":27},"id":41,"options":{"legend":{"calcs":["sum","mean"],"displayMode":"list","placement":"bottom"},"tooltip":{"mode":"multi","sort":"desc"}},"targets":[{"expr":"sum(increase(claude_code_active_time_seconds_total{type=\"cli\"}[1d]))","legendFormat":"Claude Working","refId":"A"},{"expr":"sum(increase(claude_code_active_time_seconds_total{type=\"user\"}[1d]))","legendFormat":"You Interacting","refId":"B"}],"title":"Daily Active Time","type":"timeseries"},{"description":"Lines changed per day","fieldConfig":{"defaults":{"color":{"fixedColor":"semi-dark-green","mode":"fixed"},"custom":{"axisCenteredZero":false,"axisColorMode":"text","axisLabel":"","axisPlacement":"auto","drawStyle":"bars","fillOpacity":80,"gradientMode":"scheme","lineWidth":1,"pointSize":5,"showPoints":"never","spanNulls":false,"stacking":{"group":"A","mode":"none"}},"unit":"none"}},"gridPos":{"h":8,"w":12,"x":0,"y":35},"id":42,"options":{"legend":{"calcs":["sum","mean"],"displayMode":"list","placement":"bottom"},"tooltip":{"mode":"single"}},"targets":[{"expr":"sum(sum_over_time(claude_code_lines_of_code_count_total[1d]))","legendFormat":"Lines Accepted","refId":"A"}],"title":"Daily Lines of Code","type":"timeseries"},{"description":"Token usage breakdown per day","fieldConfig":{"defaults":{"color":{"mode":"palette-classic"},"custom":{"axisCenteredZero":false,"axisColorMode":"text","axisLabel":"","axisPlacement":"auto","drawStyle":"bars","fillOpacity":80,"gradientMode":"opacity","lineWidth":1,"pointSize":5,"showPoints":"never","spanNulls":false,"stacking":{"group":"A","mode":"normal"}},"unit":"short"}},"gridPos":{"h":8,"w":12,"x":12,"y":35},"id":43,"options":{"legend":{"calcs":["sum","mean"],"displayMode":"list","placement":"bottom"},"tooltip":{"mode":"multi","sort":"desc"}},"targets":[{"expr":"sum(increase(claude_code_token_usage_tokens_total{type=\"input\"}[1d]))","legendFormat":"Input","refId":"A"},{"expr":"sum(increase(claude_code_token_usage_tokens_total{type=\"output\"}[1d]))","legendFormat":"Output","refId":"B"},{"expr":"sum(increase(claude_code_token_usage_tokens_total{type=\"cacheRead\"}[1d]))","legendFormat":"Cache Read","refId":"C"}],"title":"Daily Tokens by Type","type":"timeseries"},{"collapsed":false,"gridPos":{"h":1,"w":24,"x":0,"y":43},"id":103,"panels":[],"title":"Model Usage","type":"row"},{"description":"Where your money goes","fieldConfig":{"defaults":{"color":{"mode":"palette-classic"},"decimals":2,"unit":"currencyUSD"}},"gridPos":{"h":8,"w":12,"x":0,"y":44},"id":50,"options":{"legend":{"displayMode":"table","placement":"right","values":["value","percent"]},"pieType":"donut","reduceOptions":{"calcs":["lastNotNull"]},"tooltip":{"mode":"single"}},"targets":[{"expr":"sum by (model) (increase(claude_code_cost_usage_USD_total[$__range]))","legendFormat":"{{model}}","refId":"A"}],"title":"Cost by Model","type":"piechart"},{"description":"Token distribution across models","fieldConfig":{"defaults":{"color":{"mode":"palette-classic"},"unit":"short"}},"gridPos":{"h":8,"w":12,"x":12,"y":44},"id":51,"options":{"legend":{"displayMode":"table","placement":"right","values":["value","percent"]},"pieType":"donut","reduceOptions":{"calcs":["lastNotNull"]},"tooltip":{"mode":"single"}},"targets":[{"expr":"sum by (model) (increase(claude_code_token_usage_tokens_total[$__range]))","legendFormat":"{{model}}","refId":"A"}],"title":"Tokens by Model","type":"piechart"}],"refresh":"","schemaVersion":38,"tags":["claude","productivity","summary"],"templating":{"list":[{"current":{"text":"Daily","value":"1d"},"label":"Summary Period","name":"timeframe","options":[{"selected":true,"text":"Daily","value":"1d"},{"selected":false,"text":"Weekly","value":"1w"}],"query":"1d : Daily, 1w : Weekly","type":"custom"}]},"time":{"from":"now-7d","to":"now"},"timezone":"browser","title":"Claude Code - Daily/Weekly Summary","uid":"claude-code-summary","version":5}

Claude Code Metrics Setup Guide

This guide walks through setting up OTEL telemetry from Claude Code to Prometheus + Grafana.

Architecture

Claude Code  -->  OTLP/HTTP  -->  Prometheus  -->  Grafana
   (metrics)      (protobuf)      (storage)       (viz)

1. Environment Variables

Add to your shell profile (~/.bashrc for Linux, ~/.zshrc for macOS):

# Enable Claude Code telemetry
export CLAUDE_CODE_ENABLE_TELEMETRY=1

# OTEL export configuration
export OTEL_METRICS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:9090/api/v1/otlp
export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta

Reload your shell: source ~/.bashrc

2. Prometheus Setup

Install (AL2023 / Amazon Linux)

# Download latest Prometheus
cd /tmp
curl -LO https://github.com/prometheus/prometheus/releases/download/v3.0.0/prometheus-3.0.0.linux-amd64.tar.gz
tar xzf prometheus-3.0.0.linux-amd64.tar.gz
sudo mv prometheus-3.0.0.linux-amd64 /opt/prometheus

# Create data directory
mkdir -p ~/.prometheus/data

Install (macOS with Homebrew)

brew install prometheus

Configuration

Create ~/.prometheus/prometheus.yml:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "prometheus"
    static_configs:
    - targets: ["localhost:9090"]

Run Prometheus with OTLP Receiver

Critical flags:

  • --web.enable-otlp-receiver - Enables the OTLP ingestion endpoint
  • --enable-feature=otlp-deltatocumulative - Converts delta metrics (like lines_of_code) to cumulative
# Linux
/opt/prometheus/prometheus \
  --config.file=~/.prometheus/prometheus.yml \
  --storage.tsdb.path=~/.prometheus/data \
  --web.listen-address=127.0.0.1:9090 \
  --web.enable-otlp-receiver \
  --enable-feature=otlp-deltatocumulative

# macOS (if running manually)
prometheus \
  --config.file=/opt/homebrew/etc/prometheus.yml \
  --storage.tsdb.path=/opt/homebrew/var/prometheus \
  --web.listen-address=127.0.0.1:9090 \
  --web.enable-otlp-receiver \
  --enable-feature=otlp-deltatocumulative

You can run this in a tmux session or background it.

3. Grafana Setup

Install (AL2023 / Amazon Linux)

# Add Grafana repo
sudo tee /etc/yum.repos.d/grafana.repo << 'EOF'
[grafana]
name=grafana
baseurl=https://rpm.grafana.com
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://rpm.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
EOF

sudo dnf install grafana -y
sudo systemctl start grafana-server

Install (macOS)

brew install grafana
brew services start grafana

Access

Add Prometheus Data Source

  1. Go to Connections → Data Sources → Add data source
  2. Select Prometheus
  3. URL: http://localhost:9090
  4. Save & Test

Import Dashboards

  1. Go to Dashboards → Import
  2. Paste the JSON from the dashboard files in this directory
  3. Select your Prometheus data source
  4. Import

Dashboard files included:

  • dashboard-metrics.json - Claude Code Metrics (tokens, cost, productivity ratio)
  • dashboard-summary.json - Daily/Weekly Summary (aggregated stats)
  • dashboard-economics.json - Engineering Economics (ROI, team equivalence)

4. Verify Metrics Are Flowing

After using Claude Code with telemetry enabled:

# Check available metrics
curl -s 'http://localhost:9090/api/v1/label/__name__/values' | jq '.data[]' | grep claude

You should see:

  • claude_code_token_usage_tokens_total
  • claude_code_cost_usage_USD_total
  • claude_code_active_time_seconds_total
  • claude_code_lines_of_code_count_total
  • claude_code_session_count_total

5. Available Metrics

Metric Labels Description
claude_code_token_usage_tokens_total type (input/output/cacheRead/cacheCreation), model Token consumption
claude_code_cost_usage_USD_total model Estimated API cost in USD
claude_code_active_time_seconds_total type (cli/user) Time tracking
claude_code_lines_of_code_count_total type (added/removed) Code output (delta metric!)
claude_code_session_count_total Session count
claude_code_event_count_total event Events (commits, PRs, etc.)

6. Key Queries

Productivity Ratio (CLI time / User time):

sum(claude_code_active_time_seconds_total{type="cli"})
/ sum(claude_code_active_time_seconds_total{type="user"})

Lines per Dollar:

sum(sum_over_time(claude_code_lines_of_code_count_total[$__range]))
/ sum(increase(claude_code_cost_usage_USD_total[$__range]))

Cache Efficiency:

sum(claude_code_token_usage_tokens_total{type="cacheRead"})
/ (sum(claude_code_token_usage_tokens_total{type="cacheRead"}) + sum(claude_code_token_usage_tokens_total{type="input"}))
* 100

Important: The lines_of_code metric is a delta metric, not cumulative. Use sum_over_time() instead of increase():

# Correct
sum(sum_over_time(claude_code_lines_of_code_count_total[$__range]))

# Wrong - will give weird extrapolated values
sum(increase(claude_code_lines_of_code_count_total[$__range]))

7. Troubleshooting

No metrics showing up

  1. Check env vars are set: env | grep OTEL
  2. Verify Prometheus is running with OTLP flags: ps aux | grep prometheus
  3. Check Prometheus logs for OTLP errors
  4. Make sure you've used Claude Code after setting env vars (restart terminal first)

Grafana can't connect to Prometheus

  1. Verify Prometheus is running: curl http://localhost:9090/-/healthy
  2. Check Grafana data source URL matches Prometheus listen address

Dashboard shows no data

  1. Check time range (try "Last 24 hours")
  2. Verify metrics exist: curl 'http://localhost:9090/api/v1/query?query=claude_code_token_usage_tokens_total'
  3. Make sure Prometheus data source is selected in dashboard

8. For Datadog (Alternative)

If pushing to Datadog instead of local Prometheus:

export OTEL_METRICS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.datadoghq.com
export OTEL_EXPORTER_OTLP_HEADERS="DD-API-KEY=your_api_key"

The same metrics will flow to Datadog, and you can build similar dashboards there.

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