This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Node.js CLI tool for setting up Claude Code configurations and providing real-time analytics. The project uses modern JavaScript/Node.js development practices and includes a comprehensive analytics dashboard with modular architecture.
npm install- Install all dependenciesnpm install --save <package>- Install a production dependencynpm install --save-dev <package>- Install a development dependencynpm update- Update all dependenciesnpm audit- Check for security vulnerabilitiesnpm audit fix- Fix security vulnerabilities
npm start- Run the CLI toolnpm run analytics:start- Start the analytics dashboard servernpm run analytics:test- Run analytics-specific testsnode src/analytics.js- Direct analytics server startup
npm test- Run all tests with Jestnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage reportnpm run test:unit- Run unit tests onlynpm run test:integration- Run integration tests onlynpm run test:e2e- Run end-to-end testsnpm run test:analytics- Run analytics module testsnpm run test:all- Run comprehensive test suite
npm run lint- Run ESLint (if configured)npm run format- Format code (if configured)node --check src/analytics.js- Check syntax
npm run dev:link- Link package for local developmentnpm run dev:unlink- Unlink packagenpm version patch|minor|major- Bump versionnpm publish- Publish to npm registry
# Start the analytics dashboard
npm run analytics:start
# Open browser to http://localhost:3333
# The dashboard provides real-time monitoring of Claude Code sessions- Real-time Session Monitoring - Live tracking of active Claude Code conversations
- Conversation State Detection - "Claude working...", "User typing...", "Awaiting input..."
- Performance Analytics - System health, memory usage, and performance metrics
- WebSocket Integration - Real-time updates without polling
- Export Capabilities - CSV/JSON export of conversation data
- Browser Notifications - Desktop alerts for state changes
The analytics dashboard follows a modular architecture with:
- Backend Modules: StateCalculator, ProcessDetector, ConversationAnalyzer, FileWatcher, DataCache
- Frontend Components: Dashboard, ConversationTable, Charts, Services
- Real-time Communication: WebSocket server with notification management
- Performance Monitoring: Comprehensive metrics and health monitoring
- Testing Framework: Unit, integration, and performance tests
- Node.js - Runtime environment (v14.0.0+)
- Express.js - Web server framework
- WebSocket - Real-time communication (ws library)
- Chokidar - File system watching
- Jest - Testing framework
- Vanilla JavaScript - No framework dependencies for maximum compatibility
- Chart.js - Data visualization
- WebSocket Client - Real-time updates
- CSS3 - Modern styling with responsive design
- fs-extra - Enhanced file system operations
- chalk - Terminal string styling
- boxen - Terminal boxes
- commander - CLI argument parsing
- inquirer - Interactive command line prompts
- commander - Command-line interface framework
- inquirer - Interactive command line prompts
- ora - Terminal spinners
- boxen - Terminal boxes for notifications
- open - Cross-platform file opener
- express - Web server framework
- ws - WebSocket library for real-time communication
- chokidar - File system watcher
- fs-extra - Enhanced file system operations
- chalk - Terminal string styling
- Jest - JavaScript testing framework
- jest-watch-typeahead - Interactive test watching
- Comprehensive test coverage with unit, integration, and performance tests
- ESLint - JavaScript linting (if configured)
- Prettier - Code formatting (if configured)
- Node.js built-in - Syntax checking with
node --check
src/
├── index.js # CLI entry point
├── analytics.js # Analytics dashboard server
├── analytics/ # Analytics modules
│ ├── core/ # Core business logic
│ │ ├── StateCalculator.js
│ │ ├── ProcessDetector.js
│ │ ├── ConversationAnalyzer.js
│ │ └── FileWatcher.js
│ ├── data/ # Data management
│ │ └── DataCache.js
│ ├── notifications/ # Real-time communication
│ │ ├── WebSocketServer.js
│ │ └── NotificationManager.js
│ └── utils/ # Utilities
│ └── PerformanceMonitor.js
├── analytics-web/ # Frontend components
│ ├── index.html # Main dashboard page
│ ├── components/ # UI components
│ ├── services/ # Frontend services
│ └── assets/ # Static assets
├── templates/ # Configuration templates
└── utils/ # CLI utilities
tests/
├── unit/ # Unit tests
├── integration/ # Integration tests
├── e2e/ # End-to-end tests
└── fixtures/ # Test data
- Files/Modules: Use PascalCase for classes (
StateCalculator.js), camelCase for utilities - Classes: Use PascalCase (
StateCalculator) - Functions/Variables: Use camelCase (
getUserData) - Constants: Use UPPER_SNAKE_CASE (
API_BASE_URL) - Private methods: Prefix with underscore (
_privateMethod)
- Use CommonJS modules (
module.exports,require()) - Organize related functionality into classes
- Keep modules focused and single-purpose
- Use dependency injection for testability
- Document public APIs with JSDoc comments
- Use meaningful variable and function names
- Keep functions focused and single-purpose
- Use async/await for asynchronous operations
- Handle errors appropriately with try/catch blocks
- Use console logging with appropriate levels (chalk for styling)
- Use
fs-extrafor enhanced file operations - Prefer
path.join()for cross-platform path handling - Use async/await instead of callbacks where possible
- Handle process signals for graceful shutdown
- Use environment variables for configuration
- Organize tests to mirror source code structure
- Use descriptive test names that explain the behavior
- Follow AAA pattern (Arrange, Act, Assert)
- Use Jest fixtures and mocks for test data
- Group related tests in
describeblocks
- Unit Tests - Test individual modules and functions in isolation
- Integration Tests - Test module interactions and complete workflows
- Performance Tests - Test system performance and memory usage
- E2E Tests - Test complete user scenarios end-to-end
// jest.config.js
module.exports = {
testEnvironment: 'node',
collectCoverageFrom: [
'src/**/*.js',
'!src/**/*.test.js'
],
coverageThreshold: {
global: {
branches: 70,
functions: 70,
lines: 70,
statements: 70
}
}
};- Aim for 70%+ overall test coverage (80%+ for core modules)
- Write unit tests for business logic
- Use integration tests for module interactions
- Mock external dependencies and services
- Test error conditions and edge cases
// Unit test example
describe('StateCalculator', () => {
let stateCalculator;
beforeEach(() => {
stateCalculator = new StateCalculator();
});
it('should detect active state for recent messages', () => {
const messages = [/* test data */];
const lastModified = new Date();
const state = stateCalculator.determineConversationState(messages, lastModified);
expect(state).toBe('active');
});
});# Ensure Node.js 14+ is installed
node --version
# Install dependencies
npm install
# Install development dependencies
npm install --save-dev jest
# Link for local development
npm link- Use
package.jsonfor dependency management - Pin major versions to avoid breaking changes
- Use
npm auditto check for security vulnerabilities - Keep dependencies up to date with
npm update
The analytics dashboard has been refactored into a modular architecture in 4 phases:
- StateCalculator - Conversation state detection logic
- ProcessDetector - Running process detection and correlation
- ConversationAnalyzer - Message parsing and analysis
- FileWatcher - Real-time file system monitoring
- DataCache - Multi-level caching system
- Dashboard - Main component orchestration
- ConversationTable - Interactive conversation display
- Charts - Data visualization components
- StateService - Reactive state management
- DataService - API communication with caching
- WebSocketService - Real-time communication
- WebSocketServer - Server-side WebSocket management
- NotificationManager - Event-driven notifications
- Real-time Updates - Live conversation state changes
- Fallback Mechanisms - Polling when WebSocket unavailable
- Comprehensive Test Suite - Unit, integration, and performance tests
- PerformanceMonitor - System health and metrics tracking
- Memory Management - Automatic cleanup and optimization
- Production Readiness - Performance monitoring and error tracking
NEVER write API keys, tokens, passwords, or any secrets directly in code. This is a non-negotiable rule.
# ❌ WRONG - NEVER DO THIS
API_KEY = "AIzaSy..."
SECRET_TOKEN = "ghp_..."
PASSWORD = "mypassword123"
# ✅ CORRECT - Always use environment variables
import os
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.environ.get("GOOGLE_API_KEY")// ❌ WRONG - NEVER DO THIS
const API_KEY = "AIzaSy...";
// ✅ CORRECT - Always use environment variables
const API_KEY = process.env.GOOGLE_API_KEY;When creating scripts that need API keys:
- Use
os.environ.get()(Python) orprocess.env(Node.js) - Load from
.envfile usingdotenvlibrary - Add the variable name to
.env.examplewith placeholder value - Verify
.envis in.gitignore
If you accidentally commit a secret:
- Revoke the key IMMEDIATELY
- Generate a new key
- Update
.envwith new key - The old key is compromised forever (git history)
- Regularly update dependencies with
npm auditandnpm update - Use
npm auditto check for known vulnerabilities - Pin major versions in package.json to avoid breaking changes
- Use environment variables for sensitive configuration
- Validate input data appropriately
- Use environment variables for API keys and configuration
- Implement proper error handling without exposing sensitive information
- Sanitize file paths and user inputs
- Use HTTPS for production deployments
- Check Node.js version compatibility (14.0.0+)
- Run
npm installto install dependencies - Check syntax with
node --check src/analytics.js - Run initial tests with
npm test
- Use meaningful variable and function names
- Run tests frequently to catch issues early:
npm run test:watch - For frontend changes, let user handle analytics server startup - don't run
npm run analytics:startautomatically - Use meaningful commit messages
- Run full test suite:
npm test - Check syntax:
node --check src/analytics.js - Test analytics functionality:
npm run analytics:test - Ensure no console errors in browser (if testing frontend)
- Run performance tests if available
This CLI tool manages a comprehensive component system for Claude Code configurations:
AI specialists organized by domain expertise:
- Development:
frontend-developer,fullstack-developer,devops-engineer - Security:
security-auditor,penetration-tester,compliance-specialist - Data/AI:
data-scientist,ml-engineer,nlp-engineer - Business:
product-strategist,business-analyst,legal-advisor
Custom slash commands for development workflows:
- Setup:
/setup-ci-cd-pipeline,/setup-testing,/migrate-to-typescript - Performance:
/optimize-bundle,/performance-audit,/add-caching - Testing:
/generate-tests,/setup-e2e,/test-coverage - Documentation:
/update-docs,/generate-api-docs,/create-guide
External service connections:
- Databases:
postgresql-integration,supabase,mysql-integration - Development:
github-integration,context7,filesystem-access - Browser:
playwright-mcp,browsermcp,browser-use-mcp-server
Claude Code configuration files:
- Performance:
performance-optimization,bash-timeouts,mcp-timeouts - Security:
read-only-mode,deny-sensitive-files,allow-git-operations - Statuslines:
context-monitor,git-branch-statusline,time-statusline
Automation triggers for development workflows:
- Git:
auto-git-add,smart-commit,pre-commit-validation - Notifications:
discord-notifications,slack-notifications,telegram-notifications - Performance:
performance-monitor,lint-on-save,test-runner
# Install specific components
npx claude-code-templates@latest --agent <name>
npx claude-code-templates@latest --command <name>
npx claude-code-templates@latest --mcp <name>
npx claude-code-templates@latest --setting <name>
npx claude-code-templates@latest --hook <name>
# Batch installation
npx claude-code-templates@latest --agent security-auditor --command security-audit --setting read-only-mode
# Interactive mode
npx claude-code-templates@latestStatusline System with Python Scripts
- Statuslines can reference external Python scripts
- Files are downloaded automatically to
.claude/scripts/relative to project - Example:
statusline/context-monitorinstalls both JSON config and Python script - Implementation in
src/index.js:installIndividualSetting():
if (settingName.includes('statusline/')) {
const pythonFileName = settingName.split('/')[1] + '.py';
const pythonUrl = githubUrl.replace('.json', '.py');
additionalFiles['.claude/scripts/' + pythonFileName] = {
content: pythonContent,
executable: true
};
}The scripts/generate_components_json.py script creates the component catalog:
- Scans all component directories recursively
- Excludes
.pyfiles from public listings (they remain as background dependencies) - Generates
docs/components.jsonfor the web interface at aitmpl.com - Handles file content embedding and metadata extraction
- Relative Paths: Always use relative paths like
.claude/scripts/for project-local files - Cross-platform: Use
path.join()for cross-platform compatibility - No Hardcoding: Never hardcode user home directories or absolute paths
The statusline context monitor system demonstrates key architectural patterns:
- Component Download: Automatic download of related files (Python scripts)
- Relative Installation: Files installed relative to project, not globally
- Background Dependencies: Python files excluded from public component listings
- Dynamic Loading: Components loaded and executed dynamically by Claude Code
- Use try/catch blocks for async operations
- Log errors with appropriate context using chalk for styling
- Provide helpful error messages to users
- Handle missing files or directories gracefully
- Implement fallback mechanisms for network operations
- Structure: Follow existing directory patterns in
cli-tool/components/ - Naming: Use descriptive, hyphenated names (
security-auditor.md) - Documentation: Include clear descriptions and usage examples
- Testing: Add tests for complex logic components
- Generation: Run
python scripts/generate_components_json.pyto update catalog
- Backward Compatibility: Ensure changes don't break existing installations
- Version Management: Consider version bumping for breaking changes
- Testing: Test component installation with
--setting,--agent, etc. - Documentation: Update component descriptions if functionality changes
# Bump version (automatically updates package.json)
npm version patch # 1.20.2 -> 1.20.3
npm version minor # 1.20.3 -> 1.21.0
npm version major # 1.21.0 -> 2.0.0
# Publish to npm
npm publish- All tests passing (
npm test) - Component catalog updated (
python scripts/generate_components_json.py) - No hardcoded paths or sensitive information
- Version bumped appropriately
- Git commits include all relevant files
- Never include hardcoded credentials or API keys in components
- Validate all user inputs in components
- Use relative paths (
.claude/scripts/) instead of absolute paths - Review components for potential security vulnerabilities before publishing
The /api directory contains Vercel Serverless Functions that power critical infrastructure:
- Component download tracking (Supabase)
- Discord bot interactions
- Claude Code changelog monitoring (Neon Database)
--agent, --command, --mcp, --hook, --skill, and --setting installations.
Purpose: Tracks component downloads for analytics
Method: POST
Request Body:
{
"type": "agent|command|mcp|hook|setting|skill|template",
"name": "component-name",
"path": "components/path",
"category": "category-name",
"cliVersion": "1.0.0"
}Response: 200 OK or 400 Bad Request
Used By: CLI tool (cli-tool/bin/create-claude-config.js) on every component installation
Database: Supabase (component_downloads, download_stats tables)
Purpose: Discord bot slash commands handler
Method: POST
Features:
/search- Search components/info- Component details/install- Installation commands/popular- Most downloaded components/random- Random component discovery
Authentication: Discord signature verification
Purpose: Monitors Claude Code releases and sends Discord notifications
Method: GET (triggered by Vercel Cron every 4 hours)
Features:
- Fetches latest version from NPM
- Parses CHANGELOG.md from GitHub
- Classifies changes (features, fixes, improvements, breaking)
- Sends formatted Discord embeds
- Stores in Neon Database
Database: Neon (claude_code_versions, claude_code_changes, discord_notifications_log)
ALWAYS run tests before deploying:
# 1. Run API tests
cd api
npm test
# 2. Verify critical endpoints
npm run test:api
# 3. If tests pass, deploy
cd ..
vercel --prodThe vercel.json file in project root configures:
{
"buildCommand": "npm run build",
"outputDirectory": "docs",
"crons": [
{
"path": "/api/claude-code-check",
"schedule": "0 */4 * * *"
}
],
"rewrites": [
// Frontend routing...
]
}Important Notes:
- Serverless functions MUST be in
/apiroot or use proper naming (/api/folder/file.js) - ES modules (
type: "module") are supported - Environment variables configured in Vercel Dashboard
- Cron jobs run in production only
Required environment variables in Vercel:
# Supabase (download tracking)
SUPABASE_URL=https://xxx.supabase.co
SUPABASE_SERVICE_ROLE_KEY=xxx
# Neon Database (changelog monitoring)
NEON_DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
# Discord
DISCORD_APP_ID=xxx
DISCORD_BOT_TOKEN=xxx
DISCORD_PUBLIC_KEY=xxx
DISCORD_WEBHOOK_URL_CHANGELOG=https://discord.com/api/webhooks/xxx# Install dependencies
cd api
npm install
# Run all tests
npm test
# Run only critical endpoint tests
npm run test:api
# Watch mode for development
npm run test:watch
# Coverage report
npm run test:coverageapi/
├── __tests__/
│ └── endpoints.test.js # Critical endpoint tests
├── jest.config.cjs # Jest configuration
└── package.json # Test scripts
The test suite validates:
- ✅ All endpoints respond (< 500 status)
- ✅ Download tracking accepts valid component types
- ✅ Invalid data returns 400 errors
- ✅ CORS headers are present
- ✅ Response times are acceptable
- ✅ Correct HTTP method validation
Test Against Production:
# Test production endpoints
API_BASE_URL=https://aitmpl.com npm run test:api
# Test staging
API_BASE_URL=https://staging.aitmpl.com npm run test:apiCause: Vercel Deployment Protection is enabled
Solution:
- Use production domain (
aitmpl.com) instead of preview URLs - Or disable deployment protection for API routes
Cause: Testing against local server that isn't running
Solution:
# Always test against production
API_BASE_URL=https://aitmpl.com npm run test:apiSymptoms: No data in Supabase after component installations
Debug Steps:
- Check Vercel function logs:
vercel logs aitmpl.com --follow - Verify environment variables are set
- Test endpoint manually:
curl -X POST https://aitmpl.com/api/track-download-supabase \ -H "Content-Type: application/json" \ -d '{"type":"agent","name":"test","path":"test/path"}'
- Check Supabase table:
select * from component_downloads order by created_at desc limit 10;
Cause: Incorrect file structure or naming
Solution:
- Functions must be directly in
/api(e.g.,/api/my-function.js) - OR in named folders (e.g.,
/api/my-folder/index.jsbecomes/api/my-folder) - Use
export default async function handler(req, res) {}for ES modules
- Go to https://vercel.com/dashboard
- Select project
aitmpl - Navigate to "Functions" tab
- View real-time logs and metrics
# Real-time logs
vercel logs aitmpl.com --follow
# Filter by function
vercel logs aitmpl.com --follow | grep track-download
# Recent errors
vercel logs aitmpl.com --since 1hSupabase (Download Stats):
-- Recent downloads
SELECT type, name, COUNT(*) as downloads
FROM component_downloads
WHERE download_timestamp > NOW() - INTERVAL '7 days'
GROUP BY type, name
ORDER BY downloads DESC
LIMIT 20;Neon (Claude Code Versions):
-- Latest Claude Code versions
SELECT version, published_at, discord_notified
FROM claude_code_versions
ORDER BY published_at DESC
LIMIT 10;- Always Test Before Deploy: Run
npm run test:apibeforevercel --prod - Monitor Logs: Check Vercel logs after deployment
- Validate Environment Variables: Ensure all required vars are set
- Use Relative Paths: Never hardcode absolute paths
- Handle Errors Gracefully: Return proper HTTP status codes
- Enable CORS: All endpoints should have CORS headers
- Timeout Handling: Set appropriate timeouts for external API calls
- Rate Limiting: Be mindful of third-party API rate limits
If a deployment breaks critical endpoints:
# 1. Check recent deployments
vercel ls
# 2. Find last working deployment
vercel inspect <deployment-url>
# 3. Promote previous deployment to production
vercel promote <previous-deployment-url>
# 4. Or rollback via dashboard
# Go to Vercel Dashboard → Deployments → Click "..." → Promote to ProductionThis codebase represents a comprehensive Claude Code component ecosystem with real-time analytics, modular architecture, extensive automation capabilities, and production-ready API infrastructure. The system is designed for scalability, maintainability, and ease of use while providing powerful development workflow enhancements.