Initial commit: Claude Code Hooks with Diátaxis documentation
✨ Features: - 🧠 Shadow learner that builds intelligence from command patterns - 🛡️ Smart command validation with safety checks - 💾 Automatic context monitoring and backup system - 🔄 Session continuity across Claude restarts 📚 Documentation: - Complete Diátaxis-organized documentation - Learning-oriented tutorial for getting started - Task-oriented how-to guides for specific problems - Information-oriented reference for quick lookup - Understanding-oriented explanations of architecture 🚀 Installation: - One-command installation script - Bootstrap prompt for installation via Claude - Cross-platform compatibility - Comprehensive testing suite 🎯 Ready for real-world use and community feedback! 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
162ca67098
34 changed files with 5904 additions and 0 deletions
277
docs/how-to/share-patterns.md
Normal file
277
docs/how-to/share-patterns.md
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
# How to Share Learned Patterns with Your Team
|
||||
|
||||
**When to use this guide**: You want to share the intelligence your Claude Hooks has learned with teammates or across projects.
|
||||
|
||||
## Export Your Patterns
|
||||
|
||||
### Export Everything
|
||||
|
||||
Create a complete export of your learned patterns:
|
||||
|
||||
```bash
|
||||
claude-hooks export
|
||||
```
|
||||
|
||||
This creates a `claude_hooks_export/` directory with:
|
||||
- `patterns.json` - All learned command patterns
|
||||
- `session_data.json` - Session history and statistics
|
||||
- `logs/` - Execution logs for analysis
|
||||
|
||||
### Export Just Patterns
|
||||
|
||||
If you only want to share the learned intelligence:
|
||||
|
||||
```bash
|
||||
cp .claude_hooks/patterns/patterns.json team_patterns_$(date +%Y%m%d).json
|
||||
```
|
||||
|
||||
## Share Patterns with Teammates
|
||||
|
||||
### Method 1: Direct File Sharing
|
||||
|
||||
1. **Export your patterns**:
|
||||
```bash
|
||||
cp .claude_hooks/patterns/patterns.json my_patterns_$(whoami).json
|
||||
```
|
||||
|
||||
2. **Share the file** via your usual method (Slack, email, git repo, etc.)
|
||||
|
||||
3. **Teammates import** by copying to their patterns directory:
|
||||
```bash
|
||||
# Backup their existing patterns first
|
||||
cp .claude_hooks/patterns/patterns.json .claude_hooks/patterns/patterns.backup.json
|
||||
|
||||
# Merge your patterns
|
||||
cp received_patterns.json .claude_hooks/patterns/patterns.json
|
||||
```
|
||||
|
||||
### Method 2: Git Repository Sharing
|
||||
|
||||
Create a shared patterns repository:
|
||||
|
||||
1. **In your team's patterns repo**:
|
||||
```bash
|
||||
mkdir team-claude-patterns
|
||||
cd team-claude-patterns
|
||||
git init
|
||||
```
|
||||
|
||||
2. **Add patterns from team members**:
|
||||
```bash
|
||||
mkdir patterns
|
||||
cp ~/.../teammate1_patterns.json patterns/
|
||||
cp ~/.../teammate2_patterns.json patterns/
|
||||
git add . && git commit -m "Initial team patterns"
|
||||
```
|
||||
|
||||
3. **Team members sync** their patterns:
|
||||
```bash
|
||||
git clone git@company:team-claude-patterns.git
|
||||
|
||||
# Merge latest team patterns
|
||||
python3 merge_team_patterns.py
|
||||
```
|
||||
|
||||
### Method 3: Centralized Pattern Server
|
||||
|
||||
For larger teams, set up a simple pattern sharing server:
|
||||
|
||||
1. **Create a patterns API endpoint** (simple HTTP server):
|
||||
```python
|
||||
# patterns_server.py
|
||||
from flask import Flask, request, jsonify
|
||||
import json
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/patterns', methods=['GET'])
|
||||
def get_patterns():
|
||||
with open('team_patterns.json', 'r') as f:
|
||||
return json.load(f)
|
||||
|
||||
@app.route('/patterns', methods=['POST'])
|
||||
def update_patterns():
|
||||
# Merge submitted patterns with team patterns
|
||||
pass
|
||||
```
|
||||
|
||||
2. **Team members sync** with the server:
|
||||
```bash
|
||||
curl https://patterns.company.com/patterns > .claude_hooks/patterns/patterns.json
|
||||
```
|
||||
|
||||
## Merge Multiple Pattern Sets
|
||||
|
||||
When combining patterns from multiple sources:
|
||||
|
||||
1. **Create a merge script**:
|
||||
```bash
|
||||
cat > merge_patterns.py << 'EOF'
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
def merge_patterns(base_file, new_file, output_file):
|
||||
# Load both pattern sets
|
||||
with open(base_file, 'r') as f:
|
||||
base_patterns = json.load(f)
|
||||
with open(new_file, 'r') as f:
|
||||
new_patterns = json.load(f)
|
||||
|
||||
# Merge command patterns (keep highest confidence)
|
||||
for cmd, pattern in new_patterns.get('command_patterns', {}).items():
|
||||
if cmd not in base_patterns['command_patterns']:
|
||||
base_patterns['command_patterns'][cmd] = pattern
|
||||
else:
|
||||
# Keep pattern with higher confidence
|
||||
if pattern['confidence'] > base_patterns['command_patterns'][cmd]['confidence']:
|
||||
base_patterns['command_patterns'][cmd] = pattern
|
||||
|
||||
# Merge other pattern types similarly...
|
||||
|
||||
# Save merged patterns
|
||||
with open(output_file, 'w') as f:
|
||||
json.dump(base_patterns, f, indent=2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
merge_patterns(sys.argv[1], sys.argv[2], sys.argv[3])
|
||||
EOF
|
||||
|
||||
chmod +x merge_patterns.py
|
||||
```
|
||||
|
||||
2. **Use the merge script**:
|
||||
```bash
|
||||
./merge_patterns.py .claude_hooks/patterns/patterns.json teammate_patterns.json merged_patterns.json
|
||||
cp merged_patterns.json .claude_hooks/patterns/patterns.json
|
||||
```
|
||||
|
||||
## Team Pattern Standards
|
||||
|
||||
### Establish Team Conventions
|
||||
|
||||
Create a team agreement on pattern sharing:
|
||||
|
||||
1. **Pattern Quality Standards**:
|
||||
- Minimum confidence threshold (e.g., 0.8)
|
||||
- Minimum evidence count (e.g., 5 samples)
|
||||
- Maximum pattern age (e.g., 30 days)
|
||||
|
||||
2. **Sharing Frequency**:
|
||||
- Weekly pattern sync meetings
|
||||
- After major project milestones
|
||||
- When discovering important new patterns
|
||||
|
||||
3. **Pattern Categories**:
|
||||
- `production-safe` - Patterns safe for production environments
|
||||
- `development-only` - Patterns specific to dev environments
|
||||
- `experimental` - New patterns needing validation
|
||||
|
||||
### Filter Patterns for Sharing
|
||||
|
||||
Only share high-quality, relevant patterns:
|
||||
|
||||
```bash
|
||||
cat > filter_patterns.py << 'EOF'
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import sys
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
def filter_patterns(input_file, output_file, min_confidence=0.8, min_evidence=3):
|
||||
with open(input_file, 'r') as f:
|
||||
patterns = json.load(f)
|
||||
|
||||
filtered = {'command_patterns': {}, 'context_patterns': {}}
|
||||
|
||||
# Filter command patterns
|
||||
for cmd, pattern in patterns.get('command_patterns', {}).items():
|
||||
if (pattern['confidence'] >= min_confidence and
|
||||
pattern['evidence_count'] >= min_evidence):
|
||||
filtered['command_patterns'][cmd] = pattern
|
||||
|
||||
# Filter context patterns similarly...
|
||||
|
||||
with open(output_file, 'w') as f:
|
||||
json.dump(filtered, f, indent=2)
|
||||
|
||||
print(f"Filtered {len(patterns.get('command_patterns', {}))} to {len(filtered['command_patterns'])} patterns")
|
||||
|
||||
if __name__ == "__main__":
|
||||
filter_patterns(sys.argv[1], sys.argv[2])
|
||||
EOF
|
||||
|
||||
chmod +x filter_patterns.py
|
||||
```
|
||||
|
||||
Use it:
|
||||
```bash
|
||||
./filter_patterns.py .claude_hooks/patterns/patterns.json team_ready_patterns.json
|
||||
```
|
||||
|
||||
## Environment-Specific Pattern Sets
|
||||
|
||||
Maintain different pattern sets for different environments:
|
||||
|
||||
```bash
|
||||
# Directory structure
|
||||
team_patterns/
|
||||
├── production/
|
||||
│ └── patterns.json # Only production-safe patterns
|
||||
├── development/
|
||||
│ └── patterns.json # Dev-specific patterns
|
||||
├── staging/
|
||||
│ └── patterns.json # Staging environment patterns
|
||||
└── global/
|
||||
└── patterns.json # Patterns safe everywhere
|
||||
```
|
||||
|
||||
Load appropriate patterns:
|
||||
```bash
|
||||
# For production deployment
|
||||
cp team_patterns/production/patterns.json .claude_hooks/patterns/
|
||||
cp team_patterns/global/patterns.json .claude_hooks/patterns/global_patterns.json
|
||||
|
||||
# Merge them
|
||||
./merge_patterns.py .claude_hooks/patterns/patterns.json .claude_hooks/patterns/global_patterns.json .claude_hooks/patterns/patterns.json
|
||||
```
|
||||
|
||||
## Validate Shared Patterns
|
||||
|
||||
Before using patterns from others:
|
||||
|
||||
1. **Review dangerous patterns**:
|
||||
```bash
|
||||
jq '.command_patterns | to_entries[] | select(.value.confidence > 0.9 and .value.success_rate < 0.1)' patterns.json
|
||||
```
|
||||
|
||||
2. **Check for environment conflicts**:
|
||||
```bash
|
||||
# Test patterns against your system
|
||||
claude-hooks test-patterns shared_patterns.json
|
||||
```
|
||||
|
||||
3. **Gradually adopt** new patterns rather than importing everything at once
|
||||
|
||||
## Monitor Pattern Effectiveness
|
||||
|
||||
Track how shared patterns perform:
|
||||
|
||||
```bash
|
||||
# See which patterns are actually being used
|
||||
tail -f .claude_hooks/logs/executions_$(date +%Y%m%d).jsonl | grep "pattern_matched"
|
||||
|
||||
# Check pattern success rates
|
||||
claude-hooks patterns --stats
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Patterns not taking effect**: Ensure patterns.json is valid JSON and in the right location
|
||||
|
||||
**Conflicts between patterns**: Use the merge script to combine patterns intelligently
|
||||
|
||||
**Too many false positives**: Increase confidence thresholds or add environment-specific filtering
|
||||
|
||||
**Patterns missing context**: Include the original environment info when sharing patterns
|
||||
Loading…
Add table
Add a link
Reference in a new issue