'use client'
import { useEffect, useState } from 'react'
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table'
import { Check, Circle, Terminal, Lightbulb, Sparkles, TrendingUp } from 'lucide-react'
import type { CommandAnalysis } from '@/lib/commands'
function CategoryBar({ name, used, total, invocations }: {
name: string
used: number
total: number
invocations: number
}) {
const pct = total > 0 ? Math.round((used / total) * 100) : 0
const getColor = (p: number) => {
if (p >= 75) return 'bg-chart-2'
if (p >= 50) return 'bg-chart-1'
if (p >= 25) return 'bg-chart-3'
return 'bg-chart-5'
}
return (
{name}
{used}/{total} commands ({invocations} uses)
)
}
export function CommandUsage() {
const [analysis, setAnalysis] = useState(null)
const [loading, setLoading] = useState(true)
const [filter, setFilter] = useState<'all' | 'used' | 'unused'>('all')
useEffect(() => {
async function load() {
try {
const res = await fetch('/api/commands')
const data = await res.json()
setAnalysis(data)
} catch (e) {
console.error('Failed to load command analysis:', e)
} finally {
setLoading(false)
}
}
load()
}, [])
if (loading) {
return (
Loading command usage...
)
}
if (!analysis) {
return (
Failed to load command analysis
)
}
const filteredCommands = analysis.commands.filter(cmd => {
if (filter === 'used') return cmd.used
if (filter === 'unused') return !cmd.used
return true
})
// Pick top unused recommendations
const recommendations = analysis.commands
.filter(c => !c.used)
.filter(c => [
'/compact', '/diff', '/context', '/btw', '/branch', '/export',
'/plan', '/stats', '/insights', '/security-review', '/doctor',
'/cost', '/memory', '/hooks', '/keybindings',
].includes(c.command))
.slice(0, 8)
return (
{/* Overview cards */}
Built-in Commands
{analysis.totalCommands}
Commands Used
{analysis.usedCommands}
Usage Rate
{analysis.usagePercentage}%
Total Invocations
{analysis.totalInvocations}
{/* Category breakdown */}
Coverage by Category
How many commands you've used in each category
{Object.entries(analysis.categories)
.sort(([, a], [, b]) => b.invocations - a.invocations)
.map(([name, stats]) => (
))}
{/* Recommendations */}
{recommendations.length > 0 && (
Recommended Commands to Try
Useful commands you haven't used yet
{recommendations.map(cmd => (
{cmd.command}
{cmd.description}
))}
)}
{/* Custom commands (skills/plugins) */}
{analysis.customCommands.length > 0 && (
Custom Commands (Skills & Plugins)
Non-built-in commands you've used — these come from installed skills and plugins
{analysis.customCommands.map(({ command, count }) => (
{command}
{count}x
))}
)}
{/* Full command table */}
All Commands
Complete list of built-in Claude Code commands
{(['all', 'used', 'unused'] as const).map(f => (
))}
Command
Description
Category
Uses
{filteredCommands.map(cmd => (
{cmd.used ? (
) : (
)}
{cmd.command}
{cmd.aliases && cmd.aliases.length > 0 && (
({cmd.aliases.join(', ')})
)}
{cmd.description}
{cmd.category}
{cmd.count > 0 ? cmd.count : '–'}
))}
)
}