Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .github/workflows/claude-token-usage-analyzer.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions .github/workflows/claude-token-usage-analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ steps:
mkdir -p "$ARTIFACT_DIR"

echo "📥 Downloading token-usage.jsonl artifacts..."
jq -r '.[].databaseId' /tmp/token-analyzer-claude/claude-runs.json 2>/dev/null | head -50 | while read -r run_id; do
jq -r '.[0:50] | .[].databaseId' /tmp/token-analyzer-claude/claude-runs.json > /tmp/token-analyzer-claude/run-ids.txt
while read -r run_id; do
run_dir="$ARTIFACT_DIR/$run_id"
mkdir -p "$run_dir"
gh run download "$run_id" \
--repo "$GITHUB_REPOSITORY" \
--name "firewall-audit-logs" \
--dir "$run_dir" \
2>/dev/null || true
done
done < /tmp/token-analyzer-claude/run-ids.txt

# Count how many token-usage.jsonl files we got
JSONL_COUNT=$(find "$ARTIFACT_DIR" -name "token-usage.jsonl" 2>/dev/null | wc -l)
Expand All @@ -86,14 +87,15 @@ steps:
# Merge all token-usage.jsonl files annotated with run_id
MERGED_FILE="/tmp/token-analyzer-claude/token-usage-merged.jsonl"
> "$MERGED_FILE"
find "$ARTIFACT_DIR" -name "token-usage.jsonl" | while read -r f; do
find "$ARTIFACT_DIR" -name "token-usage.jsonl" > /tmp/token-analyzer-claude/jsonl-files.txt 2>/dev/null || true
while read -r f; do
run_id=$(echo "$f" | grep -oP '(?<=/artifacts/)\d+(?=/)' || true)
while IFS= read -r line; do
if [ -n "$line" ]; then
echo "${line}" | jq --arg run_id "$run_id" '. + {run_id: $run_id}' >> "$MERGED_FILE" 2>/dev/null || true
fi
done < "$f"
done
done < /tmp/token-analyzer-claude/jsonl-files.txt

RECORD_COUNT=$(wc -l < "$MERGED_FILE" 2>/dev/null || echo 0)
echo "✅ Merged ${RECORD_COUNT} token usage records"
Expand Down
Loading
Loading