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
48 changes: 36 additions & 12 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@ Key components:

```bash
make check # Run fmt, lint, test
make install # Install LaunchAgent + CLI
make install # Install LaunchAgent + CLI + MCP config
make uninstall # Remove LaunchAgent + CLI
make restart # Restart LaunchAgent to pick up code changes
make reinstall # pip install -e . + restart (for pyproject.toml changes)
make dev # Run in dev mode with auto-reload
```

### When to restart

The LaunchAgent runs the installed Python code. After making changes, you need to restart for them to take effect:
The install is editable (`pip install -e .`), so Python code changes are picked up automatically by the CLI. The MCP server (LaunchAgent) needs a restart to see changes.

| Change type | Restart needed? |
|-------------|-----------------|
| MCP tools (`server.py`) | Yes - `make restart` |
| Query/pattern logic (`queries.py`, `patterns.py`) | Yes - `make restart` |
| Storage/migrations (`storage.py`) | Yes - `make restart` |
| CLI only (`cli.py`) | No - CLI runs fresh each time |
| Tests | No - pytest runs fresh |
| Documentation (`guide.md`, `CLAUDE.md`) | No |
| Change type | Action needed |
|-------------|---------------|
| MCP tools (`server.py`) | `make restart` |
| Query/pattern logic (`queries.py`, `patterns.py`) | `make restart` |
| Storage/migrations (`storage.py`) | `make restart` |
| CLI only (`cli.py`) | None - CLI runs fresh each time |
| `pyproject.toml` (entry points, deps) | `make reinstall` |
| Tests | None - pytest runs fresh |
| Documentation (`guide.md`, `CLAUDE.md`) | None |

## Key Files

Expand All @@ -67,6 +69,7 @@ The LaunchAgent runs the installed Python code. After making changes, you need t
- **Formatter Registry**: CLI uses `@_register_formatter(predicate)` decorator pattern
- **Schema Migrations**: Use `@migration(version, name)` decorator in storage.py for DB changes
- **Module Imports**: server.py uses `from session_analytics import queries, patterns, ingest`
- **CLI/MCP Parity**: Always expose new query functions on both CLI and MCP. Add MCP tool in `server.py`, CLI command in `cli.py`, document in both `guide.md` and this file

## MCP API Naming Conventions

