Skip to main content Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
直接コマンドでは確認用 Prompt が省略されます。実行前にソースを確認してください。
npx skills add https://github.com/vamseeachanta/workspace-hub --skill usage-trackerコマンドは1行のまま表示されます。コピー前に横へスクロールして全体を確認してください。
ローカルで確認しますか?SkillsMP が現在取得できるファイルをダウンロードできます。
このリポジトリの他の Skills
Write outbound email and external messages in Vamsee Achanta's voice — a subtle offer to help, never bold or rash claims. Load before drafting ANY email, LinkedIn/Collide reply, proposal note, or outreach sent under his name.
Save/publish analysis or computation results from ANY ecosystem repo to Hugging Face as a queryable, viewer-renderable dataset. Use when the user wants to "save results to hugging face", "publish dataset to HF", "hugging face data saving", "save analysis results", "hf dataset", "make results queryable", or "render via datasets-server API". Reshapes nested results into flat parquet tables, writes a dataset card with a viewer `configs:` block and provenance, applies license/public-vs-private routing, enforces a domain data-quality gate (faithful-to-source != correct), publishes to `aceengineer/<repo>-<projection>`, and verifies via the datasets-server API.
Clone, create, fork, configure, and manage GitHub repositories. Manage remotes, secrets, releases, and workflows. Works with gh CLI or falls back to git + GitHub REST API via curl.
| name | usage-tracker |
| version | 1.0.0 |
| description | Track and analyze usage metrics with timestamped logging |
| author | workspace-hub |
| category | bash |
| tags | ["bash","metrics","logging","analytics","tracking","reporting"] |
| platforms | ["linux","macos"] |
Usage Tracker
Patterns for tracking usage metrics, generating reports, and analyzing trends. Extracted from workspace-hub's Claude usage monitoring system.
When to Use This Skill
✅ Use when:
- Need to track tool/resource usage over time
- Generating usage reports (daily, weekly, monthly)
- Monitoring quotas or limits
- Analyzing usage patterns
- Building dashboards
❌ Avoid when:
- Real-time metrics (use proper monitoring tools)
- High-frequency events (>100/second)
- Sensitive data without encryption
Core Capabilities
1. Basic Usage Logging
Pipe-delimited log format for easy parsing:
#!/bin/bash
USAGE_LOG="${HOME}/.workspace-hub/usage.log"
USAGE_DIR="$(dirname "$USAGE_LOG")"
mkdir -p "$USAGE_DIR"
if [[ ! -f "$USAGE_LOG" ]]; then
cat > "$USAGE_LOG" << EOF
# Usage Log
# Format: TIMESTAMP|CATEGORY|ITEM|VALUE|METADATA
# Created: $(date)
EOF
fi
log_usage() {
local category="$1"
local item="$2"
local value="${3:-1}"
local metadata="${4:-}"
local timestamp=$(date '+%Y-%m-%d_%H:%M:%S')
echo "${timestamp}|${category}|${item}|${value}|${metadata}" >> "$USAGE_LOG"
}
log_usage
log_usage
log_usage
log_usage
2. Usage Aggregation
Aggregate usage by time period:
#!/bin/bash
get_usage_period() {
local period="$1"
local category="${2:-}"
local filter_date
case "$period" in
today)
filter_date=$(date +%Y-%m-%d)
;;
week)
filter_date=$(date -d '7 days ago' +%Y-%m-%d)
;;
month)
filter_date=$(date -d '30 days ago' +%Y-%m-%d)
;;
*)
filter_date=$(date +%Y-%m-%d)
;;
esac
if [[ -n "$category" ]]; then
grep "$filter_date" "$USAGE_LOG" 2>/dev/null | grep "|${category}|" || true
else
grep "$filter_date" "$USAGE_LOG" 2>/dev/null || true
fi
}
count_by_category() {
local period="$1"
get_usage_period | \
awk -F | \
-k2 -nr
}
() {
period=
category=
get_usage_period | \
awk -F | \
-k2 -nr
}
() {
period=
category=
get_usage_period | \
awk -F
}
3. Usage Summary Reports
Generate human-readable reports:
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
generate_summary() {
local period="${1:-today}"
local opus_count=$(count_by_item "$period" "model" | grep opus | awk '{print $2}')
local sonnet_count=$(count_by_item "$period" "model" | grep sonnet | awk '{print $2}')
local haiku_count=$(count_by_item "$period" "model" | grep haiku | awk '{print $2}')
opus_count=${opus_count:-0}
sonnet_count=${sonnet_count:-0}
haiku_count=${haiku_count:-0}
local total=$((opus_count + sonnet_count + haiku_count))
if [[ $total -eq 0 ]]; then
echo -e "${YELLOW}No usage recorded for $period${NC}"
return
fi
local opus_pct=$((opus_count * / total))
sonnet_pct=$((sonnet_count * / total))
haiku_pct=$((haiku_count * / total))
-e
-e
-e
-e
-e
-e
-e
[[ -gt 50 ]];
-e
-e
[[ -lt 20 ]];
-e
-e
-e
-e
-e
-e
}
4. Threshold Monitoring
Monitor against limits and thresholds:
#!/bin/bash
declare -A THRESHOLDS=(
["opus_daily"]=50
["sonnet_daily"]=100
["haiku_daily"]=200
["total_daily"]=250
["warning_pct"]=70
["critical_pct"]=90
)
check_threshold() {
local current="$1"
local limit="$2"
local name="$3"
if [[ $limit -eq 0 ]]; then
return 0
fi
local pct=$((current * 100 / limit))
if [[ $pct -ge ${THRESHOLDS[critical_pct]} ]]; then
echo -e "${RED}⚠️ CRITICAL: $name at ${pct}% (${current}/${limit})${NC}"
return 2
elif [[ $pct -ge ${THRESHOLDS[warning_pct]} ]]; then
echo -e "${YELLOW}⚠️ WARNING: at % (/)"
1
-e
0
}
() {
period=
status=0
-e
opus=$(count_by_item | grep opus | awk )
sonnet=$(count_by_item | grep sonnet | awk )
haiku=$(count_by_item | grep haiku | awk )
total=$(( + + ))
check_threshold || status=$?
check_threshold || status=$?
check_threshold || status=$?
check_threshold || status=$?
}
5. Trend Analysis
Analyze usage trends over time:
#!/bin/bash
get_daily_trend() {
local days="${1:-7}"
local category="${2:-}"
for i in $(seq $days -1 0); do
local date=$(date -d "$i days ago" +%Y-%m-%d)
local count
if [[ -n "$category" ]]; then
count=$(grep "$date" "$USAGE_LOG" 2>/dev/null | \
grep "|${category}|" | \
awk -F'|' '{sum+=$4} END {print sum+0}')
else
count=$(grep "$date" "$USAGE_LOG" 2>/dev/null | \
awk -F'|' '{sum+=$4} END {print sum+0}')
fi
echo "$date $count"
done
}
moving_average() {
window=
values=()
=0
count=0
val ;
=$((sum + val))
count=$((count + ))
[[ -ge ]];
$((sum / window))
=$((sum - ))
}
() {
days=
max_width=40
max_val=0
-a daily_data
-r count;
daily_data+=()
[[ -gt ]] && max_val=
< <(get_daily_trend )
[[ -eq 0 ]] && max_val=1
entry ;
=
count=
bar_len=$((count * max_width / max_val))
bar=$( | )
}
6. Export and Reporting
Export data for external analysis:
#!/bin/bash
export_csv() {
local period="${1:-week}"
local output="${2:-usage_export.csv}"
echo "timestamp,category,item,value,metadata" > "$output"
get_usage_period "$period" | tr '|' ',' >> "$output"
echo "Exported to $output"
}
export_json() {
local period="${1:-week}"
local output="${2:-usage_export.json}"
echo "[" > "$output"
local first=true
while IFS='|' read -r ts cat item val meta; do
[[ "$ts" =~ ^#.*$ ]] && continue
[[ -z "$ts" ]] && continue
[[ "" == ]] && >>
first=
>> <<
< <(get_usage_period )
>>
}
() {
period=
output=
> <<
i $( 6 -1 0);
=$( -d +%Y-%m-%d)
opus=$(grep | grep | -l)
sonnet=$(grep | grep | -l)
haiku=$(grep | grep | -l)
total=$((opus + sonnet + haiku))
>>
>> <<
}
Complete Example: Usage Monitor CLI
#!/bin/bash
set -e
SCRIPT_NAME="usage-monitor"
USAGE_DIR="${HOME}/.${SCRIPT_NAME}"
USAGE_LOG="$USAGE_DIR/usage.log"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
init() {
mkdir -p "$USAGE_DIR"
[[ -f "$USAGE_LOG" ]] || echo "# Usage Log" > "$USAGE_LOG"
}
log_usage() {
local category="$1"
local item="$2"
local value="${3:-1}"
local metadata="${4:-}"
echo >>
-e
}
() {
period=
today) filter=$( +%Y-%m-%d) ;;
week) filter=$( -d +%Y-%m-%d) ;;
month) filter=$( -d +%Y-%m-%d) ;;
-e
-e
-e
grep 2>/dev/null | \
awk -F | \
-k2 -nr
-e
}
() {
<<
}
init
)
[[ -lt 2 ]] && { ; 1; }
log_usage
;;
summary)
show_summary
;;
check)
check_all_thresholds
;;
)
csv) export_csv ;;
json) export_json ;;
;;
report)
generate_markdown_report
;;
trend)
display_trend_chart
;;
|--|-h)
show_help
;;
*)
show_help
1
;;
Best Practices
- Consistent Log Format - Use pipe-delimited for easy parsing
- Include Timestamps - Always log when events occur
- Add Metadata - Extra context helps debugging
- Rotate Logs - Prevent unbounded growth
- Validate Input - Sanitize before logging
Resources
Version History
- 1.0.0 (2026-01-14): Initial release - extracted from workspace-hub check_claude_usage.sh
"model"
"opus"
"1"
"task:architecture"
"model"
"sonnet"
"1"
"task:implementation"
"api"
"requests"
"100"
"endpoint:/data"
"tokens"
"input"
"2500"
"model:opus"
"$period"
'|'
'{count[$2]+=$4} END {for (c in count) print c, count[c]}'
sort
count_by_item
local
"$1"
local
"$2"
"$period"
"$category"
'|'
'{count[$3]+=$4} END {for (i in count) print i, count[i]}'
sort
get_total
local
"$1"
local
"${2:-}"
"$period"
"$category"
'|'
'{sum+=$4} END {print sum+0}'
100
local
100
local
100
echo
"${CYAN}═══════════════════════════════════════${NC}"
echo
"${CYAN} Usage Summary - ${period}${NC}"
echo
"${CYAN}═══════════════════════════════════════${NC}"
echo
""
echo
" Total tasks: ${BLUE}${total}${NC}"
echo
""
echo
" ${GREEN}Opus:${NC} ${opus_count} tasks (${opus_pct}%)"
echo
" ${BLUE}Sonnet:${NC} ${sonnet_count} tasks (${sonnet_pct}%)"
echo
" ${YELLOW}Haiku:${NC} ${haiku_count} tasks (${haiku_pct}%)"
echo
""
if
$sonnet_pct
then
echo
"${RED}⚠️ High Sonnet usage (${sonnet_pct}%)${NC}"
echo
" Consider shifting tasks to Opus or Haiku"
echo
""
fi
if
$haiku_pct
then
echo
"${YELLOW}ℹ️ Low Haiku usage (${haiku_pct}%)${NC}"
echo
" Opportunity to use Haiku for quick tasks"
echo
""
fi
echo
"${CYAN}═══════════════════════════════════════${NC}"
echo
" ${GREEN}Target Distribution:${NC}"
echo
" Opus: 30% | Sonnet: 40% | Haiku: 30%"
echo
"${CYAN}═══════════════════════════════════════${NC}"
$name
${pct}
${current}
${limit}
${NC}
return
else
echo
"${GREEN}✓ $name: ${pct}% (${current}/${limit})${NC}"
return
fi
check_all_thresholds
local
"${1:-today}"
local
echo
"${CYAN}Checking usage thresholds...${NC}"
echo
""
local
"$period"
"model"
'{print $2}'
local
"$period"
"model"
'{print $2}'
local
"$period"
"model"
'{print $2}'
local
${opus:-0}
${sonnet:-0}
${haiku:-0}
"${opus:-0}"
"${THRESHOLDS[opus_daily]}"
"Opus"
"${sonnet:-0}"
"${THRESHOLDS[sonnet_daily]}"
"Sonnet"
"${haiku:-0}"
"${THRESHOLDS[haiku_daily]}"
"Haiku"
"$total"
"${THRESHOLDS[total_daily]}"
"Total"
return
$status
local
"${1:-3}"
local
"${@:2}"
local
sum
local
for
in
"${values[@]}"
do
sum
1
if
$count
$window
then
echo
sum
${values[$((count - window))]}
fi
done
display_trend_chart
local
"${1:-14}"
local
echo
""
echo
"Usage Trend (Last $days days)"
echo
"────────────────────────────────────────"
local
declare
while
read
date
do
"$date:$count"
$count
$max_val
$count
done
"$days"
$max_val
for
in
"${daily_data[@]}"
do
local
date
"${entry%:*}"
local
"${entry#*:}"
local
local
printf
"%${bar_len}s"
tr
' '
'█'
printf
"%s │%s %d\n"
"${date:5}"
"$bar"
"$count"
done
echo
"────────────────────────────────────────"
$first
"false"
echo
","
"$output"
false
cat
"$output"
EOF
{
"timestamp": "$ts",
"category": "$cat",
"item": "$item",
"value": $val,
"metadata": "$meta"
}
EOF
done
"$period"
echo
"]"
"$output"
echo
"Exported to $output"
generate_markdown_report
local
"${1:-week}"
local
"${2:-usage_report.md}"
cat
"$output"
EOF
# Usage Report - Week of $(date +%Y-%m-%d)
## Summary
$(generate_summary "$period" | sed 's/\x1b\[[0-9;]*m//g')
## Daily Breakdown
| Date | Opus | Sonnet | Haiku | Total |
|------|------|--------|-------|-------|
EOF
for
in
seq
do
local
date
date
"$i days ago"
local
"$date"
"$USAGE_LOG"
"|opus|"
wc
local
"$date"
"$USAGE_LOG"
"|sonnet|"
wc
local
"$date"
"$USAGE_LOG"
"|haiku|"
wc
local
echo
"| $date | $opus | $sonnet | $haiku | $total |"
"$output"
done
cat
"$output"
EOF
## Recommendations
Based on current usage patterns:
$(generate_recommendations)
---
Generated: $(date)
EOF
echo
"Report generated: $output"
"$(date '+%Y-%m-%d_%H:%M:%S')|${category}|${item}|${value}|${metadata}"
"$USAGE_LOG"
echo
"${GREEN}✓ Logged: ${category}/${item} = ${value}${NC}"
show_summary
local
"${1:-today}"
case
"$period"
in
date
date
'7 days ago'
date
'30 days ago'
esac
echo
"${CYAN}═══════════════════════════════════════${NC}"
echo
"${CYAN} Usage Summary - ${period}${NC}"
echo
"${CYAN}═══════════════════════════════════════${NC}"
echo
""
echo
"By Category:"
"$filter"
"$USAGE_LOG"
'|'
'{count[$2]+=$4} END {for (c in count) printf " %-15s %d\n", c, count[c]}'
sort
echo
""
echo
"Total: $(grep "$filter" "$USAGE_LOG" 2>/dev/null | awk -F'|' '{sum+=$4} END {print sum+0}')"
echo
"${CYAN}═══════════════════════════════════════${NC}"
show_help
cat
EOF
Usage: $SCRIPT_NAME <command> [options]
Commands:
log <category> <item> [value] [metadata]
Log a usage event
summary [today|week|month]
Show usage summary
check
Check against thresholds
export <csv|json> [filename]
Export usage data
report [filename]
Generate markdown report
trend [days]
Show usage trend chart
Examples:
$SCRIPT_NAME log model opus 1 "task:architecture"
$SCRIPT_NAME summary week
$SCRIPT_NAME export csv usage.csv
$SCRIPT_NAME trend 14
EOF
case
"${1:-}"
in
log
shift
$#
echo
"Usage: $0 log <category> <item> [value] [metadata]"
exit
"$@"
"${2:-today}"
"${2:-today}"
export
case
"${2:-csv}"
in
"${3:-week}"
"${4:-usage_export.csv}"
"${3:-week}"
"${4:-usage_export.json}"
esac
"${2:-week}"
"${3:-usage_report.md}"
"${2:-14}"
help
help
exit
esac