Loading...
Real-time coding velocity monitor tracking lines added/removed per minute with productivity scoring and daily output projection for Claude Code sessions.
#!/usr/bin/env bash
# Lines Per Minute Productivity Tracker for Claude Code
# Calculates coding velocity and productivity metrics
# Read JSON from stdin
read -r input
# Extract values
lines_added=$(echo "$input" | jq -r '.cost.total_lines_added // 0')
lines_removed=$(echo "$input" | jq -r '.cost.total_lines_removed // 0')
total_duration_ms=$(echo "$input" | jq -r '.cost.total_duration_ms // 1')
# Calculate duration in minutes (avoid division by zero)
if [ "$total_duration_ms" -gt 0 ]; then
duration_minutes=$(echo "scale=2; $total_duration_ms / 60000" | bc)
else
duration_minutes=0.01 # Prevent division by zero
fi
# Calculate net lines (added - removed)
net_lines=$((lines_added - lines_removed))
# Calculate total changed lines (added + removed)
total_changed=$((lines_added + lines_removed))
# Calculate lines per minute
if (( $(echo "$duration_minutes > 0" | bc -l) )); then
added_per_min=$(echo "scale=1; $lines_added / $duration_minutes" | bc)
removed_per_min=$(echo "scale=1; $lines_removed / $duration_minutes" | bc)
net_per_min=$(echo "scale=1; $net_lines / $duration_minutes" | bc)
total_per_min=$(echo "scale=1; $total_changed / $duration_minutes" | bc)
else
added_per_min=0
removed_per_min=0
net_per_min=0
total_per_min=0
fi
# Productivity scoring based on total changes per minute
if (( $(echo "$total_per_min > 50" | bc -l) )); then
PROD_COLOR="\033[38;5;46m" # Green: High productivity (>50 lines/min)
PROD_ICON="🚀"
PROD_RATING="HIGH"
elif (( $(echo "$total_per_min > 20" | bc -l) )); then
PROD_COLOR="\033[38;5;226m" # Yellow: Medium productivity (20-50 lines/min)
PROD_ICON="📝"
PROD_RATING="MED"
else
PROD_COLOR="\033[38;5;75m" # Blue: Low/steady productivity (<20 lines/min)
PROD_ICON="✏️"
PROD_RATING="LOW"
fi
# Project daily output (assuming 8-hour workday = 480 minutes)
if (( $(echo "$net_per_min > 0" | bc -l) )); then
daily_projection=$(echo "scale=0; $net_per_min * 480" | bc)
else
daily_projection=0
fi
RESET="\033[0m"
# Format output with net lines indicator
if [ $net_lines -lt 0 ]; then
net_display="${net_lines}"
net_label="(refactoring)"
else
net_display="+${net_lines}"
net_label="(growth)"
fi
# Output statusline
echo -e "${PROD_ICON} ${PROD_RATING}: ${PROD_COLOR}${total_per_min} L/min${RESET} | +${added_per_min} -${removed_per_min} | Net: ${net_display} ${net_label} | 📅 ${daily_projection} L/day"{
"format": "bash",
"position": "left",
"refreshInterval": 1000
}Lines per minute showing 0 despite active coding
Verify cost.total_lines_added and cost.total_lines_removed fields exist: echo '$input' | jq .cost. Ensure bc is installed: which bc. Check duration_minutes calculation: should be total_duration_ms / 60000. Very short sessions may show 0 until threshold reached.
Daily projection seems unrealistically high
Daily projection assumes CONTINUOUS coding at current velocity for 8 hours (480 minutes). This is intentional for productivity goal-setting. Actual daily output will be lower with breaks, meetings, etc. Adjust multiplier from 480 to expected active coding minutes per day.
Net lines showing negative (refactoring) when expecting growth
Negative net lines means total_lines_removed > total_lines_added. This is EXPECTED for refactoring/cleanup sessions. Script correctly labels as '(refactoring)'. If unexpected, verify you're looking at correct session - multi-file refactors often have more deletions than additions.
Productivity rating stuck at LOW despite high activity
Productivity rating is based on TOTAL changes (added + removed), not net lines. Thresholds: <20 L/min = LOW, 20-50 = MED, >50 = HIGH. Check total_per_min calculation: (lines_added + lines_removed) / duration_minutes. Adjust thresholds if your baseline velocity differs.
bc: command not found when calculating velocity
Install bc: brew install bc (macOS), apt install bc (Linux). Alternative: use integer math with awk: awk -v added=$lines_added -v dur=$duration_minutes 'BEGIN {print added/dur}' - loses decimal precision but works without bc.
Loading reviews...