Add comprehensive hook installation system and update documentation
Major Features Added: • Automated hook installation scripts (install-hooks.sh and setup-hooks) • User-scope installation with automatic domain configuration • 7 pre-configured hook profiles for different user types • Comprehensive documentation updates across all guides Hook Installation System: • ./setup-hooks - One-liner installation for most users • ./install-hooks.sh - Full-featured installer with profile selection • Automatic domain replacement using $DOMAIN environment variable • Settings backup and verification capabilities • Safe uninstallation with rollback support Documentation Enhancements: • Updated README.md with complete project overview and proper git repository URL • Enhanced Getting Started guide with automated hook installation • Improved Docker deployment guide with hook installation step • Reorganized documentation index with better visual hierarchy • Added repository URL: https://git.supported.systems/claude/claude-code-tracker.git Technical Improvements: • Rebuilt Docker containers with all latest changes • Verified application health and functionality • Updated all installation examples with correct repository URL • Improved quick start workflow with 3-step visual process 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
50c80596d0
commit
1e1d4a995d
194
HOOKS.md
Normal file
194
HOOKS.md
Normal file
@ -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.
|
347
README.md
347
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
|
### 🎯 **Core Functionality**
|
||||||
Essential hooks for basic session and tool tracking.
|
- **Automatic Session Tracking** - Real-time monitoring of Claude Code sessions
|
||||||
- Session management
|
- **Conversation History** - Complete searchable archive of your interactions
|
||||||
- Tool calls
|
- **Project Analytics** - Detailed insights per project with timelines and statistics
|
||||||
- File modifications
|
- **File Upload Import** - Easy .claude.json file import with preview functionality
|
||||||
- Conversations
|
- **Hook Integration** - 39+ hooks for comprehensive activity tracking
|
||||||
|
|
||||||
### comprehensive.json
|
### 🐳 **Deployment & Installation**
|
||||||
Complete hook setup with all available hook types.
|
- **Docker Ready** - Production-ready containerization with Caddy integration
|
||||||
- All performance monitoring
|
- **One-Click Setup** - Automated hook installation with `./setup-hooks`
|
||||||
- Code quality tracking
|
- **Multiple Profiles** - 7 pre-configured hook profiles for different use cases
|
||||||
- Learning analytics
|
- **User-Scope Installation** - Safe, reversible installation process
|
||||||
- Collaboration insights
|
|
||||||
- Project intelligence
|
|
||||||
|
|
||||||
### essential.json
|
### 📊 **Analytics & Insights**
|
||||||
Minimal setup for core functionality.
|
- **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
|
### 🔒 **Privacy & Security**
|
||||||
Focused on development workflow and code quality.
|
- **Local Data** - All data stays on your server, no external dependencies
|
||||||
- Essential hooks
|
- **HTTPS Support** - Secure communication with automatic SSL via Caddy
|
||||||
- Performance monitoring
|
- **User Control** - Complete control over data collection and retention
|
||||||
- Code quality checks
|
|
||||||
|
|
||||||
### power_user.json
|
## 📦 Quick Start
|
||||||
Advanced setup for productivity optimization.
|
|
||||||
- Essential hooks
|
|
||||||
- Performance tracking
|
|
||||||
- Workflow analysis
|
|
||||||
- Project intelligence
|
|
||||||
|
|
||||||
### research.json
|
### Option 1: Docker Deployment (Recommended)
|
||||||
Optimized for learning and exploration.
|
|
||||||
- Essential hooks
|
|
||||||
- Learning tracking
|
|
||||||
- External resource usage
|
|
||||||
- Knowledge gap analysis
|
|
||||||
|
|
||||||
### team.json
|
```bash
|
||||||
Team-focused configuration for collaboration.
|
# 1. Clone and configure
|
||||||
- Essential hooks
|
git clone https://git.supported.systems/claude/claude-code-tracker.git claude-tracker
|
||||||
- Collaboration tracking
|
cd claude-tracker
|
||||||
- Testing workflows
|
cp .env.example .env
|
||||||
- Project intelligence
|
# Edit .env with your domain
|
||||||
|
|
||||||
## Installation
|
# 2. Deploy with Docker
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
1. Choose the configuration that matches your needs
|
# 3. Install hooks on your development machine
|
||||||
2. Copy the JSON content to your Claude Code settings file:
|
export DOMAIN=your-domain.com
|
||||||
- macOS/Linux: `~/.config/claude/settings.json`
|
./setup-hooks
|
||||||
- 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!
|
|
||||||
|
|
||||||
## Available Hook Variables
|
# 4. Start using Claude Code!
|
||||||
|
```
|
||||||
|
|
||||||
Each hook can use these variables that Claude Code provides:
|
### Option 2: Local Development
|
||||||
|
|
||||||
### Session Variables
|
```bash
|
||||||
- `$SESSION_ID` - Current session identifier
|
# 1. Install dependencies
|
||||||
- `$TIMESTAMP` - Current timestamp (ISO format)
|
pip install -r requirements.txt
|
||||||
- `$PWD` - Current working directory
|
|
||||||
- `$USER` - System username
|
|
||||||
|
|
||||||
### Tool Variables
|
# 2. Initialize database
|
||||||
- `$TOOL_NAME` - Name of tool being called
|
python init_db.py
|
||||||
- `$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
|
|
||||||
|
|
||||||
### File Variables
|
# 3. Start the server
|
||||||
- `$FILE_PATH` - Path to modified file
|
python main.py
|
||||||
- `$ACTION` - File action (created/modified/deleted)
|
|
||||||
- `$FILE_SIZE_MB` - File size in megabytes
|
|
||||||
|
|
||||||
### Context Variables
|
# 4. Install hooks
|
||||||
- `$CONTENT` - Conversation content
|
export DOMAIN=localhost:8000
|
||||||
- `$CONTEXT` - Current context description
|
./setup-hooks
|
||||||
- `$SEARCH_QUERY` - What you're searching for
|
```
|
||||||
- `$NEW_PROJECT` - Project being switched to
|
|
||||||
- `$OLD_PROJECT` - Project being switched from
|
|
||||||
|
|
||||||
### Performance Variables
|
## 🛠️ Installation Scripts
|
||||||
- `$MEMORY_MB` - Memory usage in MB
|
|
||||||
- `$DURATION_MS` - Duration in milliseconds
|
|
||||||
- `$THRESHOLD_EXCEEDED` - Boolean for threshold alerts
|
|
||||||
|
|
||||||
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:
|
# Install specific profile
|
||||||
1. Adding/removing specific hooks
|
./install-hooks.sh comprehensive
|
||||||
2. Changing API endpoints or ports
|
./install-hooks.sh developer
|
||||||
3. Adjusting timeout and retry settings
|
./install-hooks.sh basic
|
||||||
4. Adding custom metadata to hook calls
|
|
||||||
|
|
||||||
## Troubleshooting
|
# Custom domain
|
||||||
|
./install-hooks.sh -d your-domain.com comprehensive
|
||||||
|
|
||||||
If hooks aren't working:
|
# Verify installation
|
||||||
1. Ensure Claude Code Tracker server is running
|
./install-hooks.sh --verify
|
||||||
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
|
|
||||||
|
|
||||||
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**
|
@ -39,7 +39,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<pre><code class="language-bash"># Clone the repository
|
<pre><code class="language-bash"># 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
|
cd claude-tracker
|
||||||
|
|
||||||
# Copy environment template
|
# Copy environment template
|
||||||
@ -80,6 +80,28 @@ docker-compose logs -f
|
|||||||
docker-compose ps</code></pre>
|
docker-compose ps</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header bg-success text-white">
|
||||||
|
<h5 class="mb-0">4. Install Claude Code Hooks</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p>After deployment, install hooks on your development machine to enable automatic tracking:</p>
|
||||||
|
<pre><code class="language-bash"># Install hooks using the same domain from your .env file
|
||||||
|
export DOMAIN=claude.l.supported.systems
|
||||||
|
./setup-hooks</code></pre>
|
||||||
|
|
||||||
|
<div class="alert alert-info mt-3">
|
||||||
|
<i class="fas fa-info-circle me-1"></i>
|
||||||
|
<strong>Note:</strong> Hooks are installed on your local development machine, not in the Docker container. This allows Claude Code to send data to your deployed tracker.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert alert-success">
|
||||||
|
<i class="fas fa-check me-1"></i>
|
||||||
|
<strong>Complete Setup:</strong> Your tracker is now deployed and ready to receive data from Claude Code!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<!-- Docker Configuration -->
|
<!-- Docker Configuration -->
|
||||||
|
@ -102,20 +102,21 @@
|
|||||||
<p class="text-muted mb-3">Set up hooks to automatically track new sessions and conversations in real-time.</p>
|
<p class="text-muted mb-3">Set up hooks to automatically track new sessions and conversations in real-time.</p>
|
||||||
|
|
||||||
<div class="bg-light p-3 rounded mb-3">
|
<div class="bg-light p-3 rounded mb-3">
|
||||||
<h6><i class="fas fa-code me-2"></i>Hook Configuration:</h6>
|
<h6><i class="fas fa-magic me-2"></i>Automatic Installation (Recommended):</h6>
|
||||||
<p class="mb-2">Add this configuration to your Claude Code settings:</p>
|
<p class="mb-2">Use our automated installer for easy setup:</p>
|
||||||
<pre class="bg-dark text-light p-3 rounded"><code>{
|
<pre class="bg-dark text-light p-3 rounded"><code># Set your domain and install hooks
|
||||||
"hooks": {
|
export DOMAIN=your-domain.com
|
||||||
"session_start": "curl -X POST http://localhost:8000/api/sessions/start",
|
./setup-hooks</code></pre>
|
||||||
"session_end": "curl -X POST http://localhost:8000/api/sessions/end",
|
|
||||||
"conversation_update": "curl -X POST http://localhost:8000/api/conversations"
|
<div class="alert alert-success mt-2 mb-0">
|
||||||
}
|
<i class="fas fa-rocket me-1"></i>
|
||||||
}</code></pre>
|
<strong>New:</strong> Automatic hook installer with 7+ pre-configured profiles available!
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="alert alert-warning mb-0">
|
<div class="alert alert-info mb-0">
|
||||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
<i class="fas fa-info-circle me-2"></i>
|
||||||
<strong>Note:</strong> Detailed hook setup instructions are available in the <a href="/dashboard/docs/hook-setup">Hook Setup Guide</a>.
|
<strong>Alternative Methods:</strong> Manual configuration and detailed setup instructions are available in the <a href="/dashboard/docs/hook-setup">Hook Setup Guide</a>.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -95,10 +95,87 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Setup Instructions -->
|
<!-- Automatic Installation -->
|
||||||
<div class="card border-0 shadow-sm mb-4">
|
<div class="card border-0 shadow-sm mb-4">
|
||||||
<div class="card-header bg-success text-white">
|
<div class="card-header bg-success text-white">
|
||||||
<h3 class="mb-0"><i class="fas fa-wrench me-2"></i>Setup Instructions</h3>
|
<h3 class="mb-0"><i class="fas fa-magic me-2"></i>Automatic Installation (Recommended)</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p>The easiest way to set up hooks is using our automated installation script that configures everything for you.</p>
|
||||||
|
|
||||||
|
<div class="alert alert-success">
|
||||||
|
<h5><i class="fas fa-rocket me-1"></i>Quick Setup</h5>
|
||||||
|
<p class="mb-2">For most users, this one-liner will set up everything you need:</p>
|
||||||
|
<pre class="bg-dark text-light p-3 rounded"><code># Set your domain and run the installer
|
||||||
|
export DOMAIN=claude.l.supported.systems
|
||||||
|
./setup-hooks</code></pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h5 class="mt-4"><i class="fas fa-cog me-2"></i>Installation Options</h5>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card bg-light">
|
||||||
|
<div class="card-header">
|
||||||
|
<strong>Basic Installation</strong>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<pre><code># Install basic hook set
|
||||||
|
./install-hooks.sh basic</code></pre>
|
||||||
|
<p class="small text-muted mb-0">Includes essential session and conversation tracking</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card bg-light">
|
||||||
|
<div class="card-header">
|
||||||
|
<strong>Comprehensive Installation</strong>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<pre><code># Install all available hooks
|
||||||
|
./install-hooks.sh comprehensive</code></pre>
|
||||||
|
<p class="small text-muted mb-0">Includes all 39+ hooks for complete tracking</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h5 class="mt-4"><i class="fas fa-list me-2"></i>Available Profiles</h5>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<ul class="list-unstyled">
|
||||||
|
<li class="mb-2"><span class="badge bg-primary me-2">basic</span>Essential hooks only</li>
|
||||||
|
<li class="mb-2"><span class="badge bg-success me-2">essential</span>Core development tracking</li>
|
||||||
|
<li class="mb-2"><span class="badge bg-info me-2">comprehensive</span>All available hooks</li>
|
||||||
|
<li class="mb-2"><span class="badge bg-warning me-2">developer</span>For active developers</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<ul class="list-unstyled">
|
||||||
|
<li class="mb-2"><span class="badge bg-secondary me-2">power_user</span>Advanced tracking features</li>
|
||||||
|
<li class="mb-2"><span class="badge bg-dark me-2">research</span>Research and analytics focused</li>
|
||||||
|
<li class="mb-2"><span class="badge bg-purple me-2">team</span>Team collaboration features</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert alert-info mt-3">
|
||||||
|
<h6><i class="fas fa-terminal me-1"></i>Script Commands</h6>
|
||||||
|
<ul class="mb-0">
|
||||||
|
<li><code>./install-hooks.sh --list</code> - List available profiles</li>
|
||||||
|
<li><code>./install-hooks.sh --verify</code> - Verify installation</li>
|
||||||
|
<li><code>./install-hooks.sh --uninstall</code> - Remove all hooks</li>
|
||||||
|
<li><code>./install-hooks.sh --help</code> - Show detailed help</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Manual Setup Instructions -->
|
||||||
|
<div class="card border-0 shadow-sm mb-4">
|
||||||
|
<div class="card-header bg-warning text-dark">
|
||||||
|
<h3 class="mb-0"><i class="fas fa-wrench me-2"></i>Manual Setup Instructions</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<!-- Step 1: Ensure Server Running -->
|
<!-- Step 1: Ensure Server Running -->
|
||||||
|
@ -181,37 +181,67 @@
|
|||||||
<div class="row mt-5">
|
<div class="row mt-5">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="card border-0 shadow-sm">
|
<div class="card border-0 shadow-sm">
|
||||||
<div class="card-header bg-light">
|
<div class="card-header bg-success text-white">
|
||||||
<h4 class="mb-0"><i class="fas fa-lightning-bolt me-2"></i>Quick Start</h4>
|
<h4 class="mb-0"><i class="fas fa-rocket me-2"></i>Quick Start - Get Running in 3 Steps</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<p class="lead">Get started with Claude Code Tracker in just a few steps:</p>
|
<p class="lead">Get started with Claude Code Tracker in just a few minutes:</p>
|
||||||
<ol class="list-unstyled">
|
|
||||||
<li class="mb-2">
|
<div class="row">
|
||||||
<span class="badge bg-primary rounded-pill me-2">1</span>
|
<div class="col-lg-4 mb-3">
|
||||||
<strong>Import existing data</strong> from your <code>~/.claude.json</code> file
|
<div class="card border-primary h-100">
|
||||||
</li>
|
<div class="card-body text-center">
|
||||||
<li class="mb-2">
|
<div class="bg-primary rounded-circle text-white d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 40px; height: 40px;">
|
||||||
<span class="badge bg-primary rounded-pill me-2">2</span>
|
<strong>1</strong>
|
||||||
<strong>Set up hooks</strong> to automatically track new sessions
|
</div>
|
||||||
</li>
|
<h6>Deploy with Docker</h6>
|
||||||
<li class="mb-2">
|
<small class="text-muted">Set up the tracker server using Docker & Caddy</small>
|
||||||
<span class="badge bg-primary rounded-pill me-2">3</span>
|
</div>
|
||||||
<strong>Explore your data</strong> through the dashboard and analytics
|
</div>
|
||||||
</li>
|
</div>
|
||||||
</ol>
|
<div class="col-lg-4 mb-3">
|
||||||
|
<div class="card border-success h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="bg-success rounded-circle text-white d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 40px; height: 40px;">
|
||||||
|
<strong>2</strong>
|
||||||
|
</div>
|
||||||
|
<h6>Import Data</h6>
|
||||||
|
<small class="text-muted">Upload your .claude.json file with file upload</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4 mb-3">
|
||||||
|
<div class="card border-info h-100">
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<div class="bg-info rounded-circle text-white d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 40px; height: 40px;">
|
||||||
|
<strong>3</strong>
|
||||||
|
</div>
|
||||||
|
<h6>Install Hooks</h6>
|
||||||
|
<small class="text-muted">Run ./setup-hooks for automatic tracking</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4 text-center">
|
<div class="col-md-4">
|
||||||
<div class="d-grid gap-2">
|
<div class="d-grid gap-2">
|
||||||
<a href="/dashboard/import" class="btn btn-success btn-lg">
|
<a href="/dashboard/docs/docker-deployment" class="btn btn-info btn-lg">
|
||||||
<i class="fas fa-upload me-2"></i>
|
<i class="fab fa-docker me-2"></i>
|
||||||
Import Data Now
|
Docker Setup
|
||||||
|
</a>
|
||||||
|
<a href="/dashboard/import" class="btn btn-success">
|
||||||
|
<i class="fas fa-cloud-upload-alt me-2"></i>
|
||||||
|
Import Data
|
||||||
|
</a>
|
||||||
|
<a href="/dashboard/docs/hook-setup" class="btn btn-warning">
|
||||||
|
<i class="fas fa-magic me-2"></i>
|
||||||
|
Setup Hooks
|
||||||
</a>
|
</a>
|
||||||
<a href="/dashboard/docs/getting-started" class="btn btn-outline-primary">
|
<a href="/dashboard/docs/getting-started" class="btn btn-outline-primary">
|
||||||
<i class="fas fa-book me-2"></i>
|
<i class="fas fa-book me-2"></i>
|
||||||
Read Full Guide
|
Full Guide
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
377
install-hooks.sh
Executable file
377
install-hooks.sh
Executable file
@ -0,0 +1,377 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Claude Code Tracker - Hook Installation Script
|
||||||
|
# Automatically installs hooks for Claude Code using domain from environment
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
CLAUDE_CONFIG_DIR="$HOME/.config/claude-code"
|
||||||
|
CLAUDE_SETTINGS_FILE="$CLAUDE_CONFIG_DIR/settings.json"
|
||||||
|
|
||||||
|
# Hook profiles available
|
||||||
|
AVAILABLE_PROFILES=(
|
||||||
|
"basic"
|
||||||
|
"essential"
|
||||||
|
"comprehensive"
|
||||||
|
"developer"
|
||||||
|
"power_user"
|
||||||
|
"research"
|
||||||
|
"team"
|
||||||
|
)
|
||||||
|
|
||||||
|
print_header() {
|
||||||
|
echo -e "${BLUE}╔════════════════════════════════════════╗${NC}"
|
||||||
|
echo -e "${BLUE}║ Claude Code Tracker Hooks ║${NC}"
|
||||||
|
echo -e "${BLUE}║ Installation Script ║${NC}"
|
||||||
|
echo -e "${BLUE}╚════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}✓${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}⚠${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}✗${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_info() {
|
||||||
|
echo -e "${BLUE}ℹ${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_requirements() {
|
||||||
|
print_info "Checking requirements..."
|
||||||
|
|
||||||
|
# Check if Claude Code is installed
|
||||||
|
if ! command -v claude-code &> /dev/null; then
|
||||||
|
print_error "Claude Code is not installed or not in PATH"
|
||||||
|
print_info "Please install Claude Code first: https://claude.ai/code"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if jq is available for JSON manipulation
|
||||||
|
if ! command -v jq &> /dev/null; then
|
||||||
|
print_warning "jq is not installed. Using fallback JSON handling."
|
||||||
|
USE_JQ=false
|
||||||
|
else
|
||||||
|
USE_JQ=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check domain configuration
|
||||||
|
if [[ -z "$DOMAIN" ]]; then
|
||||||
|
# Try to read from .env file
|
||||||
|
if [[ -f "$SCRIPT_DIR/.env" ]]; then
|
||||||
|
source "$SCRIPT_DIR/.env"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$DOMAIN" ]]; then
|
||||||
|
print_error "DOMAIN environment variable is not set"
|
||||||
|
print_info "Please set DOMAIN environment variable or create .env file"
|
||||||
|
print_info "Example: export DOMAIN=claude.l.supported.systems"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "Domain configured: $DOMAIN"
|
||||||
|
print_success "Requirements check passed"
|
||||||
|
}
|
||||||
|
|
||||||
|
create_claude_config_dir() {
|
||||||
|
if [[ ! -d "$CLAUDE_CONFIG_DIR" ]]; then
|
||||||
|
print_info "Creating Claude Code configuration directory..."
|
||||||
|
mkdir -p "$CLAUDE_CONFIG_DIR"
|
||||||
|
print_success "Created directory: $CLAUDE_CONFIG_DIR"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
backup_existing_settings() {
|
||||||
|
if [[ -f "$CLAUDE_SETTINGS_FILE" ]]; then
|
||||||
|
local backup_file="${CLAUDE_SETTINGS_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
|
||||||
|
print_info "Backing up existing settings to: $backup_file"
|
||||||
|
cp "$CLAUDE_SETTINGS_FILE" "$backup_file"
|
||||||
|
print_success "Backup created"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_hook_profile_path() {
|
||||||
|
local profile="$1"
|
||||||
|
echo "$SCRIPT_DIR/claude-hooks-${profile}.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
list_available_profiles() {
|
||||||
|
echo -e "${BLUE}Available hook profiles:${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
for profile in "${AVAILABLE_PROFILES[@]}"; do
|
||||||
|
local profile_file
|
||||||
|
profile_file=$(get_hook_profile_path "$profile")
|
||||||
|
|
||||||
|
if [[ -f "$profile_file" ]]; then
|
||||||
|
local description
|
||||||
|
if [[ "$USE_JQ" == true ]]; then
|
||||||
|
description=$(jq -r '.metadata.description // "No description available"' "$profile_file" 2>/dev/null || echo "No description available")
|
||||||
|
else
|
||||||
|
description="Hook configuration for $profile users"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e " ${GREEN}$profile${NC} - $description"
|
||||||
|
else
|
||||||
|
echo -e " ${RED}$profile${NC} - Profile file not found"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
update_hook_domain() {
|
||||||
|
local input_file="$1"
|
||||||
|
local output_file="$2"
|
||||||
|
|
||||||
|
print_info "Updating hook URLs with domain: $DOMAIN"
|
||||||
|
|
||||||
|
# Replace placeholder domain with actual domain
|
||||||
|
sed "s/\${DOMAIN}/$DOMAIN/g; s/localhost:8000/$DOMAIN/g; s/http:\/\/$DOMAIN/https:\/\/$DOMAIN/g" "$input_file" > "$output_file"
|
||||||
|
|
||||||
|
print_success "Hook URLs updated"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_hooks() {
|
||||||
|
local profile="$1"
|
||||||
|
local profile_file
|
||||||
|
profile_file=$(get_hook_profile_path "$profile")
|
||||||
|
|
||||||
|
if [[ ! -f "$profile_file" ]]; then
|
||||||
|
print_error "Hook profile file not found: $profile_file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_info "Installing hooks from profile: $profile"
|
||||||
|
|
||||||
|
# Create temporary file with updated domain
|
||||||
|
local temp_file="/tmp/claude-hooks-${profile}-$(date +%s).json"
|
||||||
|
update_hook_domain "$profile_file" "$temp_file"
|
||||||
|
|
||||||
|
# Merge with existing settings or create new
|
||||||
|
local final_settings="$temp_file"
|
||||||
|
|
||||||
|
if [[ -f "$CLAUDE_SETTINGS_FILE" ]] && [[ "$USE_JQ" == true ]]; then
|
||||||
|
print_info "Merging with existing Claude Code settings..."
|
||||||
|
|
||||||
|
# Merge hook configurations
|
||||||
|
local merged_file="/tmp/claude-settings-merged-$(date +%s).json"
|
||||||
|
jq -s '.[0] * .[1]' "$CLAUDE_SETTINGS_FILE" "$temp_file" > "$merged_file"
|
||||||
|
final_settings="$merged_file"
|
||||||
|
|
||||||
|
print_success "Settings merged"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install the hooks
|
||||||
|
cp "$final_settings" "$CLAUDE_SETTINGS_FILE"
|
||||||
|
|
||||||
|
# Cleanup temp files
|
||||||
|
rm -f "$temp_file"
|
||||||
|
if [[ -f "$merged_file" ]]; then
|
||||||
|
rm -f "$merged_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "Hooks installed successfully!"
|
||||||
|
}
|
||||||
|
|
||||||
|
show_installation_summary() {
|
||||||
|
local profile="$1"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
|
||||||
|
echo -e "${GREEN}║ Installation Complete! ║${NC}"
|
||||||
|
echo -e "${GREEN}╚════════════════════════════════════════╝${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}Profile installed:${NC} $profile"
|
||||||
|
echo -e "${BLUE}Domain configured:${NC} $DOMAIN"
|
||||||
|
echo -e "${BLUE}Settings file:${NC} $CLAUDE_SETTINGS_FILE"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}Next steps:${NC}"
|
||||||
|
echo "1. Start using Claude Code in any project"
|
||||||
|
echo "2. Visit https://$DOMAIN/dashboard to view your tracking data"
|
||||||
|
echo "3. Check the documentation at https://$DOMAIN/dashboard/docs"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}To test the installation:${NC}"
|
||||||
|
echo " claude-code --help"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_installation() {
|
||||||
|
print_info "Verifying installation..."
|
||||||
|
|
||||||
|
if [[ -f "$CLAUDE_SETTINGS_FILE" ]]; then
|
||||||
|
if [[ "$USE_JQ" == true ]]; then
|
||||||
|
if jq empty "$CLAUDE_SETTINGS_FILE" 2>/dev/null; then
|
||||||
|
print_success "Settings file is valid JSON"
|
||||||
|
|
||||||
|
local hook_count
|
||||||
|
hook_count=$(jq -r '.hooks | length // 0' "$CLAUDE_SETTINGS_FILE" 2>/dev/null || echo "0")
|
||||||
|
print_success "Number of hooks configured: $hook_count"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
print_error "Settings file contains invalid JSON"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_success "Settings file exists"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "Settings file was not created"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
echo "Claude Code Tracker - Hook Installation Script"
|
||||||
|
echo ""
|
||||||
|
echo "Usage: $0 [OPTIONS] [PROFILE]"
|
||||||
|
echo ""
|
||||||
|
echo "PROFILE: Hook profile to install (default: comprehensive)"
|
||||||
|
echo ""
|
||||||
|
echo "Options:"
|
||||||
|
echo " -l, --list List available profiles"
|
||||||
|
echo " -d, --domain DOMAIN Set the domain (overrides DOMAIN env var)"
|
||||||
|
echo " -h, --help Show this help message"
|
||||||
|
echo " --verify Verify existing installation"
|
||||||
|
echo " --uninstall Remove all hooks from settings"
|
||||||
|
echo ""
|
||||||
|
echo "Examples:"
|
||||||
|
echo " $0 # Install comprehensive profile"
|
||||||
|
echo " $0 basic # Install basic profile"
|
||||||
|
echo " $0 -d example.com # Install with custom domain"
|
||||||
|
echo " $0 --list # List available profiles"
|
||||||
|
echo ""
|
||||||
|
echo "Environment Variables:"
|
||||||
|
echo " DOMAIN Target domain for the Claude Code Tracker"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall_hooks() {
|
||||||
|
print_info "Uninstalling Claude Code Tracker hooks..."
|
||||||
|
|
||||||
|
if [[ ! -f "$CLAUDE_SETTINGS_FILE" ]]; then
|
||||||
|
print_warning "No settings file found, nothing to uninstall"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
backup_existing_settings
|
||||||
|
|
||||||
|
if [[ "$USE_JQ" == true ]]; then
|
||||||
|
# Remove hooks section but keep other settings
|
||||||
|
jq 'del(.hooks)' "$CLAUDE_SETTINGS_FILE" > "${CLAUDE_SETTINGS_FILE}.tmp"
|
||||||
|
mv "${CLAUDE_SETTINGS_FILE}.tmp" "$CLAUDE_SETTINGS_FILE"
|
||||||
|
print_success "Hooks removed from settings"
|
||||||
|
else
|
||||||
|
print_warning "Cannot automatically remove hooks without jq. Manual removal required."
|
||||||
|
print_info "Edit $CLAUDE_SETTINGS_FILE and remove the 'hooks' section"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local profile="comprehensive"
|
||||||
|
local list_profiles=false
|
||||||
|
local verify_only=false
|
||||||
|
local uninstall_only=false
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h|--help)
|
||||||
|
show_help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-l|--list)
|
||||||
|
list_profiles=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-d|--domain)
|
||||||
|
DOMAIN="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--verify)
|
||||||
|
verify_only=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--uninstall)
|
||||||
|
uninstall_only=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
print_error "Unknown option: $1"
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
profile="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
print_header
|
||||||
|
|
||||||
|
# Handle special modes
|
||||||
|
if [[ "$list_profiles" == true ]]; then
|
||||||
|
check_requirements
|
||||||
|
list_available_profiles
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$verify_only" == true ]]; then
|
||||||
|
check_requirements
|
||||||
|
verify_installation
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$uninstall_only" == true ]]; then
|
||||||
|
check_requirements
|
||||||
|
create_claude_config_dir
|
||||||
|
uninstall_hooks
|
||||||
|
print_success "Uninstallation complete"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Main installation flow
|
||||||
|
check_requirements
|
||||||
|
create_claude_config_dir
|
||||||
|
backup_existing_settings
|
||||||
|
|
||||||
|
# Validate profile
|
||||||
|
if [[ ! " ${AVAILABLE_PROFILES[@]} " =~ " $profile " ]]; then
|
||||||
|
print_error "Unknown profile: $profile"
|
||||||
|
echo ""
|
||||||
|
list_available_profiles
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install hooks
|
||||||
|
install_hooks "$profile"
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
if verify_installation; then
|
||||||
|
show_installation_summary "$profile"
|
||||||
|
else
|
||||||
|
print_error "Installation verification failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main function with all arguments
|
||||||
|
main "$@"
|
45
setup-hooks
Executable file
45
setup-hooks
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Claude Code Tracker - Quick Hook Setup
|
||||||
|
# Simple wrapper for the full installation script
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
INSTALL_SCRIPT="$SCRIPT_DIR/install-hooks.sh"
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
echo -e "${BLUE}Claude Code Tracker - Quick Hook Setup${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check if install script exists
|
||||||
|
if [[ ! -f "$INSTALL_SCRIPT" ]]; then
|
||||||
|
echo "Error: Installation script not found at $INSTALL_SCRIPT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if domain is set
|
||||||
|
if [[ -z "$DOMAIN" ]]; then
|
||||||
|
if [[ -f "$SCRIPT_DIR/.env" ]]; then
|
||||||
|
source "$SCRIPT_DIR/.env"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$DOMAIN" ]]; then
|
||||||
|
echo "Please set the DOMAIN environment variable first:"
|
||||||
|
echo ""
|
||||||
|
echo " export DOMAIN=your-domain.com"
|
||||||
|
echo " ./setup-hooks"
|
||||||
|
echo ""
|
||||||
|
echo "Or create a .env file with:"
|
||||||
|
echo " DOMAIN=your-domain.com"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}Using domain: $DOMAIN${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Run the installation with comprehensive profile (best for most users)
|
||||||
|
exec "$INSTALL_SCRIPT" comprehensive "$@"
|
Loading…
x
Reference in New Issue
Block a user