/impact
Analyze the impact of code changes on other parts of your codebase to prevent regressions. Impact detection identifies affected files, tests, and features, then suggests which tests to run and what might break.
Quick Start
# Auto-detect changes on current branch
/agileflow:impact
# Analyze specific files
/agileflow:impact FILES=src/api/auth.ts,src/middleware/jwt.ts
# Skip test execution
/agileflow:impact RUN_TESTS=noThe command will:
- Identify changed files
- Map dependencies (direct and indirect)
- Find related tests
- Detect breaking changes
- Generate impact report
- Optionally run affected tests
Key Features
Dependency Graph Analysis
Impact automatically builds a dependency graph:
Your Change: src/api/auth.ts
├─ Direct dependents (files that import this)
│ ├─ src/api/auth/index.ts
│ ├─ src/middleware/auth.ts
│ └─ tests/api/auth/login.test.ts
└─ Indirect dependents (2-level chain)
├─ src/app.ts
├─ src/routes.ts
└─ [more...]Test Discovery
Automatically finds tests that need to run:
Critical (Always Run):
✓ tests/api/auth/login.test.ts
✓ tests/integration/auth-flow.test.ts
Recommended (Affected Indirectly):
⚠️ tests/api/users/*.test.ts
⚠️ tests/e2e/login.spec.ts
Optional (Low Risk):
- tests/components/Header.test.tsxBreaking Change Detection
Identifies function signature changes:
⚠️ BREAKING CHANGE DETECTED
File: src/api/auth/login.ts
Function: login()
Before:
login(email: string, password: string): Promise<Token>
After:
login(credentials: LoginRequest): Promise<AuthResponse>
Affected callers:
- src/middleware/auth.ts:45
- tests/api/auth/login.test.ts:23
- tests/integration/auth-flow.test.ts:67Coverage Mapping
Shows test coverage for changed code:
Changed Lines: 45-52 (8 lines)
Test Coverage: 87%
Uncovered: Lines 50-51 (2 lines not tested)
⚠️ 2 lines of changes have no test coverage
Consider adding tests for these pathsUsage
Basic - auto-detect changes
/agileflow:impactUses git to find changes on current branch and analyzes impact.
Analyze specific files
/agileflow:impact FILES=src/api/auth.ts,src/middleware/jwt.tsAnalyzes only the listed files (useful for manual analysis).
Different base branch
/agileflow:impact BASE=developCompares against develop instead of main/master.
Skip test execution
/agileflow:impact RUN_TESTS=noShows impact analysis but doesn't run tests.
Parameters
| Parameter | Required | Default | Description |
|---|---|---|---|
FILES | No | Auto-detect | Comma-separated file paths |
BASE | No | main/master | Base branch for comparison |
RUN_TESTS | No | yes | Execute affected tests |
Examples
Typical feature changes
/agileflow:impact
# Output:
# Impact Analysis Report
#
# Changed Files: 3
# - src/api/auth.ts (23 lines modified)
# - src/middleware/auth.ts (15 lines modified)
# - src/components/LoginForm.tsx (12 lines modified)
#
# Affected Files: 8
# - Direct dependents: 3
# - Indirect dependents: 5
#
# Tests to Run: 5
# - Critical: 2 (direct tests)
# - Recommended: 3 (integration tests)
#
# Coverage: 87% (2 lines uncovered)Security middleware change
/agileflow:impact FILES=src/middleware/auth.ts
# Output:
# Changed: src/middleware/auth.ts (34 lines)
#
# Direct Dependents (6):
# - src/api/auth/index.ts
# - src/api/users/index.ts
# - src/api/posts/index.ts
# - src/middleware/validate.ts
# - src/app.ts
# - tests/middleware/auth.test.ts
#
# Tests to Run:
# ✓ tests/middleware/auth.test.ts
# ⚠️ tests/integration/auth-flow.test.ts
# ⚠️ tests/api/*/index.test.tsBreaking change detection
/agileflow:impact
# Output includes:
# ⚠️ BREAKING CHANGE DETECTED
#
# Function signature changed in src/api/auth/login.ts
#
# Before: login(email, password)
# After: login(credentials)
#
# Update these callers:
# - src/middleware/auth.ts:45
# - tests/api/auth/login.test.ts:23Impact Report Structure
Header
# Impact Analysis Report
**Branch**: feature/user-auth
**Base**: main
**Changed Files**: 5
**Potentially Affected Files**: 23
**Tests to Run**: 12Direct Impacts
For each changed file:
### src/api/auth/login.ts (MODIFIED)
**Type**: API endpoint
**Changes**: 23 lines modified
**Direct dependents** (3):
- src/api/auth/index.ts (exports this endpoint)
- src/middleware/auth.ts (uses login logic)
- tests/api/auth/login.test.ts (tests this file)
**Indirect dependents** (8):
- src/app.ts → src/api/auth/index.ts → login.ts
- src/routes.ts → src/api/auth/index.ts → login.ts
- [6 more...]
**Related tests**:
- ✅ tests/api/auth/login.test.ts (exists)
- ⚠️ tests/integration/auth-flow.test.ts (may need updates)
- ❌ Missing: E2E test for login flow
**Related stories**:
- US-0042: Implement JWT authentication (IN-REVIEW)
**Coverage**: 87% (lines 45-52 uncovered)Analysis Methods
Static Analysis
Impact uses static code analysis (no running code):
- Parse import/require statements
- Build dependency graph
- Identify circular dependencies
- Find exported but unused code
- Map file relationships
Benefits: Fast, doesn't require build/tests to run, catches import changes
Test Coverage Mapping
Maps changed lines to tests:
- Reads coverage reports (if available)
- Matches line numbers to test files
- Identifies uncovered changes
- Suggests test additions
Pattern Matching
Smart pattern matching for related tests:
| Change Type | Pattern |
|---|---|
| API route changed | Look for routes.test.ts, api/*.test.ts |
| Component changed | Look for *.test.tsx, *.stories.tsx |
| Service changed | Look for service.test.ts, integration tests |
| Type changed | Look for *.test.ts that use the type |
Breaking Changes
Impact detects breaking changes:
Function Signature Change
⚠️ BREAKING CHANGE
Function: login()
Before: login(email: string, password: string)
After: login(credentials: LoginRequest)
Callers to update:
- src/middleware/auth.ts:45
OLD: login(user.email, user.password)
NEW: login({ email: user.email, password: user.password })Removed Export
⚠️ BREAKING CHANGE
Removed export: validateSession
(was in src/middleware/auth.ts)
Callers will break:
- src/api/posts/index.ts:23 - imports validateSession
- tests/middleware/auth.test.ts:45Type Change
⚠️ BREAKING CHANGE
Type changed: User interface
Added required field: verified_at (Date)
Callers creating User without field:
- src/api/auth/signup.ts:67
- src/seeders/users.ts:12Test Recommendations
Impact suggests which tests to run:
Critical (Always Run)
- Direct unit tests for changed files
- Tests that specifically target the changed code
- All tests that import changed file
Recommended (Run if Time Permits)
- Integration tests using changed files
- End-to-end tests through changed features
- Tests of dependent features
Optional (Low Risk)
- Peripheral tests
- Tests with indirect dependency chains
- Tests of unrelated features
Actions After Analysis
1. Review Impact Summary
Changed: 3 files
Affected: 8 files
Tests: 5 need to run2. Run Tests (if RUN_TESTS=yes)
Running critical tests...
✅ tests/api/auth/login.test.ts (12 tests, 345ms)
✅ tests/middleware/auth.test.ts (8 tests, 234ms)
⚠️ tests/integration/auth-flow.test.ts (3 tests, FAILED)
Test Results: 20 passed, 3 failed3. Handle Failures
If tests fail:
Tests failed. Options:
1. Fix code and re-run tests
2. Create story for regression
3. Skip and investigate later
What should we do?4. Handle Breaking Changes
If breaking changes detected:
⚠️ Breaking changes found!
These functions changed signature:
- login() in src/api/auth.ts
3 callers need to be updated:
- src/middleware/auth.ts:45
- tests/api/auth/login.test.ts:23
Create stories to update these files?Visualization
Impact can visualize dependency trees:
src/api/auth/login.ts (CHANGED)
├── src/api/auth/index.ts (direct)
│ ├── src/app.ts (indirect)
│ └── src/routes.ts (indirect)
├── src/middleware/auth.ts (direct)
│ └── src/app.ts (indirect)
└── tests/api/auth/login.test.ts (test)Integration with CI
Suggest optimized CI that only runs affected tests:
- name: Impact analysis
run: npx claude-code /agileflow:impact BASE=main
- name: Run affected tests
run: npm test -- $(cat affected-tests.txt)
- name: Check for breaking changes
run: |
if grep -q "BREAKING CHANGE" impact-report.md; then
echo "::warning::Breaking changes detected"
fiUse Cases
Before submitting PR
# Check impact of your changes
/agileflow:impact
# Run the recommended tests
# If any fail, fix before submitting PRAfter code review feedback
# You made changes based on review
/agileflow:impact
# Make sure nothing broke
# Re-run affected testsBefore merging to main
# Final check before merge
/agileflow:impact BASE=main
# Ensure no regressions
# All critical tests passingRefactoring safety
# Before large refactor
/agileflow:baseline "Before refactor"
# Make changes
# Check impact
/agileflow:impact
# If breaking changes, understand them
# Update callers accordinglyTips
Run impact early and often
# After each major change
/agileflow:impact
# Catch breakage early
# Easier to fix one change than manyPay attention to indirect impacts
Direct impact: 3 affected files
Indirect impact: 8 more affected files
Fixing direct isn't enough - test indirects tooTest coverage matters
87% coverage = 13% of changes untested
Missing tests = potential bugs from untested paths
Add tests for uncovered linesBreaking changes require coordination
⚠️ Function signature changed
Need to update 5 callers
Create stories to track the updatesRelated Commands
On This Page
/impactQuick StartKey FeaturesDependency Graph AnalysisTest DiscoveryBreaking Change DetectionCoverage MappingUsageBasic - auto-detect changesAnalyze specific filesDifferent base branchSkip test executionParametersExamplesTypical feature changesSecurity middleware changeBreaking change detectionImpact Report StructureHeaderDirect ImpactsAnalysis MethodsStatic AnalysisTest Coverage MappingPattern MatchingBreaking ChangesFunction Signature ChangeRemoved ExportType ChangeTest RecommendationsCritical (Always Run)Recommended (Run if Time Permits)Optional (Low Risk)Actions After Analysis1. Review Impact Summary2. Run Tests (if RUN_TESTS=yes)3. Handle Failures4. Handle Breaking ChangesVisualizationIntegration with CIUse CasesBefore submitting PRAfter code review feedbackBefore merging to mainRefactoring safetyTipsRun impact early and oftenPay attention to indirect impactsTest coverage mattersBreaking changes require coordinationRelated Commands