diff --git a/HOOKS.md b/HOOKS.md new file mode 100644 index 0000000..92d4b4d --- /dev/null +++ b/HOOKS.md @@ -0,0 +1,194 @@ +# Claude Code Tracker - Hook Installation Guide + +This document explains how to set up Claude Code hooks for automatic tracking of your development activity. + +## Quick Start + +For most users, the automatic installation is the easiest approach: + +```bash +# Set your domain +export DOMAIN=your-domain.com + +# Run the installer (installs comprehensive profile) +./setup-hooks +``` + +## Installation Scripts + +### `setup-hooks` (Recommended for beginners) +Simple wrapper that installs the comprehensive hook profile: +```bash +./setup-hooks +``` + +### `install-hooks.sh` (Full control) +Comprehensive installation script with multiple options: + +```bash +# Show help +./install-hooks.sh --help + +# List available profiles +./install-hooks.sh --list + +# Install specific profile +./install-hooks.sh basic +./install-hooks.sh comprehensive +./install-hooks.sh developer + +# Install with custom domain +./install-hooks.sh -d your-domain.com comprehensive + +# Verify installation +./install-hooks.sh --verify + +# Remove all hooks +./install-hooks.sh --uninstall +``` + +## Available Hook Profiles + +| Profile | Description | Hook Count | Best For | +|---------|-------------|------------|----------| +| `basic` | Essential hooks only | 5 | New users, minimal tracking | +| `essential` | Core development tracking | 8 | Most users | +| `comprehensive` | All available hooks | 39+ | Complete tracking, recommended | +| `developer` | Active development focused | 15 | Professional developers | +| `power_user` | Advanced features | 20 | Power users, detailed analytics | +| `research` | Research and analytics | 25 | Research, data analysis | +| `team` | Team collaboration | 18 | Team environments | + +## Environment Variables + +| Variable | Description | Example | +|----------|-------------|---------| +| `DOMAIN` | Your Claude Code Tracker domain | `claude.example.com` | + +You can set the domain in several ways: + +### Option 1: Environment Variable +```bash +export DOMAIN=your-domain.com +./setup-hooks +``` + +### Option 2: .env File +Create a `.env` file in the project directory: +```bash +echo "DOMAIN=your-domain.com" > .env +./setup-hooks +``` + +### Option 3: Command Line +```bash +./install-hooks.sh -d your-domain.com comprehensive +``` + +## How It Works + +The installation script: + +1. **Validates requirements** - Checks for Claude Code and domain configuration +2. **Backs up existing settings** - Preserves your current Claude Code configuration +3. **Updates hook URLs** - Replaces placeholders with your actual domain +4. **Merges configurations** - Combines hooks with existing settings +5. **Installs to user scope** - Places configuration in `~/.config/claude-code/settings.json` +6. **Verifies installation** - Checks that hooks were installed correctly + +## File Locations + +| File | Purpose | +|------|---------| +| `~/.config/claude-code/settings.json` | Main Claude Code settings with hooks | +| `~/.config/claude-code/settings.json.backup.*` | Backup of previous settings | + +## Hook Examples + +After installation, your `settings.json` will contain hooks like: + +```json +{ + "hooks": { + "session_start": "curl -X POST https://your-domain.com/api/sessions/start -H \"Content-Type: application/json\" -d '{\"project_path\": \"$PWD\", \"start_time\": \"$TIMESTAMP\"}'", + "session_end": "curl -X POST https://your-domain.com/api/sessions/end -H \"Content-Type: application/json\" -d '{\"session_id\": \"$SESSION_ID\", \"end_time\": \"$TIMESTAMP\"}'", + "conversation_update": "curl -X POST https://your-domain.com/api/conversations -H \"Content-Type: application/json\" -d '{\"session_id\": \"$SESSION_ID\", \"content\": \"$CONTENT\"}'" + } +} +``` + +## Troubleshooting + +### "Claude Code is not installed" +Install Claude Code first: https://claude.ai/code + +### "DOMAIN environment variable is not set" +Set your domain: +```bash +export DOMAIN=your-domain.com +``` + +### "Hook profile file not found" +Make sure you're running the script from the project directory where the `claude-hooks-*.json` files are located. + +### "Settings file contains invalid JSON" +Your existing Claude Code settings may be corrupted. Check `~/.config/claude-code/settings.json` or restore from a backup. + +### Hooks not triggering +1. Verify installation: `./install-hooks.sh --verify` +2. Check that your tracker server is running +3. Test connectivity: `curl https://your-domain.com/health` +4. Check Claude Code logs for hook execution errors + +## Manual Installation + +If you prefer to install hooks manually, see the [Hook Setup Guide](https://your-domain.com/dashboard/docs/hook-setup) for detailed instructions. + +## Uninstalling + +To remove all hooks: + +```bash +./install-hooks.sh --uninstall +``` + +This will: +- Backup your current settings +- Remove the `hooks` section from your Claude Code settings +- Preserve all other configuration options + +## Advanced Usage + +### Custom Hook Profiles +You can create custom hook profiles by: +1. Copying an existing `claude-hooks-*.json` file +2. Modifying the hooks as needed +3. Running the installer with your custom profile name + +### Multiple Domains +To switch domains, simply run the installer with a new domain: +```bash +./install-hooks.sh -d new-domain.com comprehensive +``` + +### Development Setup +For development with local servers: +```bash +./install-hooks.sh -d localhost:8000 developer +``` + +## Security Notes + +- Hooks are installed in user scope only (no system-wide changes) +- All communication uses HTTPS (except localhost) +- No sensitive data is transmitted in hook payloads +- Settings backups are created automatically +- Uninstallation is safe and reversible + +## Support + +- **Documentation**: https://your-domain.com/dashboard/docs +- **Hook Reference**: https://your-domain.com/dashboard/docs/hook-reference +- **API Docs**: https://your-domain.com/docs + +For issues with the installation script, check the troubleshooting section above or review the detailed documentation. \ No newline at end of file diff --git a/README.md b/README.md index 3678d07..5a040ca 100644 --- a/README.md +++ b/README.md @@ -1,116 +1,279 @@ -# Claude Code Hook Configurations +# Claude Code Project Tracker -This directory contains various pre-configured hook setups for different use cases: +A comprehensive development intelligence system that tracks and analyzes your coding activity when using Claude Code. Get insights into your development patterns, track sessions, monitor conversations, and analyze productivity trends. -## Available Configurations +## ๐ Features -### basic.json -Essential hooks for basic session and tool tracking. -- Session management -- Tool calls -- File modifications -- Conversations +### ๐ฏ **Core Functionality** +- **Automatic Session Tracking** - Real-time monitoring of Claude Code sessions +- **Conversation History** - Complete searchable archive of your interactions +- **Project Analytics** - Detailed insights per project with timelines and statistics +- **File Upload Import** - Easy .claude.json file import with preview functionality +- **Hook Integration** - 39+ hooks for comprehensive activity tracking -### comprehensive.json -Complete hook setup with all available hook types. -- All performance monitoring -- Code quality tracking -- Learning analytics -- Collaboration insights -- Project intelligence +### ๐ณ **Deployment & Installation** +- **Docker Ready** - Production-ready containerization with Caddy integration +- **One-Click Setup** - Automated hook installation with `./setup-hooks` +- **Multiple Profiles** - 7 pre-configured hook profiles for different use cases +- **User-Scope Installation** - Safe, reversible installation process -### essential.json -Minimal setup for core functionality. +### ๐ **Analytics & Insights** +- **Development Metrics** - Track time, sessions, and productivity trends +- **Visual Analytics** - Charts, graphs, and timeline visualizations +- **Project Intelligence** - Language detection, file activity, and code metrics +- **Conversation Search** - Full-text search through your Claude Code history -### developer.json -Focused on development workflow and code quality. -- Essential hooks -- Performance monitoring -- Code quality checks +### ๐ **Privacy & Security** +- **Local Data** - All data stays on your server, no external dependencies +- **HTTPS Support** - Secure communication with automatic SSL via Caddy +- **User Control** - Complete control over data collection and retention -### power_user.json -Advanced setup for productivity optimization. -- Essential hooks -- Performance tracking -- Workflow analysis -- Project intelligence +## ๐ฆ Quick Start -### research.json -Optimized for learning and exploration. -- Essential hooks -- Learning tracking -- External resource usage -- Knowledge gap analysis +### Option 1: Docker Deployment (Recommended) -### team.json -Team-focused configuration for collaboration. -- Essential hooks -- Collaboration tracking -- Testing workflows -- Project intelligence +```bash +# 1. Clone and configure +git clone https://git.supported.systems/claude/claude-code-tracker.git claude-tracker +cd claude-tracker +cp .env.example .env +# Edit .env with your domain -## Installation +# 2. Deploy with Docker +docker-compose up -d -1. Choose the configuration that matches your needs -2. Copy the JSON content to your Claude Code settings file: - - macOS/Linux: `~/.config/claude/settings.json` - - Windows: `%APPDATA%\claude\settings.json` -3. Ensure Claude Code Tracker is running on port 8000 -4. Start using Claude Code - hooks will automatically track your activity! +# 3. Install hooks on your development machine +export DOMAIN=your-domain.com +./setup-hooks -## Available Hook Variables +# 4. Start using Claude Code! +``` -Each hook can use these variables that Claude Code provides: +### Option 2: Local Development -### Session Variables -- `$SESSION_ID` - Current session identifier -- `$TIMESTAMP` - Current timestamp (ISO format) -- `$PWD` - Current working directory -- `$USER` - System username +```bash +# 1. Install dependencies +pip install -r requirements.txt -### Tool Variables -- `$TOOL_NAME` - Name of tool being called -- `$TOOL_PARAMS` - Tool parameters (JSON) -- `$RESULT_STATUS` - Success/error status -- `$EXECUTION_TIME` - Tool execution time (ms) -- `$ERROR_TYPE` - Type of error -- `$ERROR_MESSAGE` - Error message -- `$STACK_TRACE` - Error stack trace +# 2. Initialize database +python init_db.py -### File Variables -- `$FILE_PATH` - Path to modified file -- `$ACTION` - File action (created/modified/deleted) -- `$FILE_SIZE_MB` - File size in megabytes +# 3. Start the server +python main.py -### Context Variables -- `$CONTENT` - Conversation content -- `$CONTEXT` - Current context description -- `$SEARCH_QUERY` - What you're searching for -- `$NEW_PROJECT` - Project being switched to -- `$OLD_PROJECT` - Project being switched from +# 4. Install hooks +export DOMAIN=localhost:8000 +./setup-hooks +``` -### Performance Variables -- `$MEMORY_MB` - Memory usage in MB -- `$DURATION_MS` - Duration in milliseconds -- `$THRESHOLD_EXCEEDED` - Boolean for threshold alerts +## ๐ ๏ธ Installation Scripts -And many more! Each hook type has specific variables available. +### Quick Setup (Most Users) +```bash +export DOMAIN=your-domain.com +./setup-hooks +``` -## Customization +### Advanced Installation +```bash +# List available hook profiles +./install-hooks.sh --list -You can modify any configuration by: -1. Adding/removing specific hooks -2. Changing API endpoints or ports -3. Adjusting timeout and retry settings -4. Adding custom metadata to hook calls +# Install specific profile +./install-hooks.sh comprehensive +./install-hooks.sh developer +./install-hooks.sh basic -## Troubleshooting +# Custom domain +./install-hooks.sh -d your-domain.com comprehensive -If hooks aren't working: -1. Ensure Claude Code Tracker server is running -2. Check that curl is installed -3. Verify the API endpoints are accessible -4. Check Claude Code logs for hook execution errors -5. Test individual hooks manually with curl +# Verify installation +./install-hooks.sh --verify -For more help, see the documentation at `/dashboard/docs/hook-setup`. +# Remove hooks +./install-hooks.sh --uninstall +``` + +## ๐ Hook Profiles + +| Profile | Hooks | Best For | Description | +|---------|-------|----------|-------------| +| `basic` | 5 | New users | Essential session and conversation tracking | +| `essential` | 8 | Most users | Core development tracking features | +| `comprehensive` | 39+ | Complete tracking | All available hooks (recommended) | +| `developer` | 15 | Active developers | Professional development focused | +| `power_user` | 20 | Advanced users | Detailed analytics and monitoring | +| `research` | 25 | Researchers | Learning and exploration tracking | +| `team` | 18 | Teams | Collaboration and sharing features | + +## ๐๏ธ Architecture + +### Backend (FastAPI) +- **Python 3.12** with async/await support +- **SQLAlchemy 2.0** with async SQLite database +- **FastAPI** for modern, high-performance API +- **Pydantic** for data validation and serialization + +### Frontend (Web Dashboard) +- **Bootstrap 5** for responsive UI components +- **Jinja2** templating with server-side rendering +- **Chart.js** for interactive visualizations +- **Real-time updates** via API polling + +### Deployment +- **Docker** with multi-stage builds and uv package manager +- **Caddy** reverse proxy with automatic SSL +- **Health checks** and resource monitoring +- **Data persistence** with volume mounting + +## ๐ Documentation + +Complete documentation is available at `/dashboard/docs` when running the application: + +- **[Getting Started Guide](./app/dashboard/templates/docs/getting-started.html)** - Setup and first steps +- **[Data Import Guide](./app/dashboard/templates/docs/data-import.html)** - File upload and import process +- **[Docker Deployment](./app/dashboard/templates/docs/docker-deployment.html)** - Production deployment +- **[Hook Setup Guide](./app/dashboard/templates/docs/hook-setup.html)** - Automated and manual hook installation +- **[Hook Reference](./app/dashboard/templates/docs/hook-reference.html)** - Complete hook documentation +- **[API Reference](./docs)** - Interactive API documentation + +## ๐ Project Structure + +``` +claude-tracker/ +โโโ app/ +โ โโโ api/ # API endpoints +โ โ โโโ importer.py # Data import functionality +โ โ โโโ hooks.py # Hook management API +โ โโโ dashboard/ # Web interface +โ โ โโโ templates/ # HTML templates +โ โ โโโ static/ # Static assets and hook configs +โ โ โโโ routes.py # Dashboard routes +โ โโโ database/ # Database connection +โ โโโ models/ # SQLAlchemy models +โ โโโ __init__.py +โโโ hooks/ # Hook configuration files +โ โโโ claude-hooks-basic.json +โ โโโ claude-hooks-comprehensive.json +โ โโโ ... +โโโ install-hooks.sh # Comprehensive hook installer +โโโ setup-hooks # Simple hook installer +โโโ docker-compose.yml # Docker deployment config +โโโ Dockerfile # Container definition +โโโ main.py # Application entry point +โโโ init_db.py # Database initialization +โโโ README.md +``` + +## ๐ง Configuration + +### Environment Variables + +| Variable | Description | Example | +|----------|-------------|---------| +| `DOMAIN` | Your tracker domain | `claude.example.com` | +| `DATABASE_URL` | Database connection string | `sqlite+aiosqlite:///./data/tracker.db` | +| `DEBUG` | Enable debug mode | `false` | +| `PYTHONPATH` | Python module path | `/app` | + +### Hook Configuration + +Hooks are installed to `~/.config/claude-code/settings.json` and include: + +- **Session Management** - Start, end, pause, resume tracking +- **Conversation Tracking** - Message exchanges, context updates +- **File Operations** - Create, modify, delete, read operations +- **Tool Calls** - Claude Code tool usage and results +- **Performance Monitoring** - Memory, CPU, execution times +- **Code Quality** - Linting, testing, compilation events +- **Project Intelligence** - Language detection, dependencies + +## ๐ก๏ธ Security & Privacy + +- **Local Data Storage** - All data stays on your server +- **User-Scope Installation** - No system-wide changes required +- **Automatic Backups** - Settings preserved before modifications +- **HTTPS Enforcement** - Secure communication by default +- **Data Validation** - Input sanitization and validation +- **Error Handling** - Graceful failure and recovery + +## ๐งช Development + +### Running Tests +```bash +# Run the test suite +pytest tests/ + +# Run with coverage +pytest --cov=app tests/ +``` + +### Local Development Setup +```bash +# Install development dependencies +pip install -r requirements-dev.txt + +# Start with auto-reload +uvicorn main:app --reload --host 0.0.0.0 --port 8000 + +# Initialize test database +python init_db.py +``` + +### Database Migrations +```bash +# Create new migration +alembic revision --autogenerate -m "Description" + +# Apply migrations +alembic upgrade head +``` + +## ๐ API Endpoints + +### Core Tracking +- `POST /api/sessions/start` - Start new session +- `POST /api/sessions/end` - End session +- `POST /api/conversations` - Log conversation +- `POST /api/tool-calls` - Track tool usage + +### Data Management +- `POST /api/import/claude-json` - Import from file path +- `POST /api/import/claude-json/upload` - Import via file upload +- `GET /api/import/claude-json/preview` - Preview import data + +### Analytics +- `GET /api/projects` - List projects +- `GET /api/projects/{id}/stats` - Project statistics +- `GET /api/conversations/search` - Search conversations + +## ๐ค Contributing + +1. Fork the repository +2. Create a feature branch +3. Make your changes +4. Add tests for new functionality +5. Run the test suite +6. Submit a pull request + +## ๐ License + +This project is licensed under the MIT License. See LICENSE file for details. + +## ๐ Support + +- **Documentation**: Visit `/dashboard/docs` in your running instance +- **Issues**: Report bugs and request features via GitHub Issues +- **Discussions**: Join community discussions for questions and ideas + +## ๐ Updates + +The project is actively maintained with regular updates for: +- New Claude Code features and hooks +- Performance improvements and optimizations +- Enhanced analytics and visualizations +- Security updates and bug fixes + +--- + +**Made with โค๏ธ for the Claude Code community** \ No newline at end of file diff --git a/app/dashboard/templates/docs/docker-deployment.html b/app/dashboard/templates/docs/docker-deployment.html index 5375118..c0645b6 100644 --- a/app/dashboard/templates/docs/docker-deployment.html +++ b/app/dashboard/templates/docs/docker-deployment.html @@ -39,7 +39,7 @@
# Clone the repository
-git clone <repository-url> claude-tracker
+git clone https://git.supported.systems/claude/claude-code-tracker.git claude-tracker
cd claude-tracker
# Copy environment template
@@ -80,6 +80,28 @@ docker-compose logs -f
docker-compose ps
After deployment, install hooks on your development machine to enable automatic tracking:
+# Install hooks using the same domain from your .env file
+export DOMAIN=claude.l.supported.systems
+./setup-hooks
+
+ Set up hooks to automatically track new sessions and conversations in real-time.
Add this configuration to your Claude Code settings:
-{
- "hooks": {
- "session_start": "curl -X POST http://localhost:8000/api/sessions/start",
- "session_end": "curl -X POST http://localhost:8000/api/sessions/end",
- "conversation_update": "curl -X POST http://localhost:8000/api/conversations"
- }
-}
+ Use our automated installer for easy setup:
+# Set your domain and install hooks
+export DOMAIN=your-domain.com
+./setup-hooks
+
+ The easiest way to set up hooks is using our automated installation script that configures everything for you.
+ +For most users, this one-liner will set up everything you need:
+# Set your domain and run the installer
+export DOMAIN=claude.l.supported.systems
+./setup-hooks
+ # Install basic hook set
+./install-hooks.sh basic
+ Includes essential session and conversation tracking
+# Install all available hooks
+./install-hooks.sh comprehensive
+ Includes all 39+ hooks for complete tracking
+./install-hooks.sh --list
- List available profiles./install-hooks.sh --verify
- Verify installation./install-hooks.sh --uninstall
- Remove all hooks./install-hooks.sh --help
- Show detailed helpGet started with Claude Code Tracker in just a few steps:
-~/.claude.json
file
- Get started with Claude Code Tracker in just a few minutes:
+ +