Skip to main content
This cookbook shows how to use hooks to track Droid usage, collect development metrics, analyze patterns, and generate insights about your development workflow.

How it works

Logging and analytics hooks can:
  1. Track tool usage: Log which tools Droid uses most frequently
  2. Measure performance: Track session duration, command execution time
  3. Analyze patterns: Identify common workflows and bottlenecks
  4. Generate reports: Create usage summaries and insights
  5. Monitor costs: Track token usage and API costs

Prerequisites

Tools for logging and data collection:

Basic logging

Log all commands

Track every command Droid executes. Create .factory/hooks/log-commands.sh:
Add to ~/.factory/hooks.json:
Analyze logs:

Track file modifications

Log all file edits and writes. Create .factory/hooks/track-file-changes.sh:
Query the database:

Session duration tracking

Measure how long sessions last: Create .factory/hooks/track-session.sh:
Add to hooks:
Query session stats:

Advanced analytics

Usage heatmap

Track when Droid is used most: Create .factory/hooks/usage-heatmap.py:
Run periodically:

Tool usage statistics

Track which tools are used most: Create .factory/hooks/tool-stats.sh:
Add to PreToolUse for all tools:
Generate report:

Performance metrics

Track hook execution performance: Create .factory/hooks/perf-monitor.sh:
Analyze performance:

Cost tracking

Monitor token usage and API costs: Create .factory/hooks/track-costs.sh:
Query costs:

Generate weekly reports

Compile usage reports: Create .factory/hooks/weekly-report.py:
Schedule weekly:

Best practices

1

Use structured logging

Log in JSON or to database for easy querying:
2

Minimize performance impact

Keep logging hooks fast:
3

Protect sensitive data

Don’t log secrets or credentials:
4

Rotate logs

Prevent log files from growing too large:
5

Make analytics opt-in

Respect user privacy:

Troubleshooting

Problem: Log files consuming too much disk space Solution: Implement log rotation:
Problem: SQLite database locked during concurrent access Solution: Use WAL mode and retry logic:
Problem: Hooks take too long Solution: Use async logging:

See also