
commit-analysis
by shfc
A curated collection of plugins that extend Claude Code with new commands, skills, hooks, and capabilities.
SKILL.md
name: Commit Analysis description: This skill should be used when the user asks to "analyze commits", "identify fix patterns", "detect code issues from commits", "git commit analysis", "parse commit history", or needs guidance on analyzing git commits to extract problem patterns and generate postmortem insights. version: 0.1.0
Commit Analysis for Problem Pattern Detection
This skill provides techniques for analyzing git commits to identify bug fix patterns, extract root causes, and detect similar issues in code changes.
Purpose
Commit analysis transforms raw git history into actionable insights by:
- Identifying which commits represent bug fixes vs. features
- Extracting problem patterns from fix commits
- Understanding root causes from code changes
- Detecting similar patterns in new code changes
- Building knowledge bases from historical fixes
Commit Identification Strategy
Two-Stage Filtering
Use a two-stage approach to identify fix-related commits:
Stage 1: Shell-based filtering
- Fast, deterministic filtering using commit message patterns
- Excludes obvious non-fix commits (feat, docs, chore, style, refactor, test, build, ci, perf)
- Includes commits with fix-related keywords if configured
Stage 2: AI analysis
- Analyze commit messages and diffs to confirm actual fixes
- Distinguish between bug fixes, workarounds, and refactorings
- Identify root cause from changes made
Conventional Commit Pattern Recognition
Parse conventional commit format: type(scope): subject
Common fix types:
fix:- Bug fixesbugfix:- Explicit bug fixeshotfix:- Urgent production fixespatch:- Small fixesrevert:- Reverting broken changessecurity:- Security fixes
Exclude types (not fixes):
feat:- New featuresdocs:- Documentationchore:- Maintenance tasksstyle:- Formatting, no logic changerefactor:- Code restructuring, no behavior changetest:- Test additionsbuild:- Build system changesci:- CI/CD configurationperf:- Performance improvements (not fixes)
Keyword-Based Detection
When commit messages don't follow conventional format, look for keywords:
Strong fix indicators:
- fix, fixes, fixed, fixing
- bug, bugfix
- issue, resolve, resolves, resolved
- hotfix, patch
- crash, error, failure
- broken, break
Context-dependent indicators:
- handle, prevent (may indicate defensive coding, not necessarily fixing existing bug)
- improve, update (could be enhancement or fix)
- correct, adjust (likely fixes)
AI analysis needed: When keywords are ambiguous, examine the diff to determine if it's fixing existing broken behavior or adding new functionality.
Commit Diff Analysis
Structure of Analysis
For each commit identified as potential fix, analyze:
- Files changed: Which modules/components affected
- Code patterns: What types of changes made
- Logic changes: What behavior was modified
- Test changes: What test coverage was added
Identifying Root Cause from Diff
Added Validation or Bounds Checking
Pattern: New if statements, assertions, or checks added
+ if (index < 0 || index >= array.length) {
+ throw new Error("Index out of bounds");
+ }
return array[index];
Root cause: Missing input validation or boundary check
Fixed Null/Undefined Handling
Pattern: Added null checks, optional chaining, or default values
- const name = user.profile.name;
+ const name = user?.profile?.name ?? "Unknown";
Root cause: Null pointer/undefined access
Corrected Logic or Algorithm
Pattern: Changed comparison operators, loop conditions, or calculations
- if (count > threshold) {
+ if (count >= threshold) {
Root cause: Logic error, off-by-one error
Added Synchronization or Locking
Pattern: Added mutexes, locks, or atomic operations
+ mutex.lock();
shared_resource.update();
+ mutex.unlock();
Root cause: Race condition or concurrency issue
Fixed Error Handling
Pattern: Added try-catch, error checking, or improved error propagation
try {
perform_operation();
+ } catch (SpecificError e) {
+ handle_error(e);
+ throw new UserFriendlyError("Operation failed");
}
Root cause: Missing or inadequate error handling
Corrected API Usage
Pattern: Changed function calls, parameter order, or API contracts
- api.call(data, callback, options);
+ api.call(data, options, callback);
Root cause: API misuse or misunderstanding
Fixed Resource Management
Pattern: Added resource cleanup, close operations, or lifecycle management
const file = open(path);
process(file);
+ file.close();
Root cause: Resource leak
Pattern Detection
Common Problem Patterns
Identify recurring patterns across fix commits:
1. Input Validation Issues
Symptoms:
- Added bounds checking
- Added type validation
- Added format verification
Pattern signature:
# Check for additions like:
if not validate_input(x):
raise ValueError()
2. Null/None Safety Issues
Symptoms:
- Added null checks
- Added default values
- Changed to safe navigation
Pattern signature:
# Check for changes like:
obj?.property # Optional chaining
value ?? default # Nullish coalescing
3. Race Conditions
Symptoms:
- Added locks or mutexes
- Changed to atomic operations
- Added synchronization
Pattern signature:
# Check for additions like:
with lock:
shared_state.update()
4. Off-by-One Errors
Symptoms:
- Changed
<to<=or vice versa - Changed
+1to+0or vice versa - Changed loop bounds
Pattern signature:
- for i in range(len(array)):
+ for i in range(len(array) - 1):
5. Error Handling Gaps
Symptoms:
- Added try-catch blocks
- Added error checking after operations
- Improved error messages
Pattern signature:
# Check for additions like:
try:
operation()
except Exception as e:
handle_error(e)
Merge Commit Analysis
Merge commits require special handling to identify conflict resolutions.
Detecting Merge-Related Fixes
Indicators of conflict resolution issues:
- Merge commit contains logic changes (not just combining changes)
- Subsequent fix commit shortly after merge
- Fix affects files that were merged
Analyzing Merge Conflicts
Use git tools to examine merge conflict resolution:
# Show what was changed in merge compared to parents
git show <merge-commit> --cc
# See which files had conflicts
git show <merge-commit> --name-only
Look for:
- Logic that combines both parents incorrectly
- Missing code from one parent
- Incorrect conflict resolution choices
- Broken integrations between merged features
Similarity Detection
Comparing Code Changes
To detect if new changes match known problem patterns:
File Path Similarity
- Exact match: Same file modified = High risk
- Same directory: Related files = Medium risk
- Same module: Same component = Low-medium risk
- Different area: Unrelated = Low risk
Code Structure Similarity
Analyze AST (Abstract Syntax Tree) or code patterns:
- Same function names or signatures
- Similar variable names
- Similar control flow structures
- Same API usage patterns
Keyword Similarity
Extract keywords from postmortem and compare with new changes:
- Technical terms (array, index, token, validation)
- Operation verbs (check, validate, parse, handle)
- Problem indicators (null, race, leak, overflow)
Risk Scoring
Combine similarity metrics:
risk_score = (
file_similarity * 0.4 +
pattern_similarity * 0.3 +
keyword_similarity * 0.3
)
if risk_score > 0.8:
risk_level = "critical"
elif risk_score > 0.6:
risk_level = "high"
elif risk_score > 0.4:
risk_level = "medium"
else:
risk_level = "low"
Batch Analysis Strategy
For analyzing many commits (during initialization):
Batch Size
- Process 10-20 commits per batch
- Prevents context overflow
- Allows for comprehensive analysis of each commit
Batch Processing Steps
- Extract commit metadata: Use
commit-filter.shto get candidate commits - Batch commits: Group into batches of 10-20
- Analyze each batch:
- For each commit: Get diff, message, files changed
- Determine if it's a fix (AI analysis)
- If fix: Extract problem pattern, root cause
- Generate postmortem draft
- Save results: Write postmortem documents
- Update index: Maintain searchable index
Incremental Updates
For ongoing updates:
- Track last analyzed commit hash in index
- Only analyze commits since last update
- Merge or update existing postmortems if new information found
Git Helper Utilities
Use provided scripts for common operations:
Get Commit Info
${CLAUDE_PLUGIN_ROOT}/scripts/git-helpers.sh get_commit_info <commit-hash>
Returns JSON with commit metadata.
Get Commit Diff
${CLAUDE_PLUGIN_ROOT}/scripts/git-helpers.sh get_commit_diff <commit-hash> --full
Options: --stat, --name-only, --full
Filter Commits
${CLAUDE_PLUGIN_ROOT}/scripts/commit-filter.sh \
--include-keywords "fix,bug,hotfix" \
--since 6.months.ago \
--format json
Returns filtered commit list.
Analysis Workflow
For Postmortem Generation
- Identify commit: Get commit hash from user or filter output
- Gather information:
info=$(git-helpers.sh get_commit_info $commit) diff=$(git-helpers.sh get_commit_diff $commit --full) - Analyze diff: Identify pattern from changes (see "Identifying Root Cause from Diff")
- Determine severity: Based on impact and scope
- Extract tags: From commit message, files, and patterns
- Generate postmortem: Use template and fill sections
- Validate: Ensure all sections complete and actionable
For Risk Analysis
- Get current changes:
git diff # For uncommitted changes git show <commit> # For specific commit - Load postmortem index: Read all existing postmortems
- Calculate similarity:
- File path matching
- Code pattern matching
- Keyword matching
- Score risk: Combine similarity metrics
- Report findings: List matching postmortems with risk levels
Common Analysis Mistakes
Mistake 1: Confusing Refactoring with Fixes
Not every code change is a fix. Refactoring improves structure without changing behavior.
Fix indicators:
- Adds validation that was missing
- Changes logic that was incorrect
- Handles errors that were unhandled
Refactoring indicators:
- Renames for clarity
- Extracts functions
- Improves structure without logic changes
Mistake 2: Missing Root Cause
Don't stop at surface symptom.
Surface: "Added null check" Root cause: "Function assumed input was always non-null because it was only called from one location, but new caller can pass null"
Mistake 3: Overmatching
Not every change to authentication code is the same issue.
Be specific: Match specific patterns, not just file paths.
Mistake 4: Ignoring Test Changes
Test additions reveal what edge cases were missed.
Analyze tests: They document the bug better than the fix sometimes.
Additional Resources
Reference Files
For detailed pattern detection techniques:
references/pattern-detection.md- Comprehensive pattern libraryreferences/diff-analysis.md- Advanced diff analysis techniques
Scripts
Utility scripts for commit analysis:
${CLAUDE_PLUGIN_ROOT}/scripts/commit-filter.sh- Universal commit filtering${CLAUDE_PLUGIN_ROOT}/scripts/git-helpers.sh- Git operation utilities
Key Principles
- Two-stage filtering: Shell first (fast), then AI (accurate)
- Root cause focus: Go beyond surface changes to understand why
- Pattern recognition: Look for recurring structures across fixes
- Similarity metrics: Combine multiple signals for risk detection
- Batch processing: Handle large histories efficiently
- Incremental updates: Only analyze new commits
Apply these techniques to transform git history into actionable knowledge for preventing code regression.
Score
Total Score
Based on repository quality metrics
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
Reviews
Reviews coming soon