Automated Change Inspector
Comprehensive hook designed for track, file, changes, simple. Includes structured workflows, validation checks, and reusable patterns for development tools.
Automated Change Inspector
Inspects and analyzes code changes after every edit operation, providing real-time feedback on code quality, complexity, and potential issues.
When to Use This Hook
Attach this hook when you need to:
- Get immediate feedback on code quality after every file modification including complexity analysis, pattern violations, and potential bugs
- Track cumulative code changes within a session to understand the scope and impact of modifications before committing
- Enforce coding standards automatically by inspecting each edit against configurable rules without waiting for a separate linting step
Consider alternatives when:
- Your IDE already provides real-time code analysis through language servers and inline diagnostics that cover the same concerns
- You are making rapid iterative changes where per-edit inspection creates too much overhead and you prefer batch analysis
Quick Start
Configuration
name: automated-change-inspector type: hook trigger: PostToolUse category: development-tools
Example Trigger
# Claude edits src/utils/parser.ts # Hook fires after Edit completes: # Change Inspector: Analyzing modification...
Example Output
Change Inspector: Analysis of src/utils/parser.ts
Lines Changed: 14 (added: 8, modified: 4, removed: 2)
Complexity Delta: +2 (new cyclomatic complexity: 12)
Pattern Check:
- console.log detected (consider removing for production)
- Magic number 86400 on line 23 (extract to named constant)
- Function parseInput now exceeds 30 lines (consider splitting)
Type Safety: All types resolved
Import Analysis: 1 new import added (lodash/merge)
Session Total: 47 lines changed across 6 files
Status: PASS with 3 suggestions
Core Concepts
Change Inspection Overview
| Aspect | Details |
|---|---|
| Trigger Point | PostToolUse on Edit, MultiEdit, and Write tool operations |
| Analysis Scope | Changed lines only, with context from surrounding code |
| Complexity Tracking | Cyclomatic complexity delta calculated per function |
| Pattern Library | Configurable set of anti-patterns and code smell detectors |
| Session Accumulator | Tracks cumulative changes across the entire session |
| Severity Levels | Info, suggestion, warning, and error for graduated feedback |
Inspection Workflow
PostToolUse (Edit/MultiEdit/Write)
|
v
[Identify changed file and lines]
|
v
[Parse changed code region]
|
+--- [Complexity analysis] --+
| |
+--- [Pattern matching] -----+
| |
+--- [Import analysis] ------+
| |
+--- [Type safety check] ----+
| |
v v
[Aggregate results] <-----------+
|
v
[Update session change accumulator]
|
v
[Output formatted report]
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
matcher | string | Edit|MultiEdit|Write | Tool types that trigger the change inspector |
complexity_threshold | integer | 15 | Cyclomatic complexity score that triggers a warning for a function |
max_function_lines | integer | 30 | Maximum function length in lines before suggesting decomposition |
pattern_file | string | .claude/inspection-patterns.json | Path to the configurable anti-pattern definition file |
severity_filter | string | suggestion | Minimum severity level to display: info, suggestion, warning, or error |
Best Practices
-
Start with suggestion severity and tighten gradually - Begin with the inspector showing all suggestions and gradually raise the
severity_filterto warning as your team becomes familiar with the feedback. This prevents information overload during the adoption period. -
Customize patterns for your project conventions - The default pattern library covers common anti-patterns, but every project has specific conventions. Add patterns for your framework-specific rules, naming conventions, and architecture boundaries to make the inspector truly useful.
-
Use the session accumulator for commit preparation - Before committing, review the session total to understand the full scope of changes. This summary helps write accurate commit messages and identify if the changes should be split into multiple focused commits.
-
Track complexity trends across sessions - Export complexity data from the inspector to track how functions evolve over time. Functions that consistently increase in complexity are candidates for refactoring before they become maintenance burdens.
-
Integrate with team code review standards - Align the inspector's pattern library with your team's code review checklist. This catches common review feedback automatically, allowing human reviewers to focus on architectural and design concerns.
Common Issues
-
Inspector reports false positives on generated code - Auto-generated files like API clients or schema types may trigger pattern violations that are not meaningful. Add file path exclusion patterns to skip inspection on generated directories like
src/generated/or__generated__/. -
Complexity analysis does not understand framework patterns - React components, Redux reducers, and other framework patterns may have high cyclomatic complexity by nature. Configure framework-specific complexity thresholds or exclude known patterns from complexity scoring.
-
Session accumulator resets unexpectedly - The accumulator state is stored in memory and resets when the hook process restarts. If you notice the session total resetting, it may indicate the hook is being re-initialized. Persist accumulator state to a temp file for durability across hook restarts.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.