Skip to content

Instantly share code, notes, and snippets.

@MrLucas11
Created June 4, 2026 07:25
Show Gist options
  • Select an option

  • Save MrLucas11/45c770723fd216da4a1a97645f446eea to your computer and use it in GitHub Desktop.

Select an option

Save MrLucas11/45c770723fd216da4a1a97645f446eea to your computer and use it in GitHub Desktop.
Free: see where your Claude Code token spend goes + the tactics that cut it

Claude Code Token-Saver β€” FREE sample

Post this publicly (GitHub gist / repo README / Reddit / Show HN). It's the runnable, free-to-try hook that makes Show HN and Reddit value-first posts legitimate. The full kit (18 tactics + drop-in configs + rules + scripts) is the paid upgrade.

Free: the 5 tactics that are ~80% of the savings

  1. Route the model to the task. Haiku for mechanical edits/scaffolding, Sonnet for daily feature work, Opus only for genuinely hard reasoning. Pinning everything to the top model is the most expensive default there is.
  2. /clear between unrelated tasks. Every turn re-sends the whole conversation as input tokens; don't pay to drag a finished task into the next one.
  3. Stop re-reading files you just edited. The edit already confirmed success β€” re-reading to "verify" doubles the cost for zero new info.
  4. (API) Turn on prompt caching + the Batch API. Cached input and non-realtime batch jobs are dramatically cheaper. Most people never switch them on.
  5. Cap extended thinking on routine sessions. Great for hard problems, pure overhead on easy ones.

Free: the token-report script

A read-only script (Windows PowerShell + bash) that scans your local Claude Code transcripts and shows input/output/cached tokens + cache-hit % over the last N days. Run it weekly; watch the number drop. (Included in this sample.)

Want the full thing?

The paid Claude Code Token-Saver Kit adds:

  • The full 18-tactic playbook, ranked by $ saved per minute
  • A ready-to-merge cost-control settings.json (model default, thinking cap, hygiene hook)
  • A model-routing decision table
  • A drop-in cost-control.md rules file
  • Single-seat commercial license + 14-day refund

πŸ‘‰ https://payhip.com/b/QlJE9

Prices and model names change β€” always confirm current numbers in Anthropic's official docs. The tactics are durable.

# token-report.ps1 β€” quick estimate of recent Claude Code usage (Windows PowerShell)
# Reads Claude Code project transcripts and tallies approximate token usage so you
# can watch your spend trend down week over week. Read-only; touches nothing else.
#
# Usage: powershell -ExecutionPolicy Bypass -File token-report.ps1
# powershell -File token-report.ps1 -Days 7
param(
[int]$Days = 7
)
$projectsDir = Join-Path $env:USERPROFILE ".claude\projects"
if (-not (Test-Path $projectsDir)) {
Write-Host "No Claude Code projects directory found at $projectsDir" -ForegroundColor Yellow
exit 0
}
$cutoff = (Get-Date).AddDays(-$Days)
$files = Get-ChildItem -Path $projectsDir -Recurse -Filter *.jsonl -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -ge $cutoff }
if (-not $files) {
Write-Host "No transcript activity in the last $Days day(s)." -ForegroundColor Yellow
exit 0
}
$inputTokens = 0
$outputTokens = 0
$cacheRead = 0
foreach ($f in $files) {
foreach ($line in [System.IO.File]::ReadLines($f.FullName)) {
if ($line -notmatch '"usage"') { continue }
try { $obj = $line | ConvertFrom-Json -ErrorAction Stop } catch { continue }
$u = $obj.message.usage
if ($null -eq $u) { $u = $obj.usage }
if ($null -eq $u) { continue }
if ($u.input_tokens) { $inputTokens += [int]$u.input_tokens }
if ($u.output_tokens) { $outputTokens += [int]$u.output_tokens }
if ($u.cache_read_input_tokens) { $cacheRead += [int]$u.cache_read_input_tokens }
}
}
$totalIn = $inputTokens + $cacheRead
$cachePct = if ($totalIn -gt 0) { [math]::Round(($cacheRead / $totalIn) * 100, 1) } else { 0 }
Write-Host ""
Write-Host "Claude Code usage - last $Days day(s)" -ForegroundColor Cyan
Write-Host "----------------------------------------"
Write-Host ("Input tokens (fresh): " + $inputTokens.ToString("N0"))
Write-Host ("Input tokens (cached): " + $cacheRead.ToString("N0") + " " + $cachePct + "% from cache")
Write-Host ("Output tokens: " + $outputTokens.ToString("N0"))
Write-Host ""
Write-Host "Tip: higher cache % = lower bill. If cache % is near 0 and you build on the API," -ForegroundColor DarkGray
Write-Host "see GUIDE.md tactic #2 (prompt caching)." -ForegroundColor DarkGray
#!/usr/bin/env bash
# token-report.sh β€” quick estimate of recent Claude Code usage (macOS/Linux)
# Reads Claude Code project transcripts and tallies approximate token usage.
# Read-only. Requires: jq.
#
# Usage: ./token-report.sh [DAYS] (default 7)
set -euo pipefail
DAYS="${1:-7}"
DIR="$HOME/.claude/projects"
if ! command -v jq >/dev/null 2>&1; then
echo "This script needs 'jq'. Install it (brew install jq / apt-get install jq) and retry." >&2
exit 1
fi
if [ ! -d "$DIR" ]; then
echo "No Claude Code projects directory at $DIR"
exit 0
fi
in_fresh=0; in_cache=0; out=0
while IFS= read -r -d '' f; do
while IFS= read -r line; do
case "$line" in
*'"usage"'*) ;;
*) continue ;;
esac
i=$(printf '%s' "$line" | jq -r '(.message.usage // .usage).input_tokens // 0' 2>/dev/null || echo 0)
c=$(printf '%s' "$line" | jq -r '(.message.usage // .usage).cache_read_input_tokens // 0' 2>/dev/null || echo 0)
o=$(printf '%s' "$line" | jq -r '(.message.usage // .usage).output_tokens // 0' 2>/dev/null || echo 0)
in_fresh=$(( in_fresh + i ))
in_cache=$(( in_cache + c ))
out=$(( out + o ))
done < "$f"
done < <(find "$DIR" -name '*.jsonl' -type f -mtime "-${DAYS}" -print0)
total_in=$(( in_fresh + in_cache ))
pct=0
[ "$total_in" -gt 0 ] && pct=$(( in_cache * 100 / total_in ))
echo ""
echo "Claude Code usage - last ${DAYS} day(s)"
echo "----------------------------------------"
printf "Input tokens (fresh): %'d\n" "$in_fresh" 2>/dev/null || echo "Input tokens (fresh): $in_fresh"
printf "Input tokens (cached): %'d (%s%% from cache)\n" "$in_cache" "$pct" 2>/dev/null || echo "Input tokens (cached): $in_cache (${pct}% from cache)"
printf "Output tokens: %'d\n" "$out" 2>/dev/null || echo "Output tokens: $out"
echo ""
echo "Higher cache % = lower bill. See GUIDE.md tactic #2 if it's near 0."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment