Feed AGS Claude card from Omarchy agent usage records

Claude-Session: https://claude.ai/code/session_014ADhvRXuiTvrXSbConxUey
This commit is contained in:
2026-08-19 13:55:44 -04:00
parent 2c467cc8cb
commit b126063701
3 changed files with 387 additions and 60 deletions
+17 -27
View File
@@ -1,32 +1,22 @@
#!/bin/bash
PROJECTS_DIR="$HOME/.claude/projects"
TODAY=$(date -u '+%Y-%m-%d')
EMPTY='{"available":false,"tokens":0,"messages":0,"cacheHitPercent":0}'
USAGE_RECORD="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy/agents/usage/claude.json"
MAX_RECORD_AGE_SECONDS=900
EMPTY='{"ready":false}'
if [ ! -d "$PROJECTS_DIR" ]; then
record_is_fresh() {
[ -f "$USAGE_RECORD" ] || return 1
local record_age
record_age=$(( $(date +%s) - $(stat -c %Y "$USAGE_RECORD") ))
[ "$record_age" -lt "$MAX_RECORD_AGE_SECONDS" ]
}
if ! record_is_fresh && command -v omarchy-agent-usage-update &> /dev/null; then
omarchy-agent-usage-update claude >/dev/null 2>&1
fi
if [ -f "$USAGE_RECORD" ]; then
cat "$USAGE_RECORD"
else
echo "$EMPTY"
exit 0
fi
FILES=$(find "$PROJECTS_DIR" -name "*.jsonl" -newermt "$TODAY")
if [ -z "$FILES" ]; then
echo '{"available":true,"tokens":0,"messages":0,"cacheHitPercent":0}'
exit 0
fi
jq -s --arg today "$TODAY" '
[.[] | select(.timestamp != null and (.timestamp | startswith($today)) and .message.usage != null) | .message.usage] as $usages
| ([$usages[] | .input_tokens // 0] | add // 0) as $input
| ([$usages[] | .output_tokens // 0] | add // 0) as $output
| ([$usages[] | .cache_creation_input_tokens // 0] | add // 0) as $cacheCreate
| ([$usages[] | .cache_read_input_tokens // 0] | add // 0) as $cacheRead
| ($input + $cacheCreate + $cacheRead) as $totalInput
| {
available: true,
tokens: ($totalInput + $output),
messages: ($usages | length),
cacheHitPercent: (if $totalInput > 0 then (($cacheRead / $totalInput) * 100) else 0 end)
}
' $FILES 2>/dev/null || echo "$EMPTY"