Expand Down Expand Up @@ -131,6 +134,10 @@ Do this:
| `search_messages` | Full-text search on user messages (FTS5) |
| `get_session_signals` | Raw session metrics for LLM interpretation (RFC #26) |
| `get_session_commits` | Session-commit mappings with timing (RFC #26) |
| `get_file_activity` | File reads/edits/writes with breakdown |
| `get_languages` | Language distribution from file extensions |
| `get_projects` | Activity across all projects |
| `get_mcp_usage` | MCP server and tool usage breakdown |

### Session Discovery and Drill-In Flow

Expand All @@ -151,19 +158,36 @@ All commands support `--json` for machine-readable output:
```bash
session-analytics-cli status # DB stats
session-analytics-cli ingest --days 30 # Refresh data
session-analytics-cli frequency # Tool usage
session-analytics-cli frequency # Tool usage (--no-expand to hide breakdowns)
session-analytics-cli commands --prefix git # Command breakdown
session-analytics-cli sessions # Session info
session-analytics-cli tokens --by model # Token usage
session-analytics-cli sequences # Tool chains
session-analytics-cli sequences # Tool chains (--expand for command-level)
session-analytics-cli permissions # Permission gaps
session-analytics-cli insights # For /improve-workflow
session-analytics-cli journey # User messages across sessions
session-analytics-cli search <query> # Full-text search on messages
session-analytics-cli signals # Raw session signals (RFC #26)
session-analytics-cli session-commits # Session-commit associations (RFC #26)
session-analytics-cli file-activity # File reads/edits/writes
session-analytics-cli languages # Language distribution
session-analytics-cli projects # Cross-project activity
session-analytics-cli mcp-usage # MCP server/tool usage
```

### Expand Flags

The `--expand` flag shows detailed breakdowns for aggregated tools:

| Command | Default | Flag | Effect |
|---------|---------|------|--------|
| `frequency` | Expanded | `--no-expand` | Show Bash/Skill/Task breakdowns (commands, skills, agents) |
| `sequences` | Tool-level | `--expand` | Expand to command/skill/agent level sequences |

**Why different defaults?**
- `frequency` answers "what am I using?" - breakdowns are useful by default
- `sequences` answers "what's my workflow?" - tool-level patterns are clearer by default, command-level is for drilling in

## Integration

### With /improve-workflow
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: check fmt lint test clean install uninstall restart dev venv
.PHONY: check fmt lint test clean install uninstall restart reinstall dev venv

# Run all quality gates (format check, lint, tests)
check: fmt lint test
Expand Down Expand Up @@ -75,6 +75,12 @@ restart:
exit 1; \
fi

# Reinstall: pip install + restart LaunchAgent (picks up code changes)
reinstall: venv
@echo "Reinstalling package..."
.venv/bin/pip install -e .
@$(MAKE) restart

# Uninstall: LaunchAgent + CLI + MCP config
uninstall:
@echo "Uninstalling..."
Expand Down
113 changes: 113 additions & 0 deletions scripts/global-report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash
# Generate a 7-day global analytics report
# Outputs to /tmp/session-analytics-report.md

set -e

OUTPUT="/tmp/session-analytics-report.md"
DAYS=7
CLI="session-analytics-cli"

# Check if CLI is available
if ! command -v "$CLI" &> /dev/null; then
# Try the venv version
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CLI="$SCRIPT_DIR/../.venv/bin/session-analytics-cli"
if [[ ! -x "$CLI" ]]; then
echo "Error: session-analytics-cli not found" >&2
exit 1
fi
fi

echo "Generating $DAYS-day global report..."

{
echo "# Claude Code Session Analytics Report"
echo ""
echo "Generated: $(date '+%Y-%m-%d %H:%M:%S')"
echo "Period: Last $DAYS days"
echo ""

echo "## Status"
echo ""
echo '```'
"$CLI" status
echo '```'
echo ""

echo "## Tool Usage"
echo ""
echo '```'
"$CLI" frequency --days "$DAYS"
echo '```'
echo ""

echo "## Command Breakdown"
echo ""
echo '```'
"$CLI" commands --days "$DAYS"
echo '```'
echo ""

echo "## MCP Server Usage"
echo ""
echo '```'
"$CLI" mcp-usage --days "$DAYS"
echo '```'
echo ""

echo "## Language Distribution"
echo ""
echo '```'
"$CLI" languages --days "$DAYS"
echo '```'
echo ""

echo "## Project Activity"
echo ""
echo '```'
"$CLI" projects --days "$DAYS"
echo '```'
echo ""

echo "## File Activity (Top 20, worktrees collapsed)"
echo ""
echo '```'
"$CLI" file-activity --days "$DAYS" --limit 20 --collapse-worktrees
echo '```'
echo ""

echo "## Tool Sequences"
echo ""
echo '```'
"$CLI" sequences --days "$DAYS" --min-count 5
echo '```'
echo ""

echo "## Token Usage by Day"
echo ""
echo '```'
"$CLI" tokens --days "$DAYS" --by day
echo '```'
echo ""

echo "## Session Overview"
echo ""
echo '```'
"$CLI" sessions --days "$DAYS"
echo '```'
echo ""

echo "## Permission Gaps"
echo ""
echo '```'
"$CLI" permissions --days "$DAYS" --min-count 3
echo '```'
echo ""

} > "$OUTPUT"

echo "Report saved to: $OUTPUT"
echo ""
echo "View with: cat $OUTPUT"
echo "Or open in browser: open $OUTPUT"
Loading