Skip to content

Latest commit

Β 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hindsight

AI Tool Usage Analyzer & Workflow Optimizer

Hindsight analyzes your AI tool usage and shell history to identify patterns and suggest concrete optimizations. Learn from your actual workflows to improve productivity with MCP servers, custom skills, hooks, and automations.

Python 3.11+ uv License: MIT

Overview

Hindsight analyzes your development workflows to surface optimization opportunities you might otherwise miss. By examining shell history and AI tool interactions, it identifies patterns and generates actionable recommendations.

Supported Data Sources:

  • Shell history via McFly
  • Claude Code sessions (exported using claude-code-exporter)
  • Claude Desktop conversations (exported via Claude Desktop's export feature)
  • Extensible architecture for additional sources

Generated Recommendations:

  • πŸ”Œ MCP Server suggestions - Identify frequently-accessed APIs that could benefit from MCP integration
  • 🎯 Custom Skills - Auto-generate reusable skills from repeated prompt patterns
  • ⚑ Hooks & Automations - Detect command sequences suitable for automation
  • πŸ“ Output Style Preferences - Codify formatting and style preferences
  • πŸ”— Integration Opportunities - Surface gaps where tools could be better connected

Features

πŸ” Pattern Analysis

  • Command frequency analysis by directory and time
  • Sequence detection (common command chains)
  • Error pattern identification
  • AI interaction pattern analysis
  • Cross-tool workflow analysis

πŸ’‘ Smart Recommendations

  • MCP Servers - Ranked by usage frequency
  • Custom Skills - Generated from repeated instructions
  • Hooks - Pre/post command automations
  • Aliases - For frequently used command sequences
  • Style Preferences - Automatic configuration suggestions

πŸ“Š Visual Dashboard

  • Web interface at http://localhost:8000
  • Pattern visualizations
  • Recommendation prioritization
  • Implementation templates
  • Impact tracking

βš™οΈ CLI Commands

# Interactive setup wizard (first-time setup)
uv run hindsight setup

# Run analysis (incremental by default)
uv run hindsight analyze

# Run full analysis (re-analyze all data)
uv run hindsight analyze --full

# Enable AI-powered template generation
uv run hindsight analyze --ai-templates

# Run with verbose error output
uv run hindsight analyze --verbose

# Start web interface
uv run hindsight serve

# Start on custom port
uv run hindsight serve --port 3000

# Monitor data sources for changes (auto-analyze)
uv run hindsight monitor

# Monitor with custom interval (seconds)
uv run hindsight monitor --interval 600

# Discover data sources (optional)
uv run hindsight init

Quick Start

Prerequisites

  • Python 3.11 or higher
  • uv package manager
  • At least one supported data source (see Data Export Guide below)

Installation

# Clone the repository
git clone https://github.com/lcatlett/hindsight.git
cd hindsight

# Run interactive setup wizard
uv run hindsight setup

The setup wizard will:

  • Detect available data sources on your system
  • Configure enabled sources
  • Generate an optimized configuration file
  • Validate paths and permissions
  • Optionally run a sample analysis

Data Export Guide

Before running Hindsight, you'll need to export data from your AI tools:

McFly (Shell History)

  1. Install McFly: cantino/mcfly
  2. Use it for a while to build up command history
  3. Database is automatically created at ~/Library/Application Support/McFly/history.db (macOS)

Claude Code Sessions

  1. Use a GitHub package to export your Claude Code sessions (search for claude-code-exporter)
  2. Export sessions to a directory (e.g., ~/Desktop/sessions)
  3. Configure the path in config/config.yaml:
    claude_code:
      enabled: true
      path: ~/Desktop/sessions

Claude Desktop Conversations

  1. Open Claude Desktop
  2. Use the built-in export feature to export your conversations
  3. Save to a directory (e.g., ~/Desktop/desktop)
  4. Configure the path in config/config.yaml:
    claude_desktop:
      enabled: true
      path: ~/Desktop/desktop

Note: Hindsight analyzes exported data locally. Your conversations and command history never leave your machine.

Usage

# Run analysis on your data
uv run hindsight analyze

# Start the web dashboard
uv run hindsight serve

# Open http://localhost:8000 to view recommendations

Configuration

Configuration is managed in config/config.yaml.

Quick Start:

# Copy the example configuration
cp config/config.example.yaml config/config.yaml

# Edit with your paths
nano config/config.yaml

Or use the interactive setup wizard:

uv run hindsight setup

Complete Configuration Reference

data_sources:
  mcfly:
    enabled: true
    path: ~/Library/Application Support/McFly/history.db
    # Path to McFly SQLite database

  claude_code:
    enabled: true
    path: ~/Desktop/sessions
    # Path to exported Claude Code sessions directory
    # Export using: https://github.com/search?q=claude-code-exporter
    # Set to null for auto-detection from standard locations

  claude_desktop:
    enabled: true
    path: ~/Desktop/desktop
    # Path to exported Claude Desktop conversations directory
    # Export via Claude Desktop's export feature
    # Set to null for auto-detection from standard locations

analysis:
  lookback_days: 30
  # Number of days of history to analyze (default: 30)

  min_sequence_frequency: 3
  # Minimum times a command sequence must appear to be considered (default: 3)

  min_command_frequency: 3
  # Minimum times a command must appear to be considered (default: 3)

  sequence_length: 3
  # Number of commands in a sequence to detect (default: 3)

output:
  database: ~/.hindsight/analytics.db
  # SQLite database path for storing analysis results

  cache_dir: ~/.hindsight/cache
  # Directory for caching intermediate analysis data

recommendations:
  ai_templates:
    enabled: true
    # Enable AI-powered custom template generation (requires ANTHROPIC_API_KEY)

    cache_dir: ~/.hindsight/template_cache
    # Directory for caching AI-generated templates

  min_pattern_confidence: 0.3
  # Minimum confidence score (0.0-1.0) for pattern-based recommendations

  effort_thresholds:
    quick_win: 2
    # Maximum hours for "quick win" effort level

    medium: 8
    # Maximum hours for "medium" effort level

    project: 40
    # Maximum hours for "project" effort level
    # Anything above is considered "epic"

Data Source Setup

McFly:

  • Install from cantino/mcfly
  • Database location is typically ~/Library/Application Support/McFly/history.db (macOS)

Claude Code:

  • Export sessions using a GitHub package like claude-code-exporter
  • Point path to the exported sessions directory
  • Set path: null for auto-detection from ~/Desktop/sessions, ~/Documents/claude-sessions, or ~/.claude/exports/sessions

Claude Desktop:

  • Export conversations via Claude Desktop's built-in export feature
  • Point path to the exported conversations directory
  • Set path: null for auto-detection from ~/Desktop/desktop, ~/Documents/claude-desktop, or ~/.claude/exports/desktop

πŸ“– For complete configuration documentation, see CONFIGURATION.md

How It Works

Analysis Pipeline

# Run analysis on your data
uv run hindsight analyze

The analysis pipeline:

  1. Loads command history and AI sessions from configured sources
  2. Detects patterns, sequences, and error conditions
  3. Generates prioritized recommendations
  4. Stores results in a local SQLite database

Web Dashboard

# Start the web interface
uv run hindsight serve

The dashboard (http://localhost:8000) provides:

  • Prioritized recommendations with impact scores
  • Pattern visualizations and frequency charts
  • Implementation templates for each recommendation
  • Accept/dismiss workflow for tracking actions

Example Output

πŸ” Running Hindsight Analysis...
βœ“ Config loaded
βœ“ Loaded 15,432 commands, 127 sessions

Analyzing patterns...
βœ“ Found 43 frequent commands
βœ“ Found 12 command sequences

Generating recommendations...
βœ“ Generated 8 recommendations

πŸ“Š Top 3 Recommendations:

1. Install GitHub MCP Server (priority: 47.2)
   47 commands could benefit from GitHub MCP integration
   Effort: quick_win, Impact: 8.5/10

2. Automate Git Commit Workflow (priority: 42.8)
   Sequence detected 23 times with 83% consistency
   Effort: quick_win, Impact: 7.0/10

3. Create 'gcp' alias (priority: 38.5)
   Command sequence used 31 times
   Effort: quick_win, Impact: 5.0/10

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Data Ingestion Layer                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  McFly Reader  β”‚  Claude Code  β”‚  Claude Desktop β”‚  Augment β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Pattern Analysis Engine                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Frequency  β”‚  Sequences  β”‚  Errors  β”‚  AI Patterns  β”‚ etc. β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Recommendation Engine                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  MCP Servers  β”‚  Skills  β”‚  Hooks  β”‚  Aliases  β”‚  Styles   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Reporting & Interface (FastAPI + Web)          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

hindsight/
β”œβ”€β”€ src/hindsight/
β”‚   β”œβ”€β”€ readers/          # Data source readers (McFly, Claude Code, Claude Desktop)
β”‚   β”œβ”€β”€ analyzers/        # Pattern detection and analysis
β”‚   β”œβ”€β”€ recommendations/  # Recommendation generation engine
β”‚   β”œβ”€β”€ db/              # Database schema and repositories
β”‚   β”œβ”€β”€ api/             # FastAPI web backend
β”‚   └── cli/             # Command-line interface
β”œβ”€β”€ tests/               # Comprehensive test suite
β”œβ”€β”€ config/              # Configuration files
β”œβ”€β”€ QUICKSTART.md        # Quick start guide
└── README.md            # This file

Development

Running Tests

# Run all tests
uv run pytest tests/ -v

# Run with coverage report
uv run pytest tests/ --cov=src/hindsight --cov-report=html

# Run specific test file
uv run pytest tests/analyzers/test_sequence_detector.py -v

Code Quality

# Linting
uv run ruff check src/

# Type checking
uv run mypy src/

# Formatting
uv run ruff format src/

Extending Hindsight

To add a new data source reader:

  1. Create a new reader class in src/hindsight/readers/
  2. Implement the DataReader interface
  3. Add configuration options to config/config.yaml
  4. Register the reader in the analysis pipeline
  5. Add tests in tests/readers/

See existing readers (McFly, Claude Code) for reference implementations.

FAQ

Q: How do I export my Claude Code sessions? A: Use a GitHub package like claude-code-exporter to export your sessions to a local directory. Point Hindsight to this directory in the configuration.

Q: How do I export my Claude Desktop conversations? A: Use Claude Desktop's built-in export feature to export conversations to a local directory. Configure the path in config/config.yaml.

Q: Do I need all data sources configured? A: No. Hindsight works with any combination of supported data sources. More sources provide richer insights, but the tool is useful with even a single source.

Q: What if I don't have McFly installed? A: Hindsight works without McFly, though it provides the most comprehensive command history data. You can use Claude Code and Claude Desktop sessions alone.

Q: Does this send my data anywhere? A: No. All analysis runs locally. Your command history and AI sessions never leave your machine. Optional AI-powered features (template generation) use the Claude API only when explicitly invoked with --ai-templates.

Q: What's the difference between incremental and full analysis? A: Incremental analysis (default) only processes new data since the last run, making it much faster. Full analysis (--full flag) re-analyzes all data from scratch.

Q: How much disk space does it use? A: Minimal. The SQLite database and cache typically use less than 100MB even with extensive history.

Q: Can I customize the recommendation logic? A: Yes. The recommendation engine is modular and extensible. You can adjust scoring weights, effort thresholds, confidence levels, and other parameters in config/config.yaml.

Q: What's the performance impact? A: Analysis typically completes in seconds to minutes depending on data volume. Incremental analysis is very fast. The web dashboard is lightweight and runs locally.

Q: What does the monitor command do? A: hindsight monitor watches your data sources for changes and automatically runs incremental analysis when new data is detected. Useful for continuous insights.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup

git clone https://github.com/lcatlett/hindsight.git
cd hindsight
uv sync
uv run pytest tests/

License

MIT License - see LICENSE for details.

Acknowledgments

  • Built with FastAPI for the web framework
  • Powered by uv for dependency management
  • Shell history integration via McFly
  • Developed using Claude Code

Ready to optimize your workflow? Get started with the Quick Start guide above.

About

Analyzes your AI tool usage and shell history to identify patterns and suggest concrete optimizations. Learn from your actual workflows to improve productivity with MCP servers, custom skills, hooks, and automations

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages