Install once. Every session auto-logs to your dashboard — project name, token count, cost. Zero work after setup.
Create an API key
Sign up, go to Settings → API Keys, type a name like "Claude Code" and click Create. Copy the key — you only see it once.
Download the hook script
Save the PowerShell script below as C:\Users\YOUR_NAME\.claude\promptcost-hook.ps1 and replace YOUR_API_KEY_HERE with your key.
Add the hook to Claude Code
Open C:\Users\YOUR_NAME\.claude\settings.json and add the hook config below. Replace YOUR_NAME with your Windows username.
Done
Finish your next Claude Code session. When it ends the hook fires automatically and your dashboard updates.
promptcost-hook.ps1
$API_KEY = "YOUR_API_KEY_HERE"
$API_URL = "https://getpromptcost.com/api/ingest"
$inputLines = @()
while ($null -ne ($line = [Console]::In.ReadLine())) { $inputLines += $line }
$hookData = $inputLines -join "" | ConvertFrom-Json
$transcriptPath = $hookData.transcript_path
$cwd = $hookData.cwd
$projectName = Split-Path $cwd -Leaf
$totalInput = 0; $totalOutput = 0; $model = "claude-sonnet-4-6"
if ($transcriptPath -and (Test-Path $transcriptPath)) {
$lines = Get-Content $transcriptPath
foreach ($line in $lines) {
try {
$entry = $line | ConvertFrom-Json -ErrorAction SilentlyContinue
if ($entry -and $entry.type -eq "assistant" -and $entry.message -and $entry.message.usage) {
$inp = $entry.message.usage.input_tokens
$out = $entry.message.usage.output_tokens
if ($inp) { $totalInput += [int]$inp }
if ($out) { $totalOutput += [int]$out }
if ($entry.message.model) { $model = $entry.message.model }
}
} catch {}
}
}
if ($totalInput -eq 0 -and $totalOutput -eq 0) { exit 0 }
$body = "{`"workflow`":`"$projectName`",`"model`":`"$model`",`"input_tokens`":$totalInput,`"output_tokens`":$totalOutput,`"description`":`"Claude Code session`"}"
Invoke-RestMethod -Uri $API_URL -Method POST -Body $body -Headers @{
"Content-Type" = "application/json"
"Authorization" = "Bearer $API_KEY"
} | Out-Null~/.claude/settings.json — add this hook
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "powershell -ExecutionPolicy Bypass -File \"C:\\Users\\YOUR_NAME\\.claude\\promptcost-hook.ps1\""
}
]
}
]
}
}Create an API key
Sign up, go to Settings → API Keys, type a name like "Claude Code" and click Create. Copy the key.
Download and configure the hook
Save the bash script to ~/.claude/promptcost-hook.sh, replace YOUR_API_KEY_HERE, then run: chmod +x ~/.claude/promptcost-hook.sh
Add the hook to Claude Code
Open ~/.claude/settings.json and add the hook config shown below.
Done
Every Claude Code session now logs automatically. Your folder name becomes the workflow name.
~/.claude/promptcost-hook.sh
#!/bin/bash
API_KEY="YOUR_API_KEY_HERE"
API_URL="https://getpromptcost.com/api/ingest"
INPUT=$(cat)
TRANSCRIPT=$(echo "$INPUT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('transcript_path',''))" 2>/dev/null)
CWD=$(echo "$INPUT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('cwd',''))" 2>/dev/null)
PROJECT=$(basename "$CWD")
TOTAL_INPUT=0; TOTAL_OUTPUT=0; MODEL="claude-sonnet-4-6"
if [ -f "$TRANSCRIPT" ]; then
while IFS= read -r line; do
TYPE=$(echo "$line" | python3 -c "import sys,json; print(json.load(sys.stdin).get('type',''))" 2>/dev/null)
if [ "$TYPE" = "assistant" ]; then
INP=$(echo "$line" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('message',{}).get('usage',{}).get('input_tokens',0))" 2>/dev/null)
OUT=$(echo "$line" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('message',{}).get('usage',{}).get('output_tokens',0))" 2>/dev/null)
M=$(echo "$line" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('message',{}).get('model',''))" 2>/dev/null)
TOTAL_INPUT=$((TOTAL_INPUT + ${INP:-0}))
TOTAL_OUTPUT=$((TOTAL_OUTPUT + ${OUT:-0}))
[ -n "$M" ] && MODEL="$M"
fi
done < "$TRANSCRIPT"
fi
[ "$TOTAL_INPUT" -eq 0 ] && [ "$TOTAL_OUTPUT" -eq 0 ] && exit 0
curl -s -X POST "$API_URL" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d "{\"workflow\":\"$PROJECT\",\"model\":\"$MODEL\",\"input_tokens\":$TOTAL_INPUT,\"output_tokens\":$TOTAL_OUTPUT,\"description\":\"Claude Code session\"}"~/.claude/settings.json
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "bash ~/.claude/promptcost-hook.sh"
}
]
}
]
}
}Use the POST /api/ingest endpoint directly after any AI API call. Works in any language.
// After any AI API call, log the usage:
await fetch("https://getpromptcost.com/api/ingest", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
body: JSON.stringify({
workflow: "my-project", // your project name
model: "claude-sonnet-4-6", // model used
input_tokens: response.usage.input_tokens,
output_tokens: response.usage.output_tokens,
description: "optional note" // optional
})
})Pricing is approximate — verify at provider docs.