From d5c8ca937d8b1725acd0b2714685c325f335d50e Mon Sep 17 00:00:00 2001 From: claude Date: Tue, 17 Mar 2026 13:16:51 +0000 Subject: [PATCH] Fix show-impact.sh cost formatting to use python3 instead of bc Co-Authored-By: Claude Opus 4.6 (1M context) --- .claude/hooks/show-impact.sh | 9 +++++---- impact-toolkit/hooks/show-impact.sh | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.claude/hooks/show-impact.sh b/.claude/hooks/show-impact.sh index cdb2100..4c57b2e 100755 --- a/.claude/hooks/show-impact.sh +++ b/.claude/hooks/show-impact.sh @@ -48,7 +48,8 @@ while IFS= read -r line; do if [ "$cache_create" != "0" ] || [ "$cache_read" != "0" ]; then printf " Cache: %s created, %s read\n" "$cache_create" "$cache_read" fi - LC_NUMERIC=C printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%.2f\n" "$energy" "$co2" "$(echo "$cost / 100" | bc -l 2>/dev/null || echo "$cost cents")" + cost_dollars=$(python3 -c "print(f'{int(\"${cost}\") / 100:.2f}')" 2>/dev/null || echo "?") + printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%s\n" "$energy" "$co2" "$cost_dollars" # Social cost proxies (if present in log entry) model=$(echo "$line" | jq -r '.model_id // empty') @@ -88,9 +89,9 @@ TOTAL_COST=$(jq -s '[.[].cost_cents] | add' "$LOG_FILE") TOTAL_ENTRIES=$(wc -l < "$LOG_FILE") echo "=== Totals ($TOTAL_ENTRIES snapshots) ===" -LC_NUMERIC=C printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%.2f\n" \ - "$TOTAL_ENERGY" "$TOTAL_CO2" \ - "$(echo "$TOTAL_COST / 100" | bc -l 2>/dev/null || echo "$TOTAL_COST cents")" +TOTAL_COST_DOLLARS=$(python3 -c "print(f'{int(\"${TOTAL_COST}\") / 100:.2f}')" 2>/dev/null || echo "?") +printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%s\n" \ + "$TOTAL_ENERGY" "$TOTAL_CO2" "$TOTAL_COST_DOLLARS" # Show annotations if they exist ANNOT_FILE="$PROJECT_DIR/.claude/impact/annotations.jsonl" diff --git a/impact-toolkit/hooks/show-impact.sh b/impact-toolkit/hooks/show-impact.sh index cdb2100..4c57b2e 100755 --- a/impact-toolkit/hooks/show-impact.sh +++ b/impact-toolkit/hooks/show-impact.sh @@ -48,7 +48,8 @@ while IFS= read -r line; do if [ "$cache_create" != "0" ] || [ "$cache_read" != "0" ]; then printf " Cache: %s created, %s read\n" "$cache_create" "$cache_read" fi - LC_NUMERIC=C printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%.2f\n" "$energy" "$co2" "$(echo "$cost / 100" | bc -l 2>/dev/null || echo "$cost cents")" + cost_dollars=$(python3 -c "print(f'{int(\"${cost}\") / 100:.2f}')" 2>/dev/null || echo "?") + printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%s\n" "$energy" "$co2" "$cost_dollars" # Social cost proxies (if present in log entry) model=$(echo "$line" | jq -r '.model_id // empty') @@ -88,9 +89,9 @@ TOTAL_COST=$(jq -s '[.[].cost_cents] | add' "$LOG_FILE") TOTAL_ENTRIES=$(wc -l < "$LOG_FILE") echo "=== Totals ($TOTAL_ENTRIES snapshots) ===" -LC_NUMERIC=C printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%.2f\n" \ - "$TOTAL_ENERGY" "$TOTAL_CO2" \ - "$(echo "$TOTAL_COST / 100" | bc -l 2>/dev/null || echo "$TOTAL_COST cents")" +TOTAL_COST_DOLLARS=$(python3 -c "print(f'{int(\"${TOTAL_COST}\") / 100:.2f}')" 2>/dev/null || echo "?") +printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%s\n" \ + "$TOTAL_ENERGY" "$TOTAL_CO2" "$TOTAL_COST_DOLLARS" # Show annotations if they exist ANNOT_FILE="$PROJECT_DIR/.claude/impact/annotations.jsonl"