<!-- description: Show codebase statistics - lines of code, token usage, feature velocity -->
# aigon-stats

Show codebase and development statistics for the current project.

## Usage

```bash
aigon stats              # Full report
aigon stats --loc        # Lines of code only
aigon stats --tokens     # Token usage only
aigon stats --velocity   # Feature velocity only
aigon stats --oneliner   # One-line summary
```

## What to do

### Lines of Code (LOC)

Count lines in the current project, broken down by category. Exclude `node_modules`, `.next`, `dist`, `build`, `.git`, and lock files.

```bash
# Application code (TS/JS/TSX/JSX)
find . -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \) \
  -not -path "*/node_modules/*" -not -path "*/.next/*" -not -path "*/dist/*" -not -path "*/build/*" \
  -not -path "*/.git/*" -not -name "*.test.*" -not -name "*.spec.*" \
  | xargs wc -l 2>/dev/null | tail -1

# Tests
find . -type f \( -name "*.test.*" -o -name "*.spec.*" \) \
  -not -path "*/node_modules/*" \
  | xargs wc -l 2>/dev/null | tail -1

# Styles (CSS/SCSS)
find . -type f \( -name "*.css" -o -name "*.scss" \) \
  -not -path "*/node_modules/*" \
  | xargs wc -l 2>/dev/null | tail -1

# Markdown/Docs
find . -type f -name "*.md" -not -path "*/node_modules/*" \
  | xargs wc -l 2>/dev/null | tail -1
```

Break down application code by top-level directory, showing lines per directory.

### Token Usage

Read Claude Code's session metadata to estimate token usage for this project:

```bash
# Find sessions for this project
PROJECT_PATH=$(pwd)
ls ~/.claude/usage-data/session-meta/*.json 2>/dev/null | head -5
```

For each session JSON in `~/.claude/usage-data/session-meta/`, check if `projectPath` matches the current project. Sum up:
- `inputTokens` — tokens sent to the model
- `outputTokens` — tokens generated by the model
- `totalMessages` — conversation turns
- `toolUseCount` — tool calls made

Also check `~/.claude/stats-cache.json` for aggregate model usage data (`tokensByModel`).

Present as:
- Total tokens (input + output) for this project
- Estimated cost (use approximate pricing: Opus ~$15/M input, $75/M output; Sonnet ~$3/M input, $15/M output; Haiku ~$0.25/M input, $1.25/M output)
- Sessions count
- Average tokens per session

### Feature Velocity

Run the aigon analytics to get feature throughput:

```bash
aigon board --features --all 2>/dev/null | head -20
```

Count features in each stage:
- Inbox, Backlog, In-Progress, Evaluation, Done

If the dashboard is running, fetch `/api/analytics` for velocity metrics:
```bash
curl -s http://127.0.0.1:4100/api/analytics 2>/dev/null
```

Report: features completed (7d, 30d), median cycle time, autonomy score.

### One-liner Format

When `--oneliner` is passed, output a single line like:

> **ProjectName** is **X lines of TypeScript** across N files, with Y lines of tests and Z features completed.

## Output Format

Present results in a clean markdown table. Use the project name from `package.json` or directory name. Round large numbers (74,712 → 74.7K).

## Notes

- This command reads files and metadata — it doesn't modify anything
- Token usage data is only available if Claude Code is the agent (other agents don't expose this)
- Feature velocity requires aigon to be initialized in the project
