AgileFlow

/impact

PreviousNext

Analyze change impact across codebase

/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=no

The command will:

  1. Identify changed files
  2. Map dependencies (direct and indirect)
  3. Find related tests
  4. Detect breaking changes
  5. Generate impact report
  6. 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.tsx

Breaking 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:67

Coverage 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 paths

Usage

Basic - auto-detect changes

/agileflow:impact

Uses git to find changes on current branch and analyzes impact.

Analyze specific files

/agileflow:impact FILES=src/api/auth.ts,src/middleware/jwt.ts

Analyzes only the listed files (useful for manual analysis).

Different base branch

/agileflow:impact BASE=develop

Compares against develop instead of main/master.

Skip test execution

/agileflow:impact RUN_TESTS=no

Shows impact analysis but doesn't run tests.

Parameters

ParameterRequiredDefaultDescription
FILESNoAuto-detectComma-separated file paths
BASENomain/masterBase branch for comparison
RUN_TESTSNoyesExecute 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.ts

Breaking 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:23

Impact Report Structure

# Impact Analysis Report
 
**Branch**: feature/user-auth
**Base**: main
**Changed Files**: 5
**Potentially Affected Files**: 23
**Tests to Run**: 12

Direct 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 TypePattern
API route changedLook for routes.test.ts, api/*.test.ts
Component changedLook for *.test.tsx, *.stories.tsx
Service changedLook for service.test.ts, integration tests
Type changedLook 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:45

Type 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:12

Test 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
  • 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 run

2. 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 failed

3. 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"
    fi

Use Cases

Before submitting PR

# Check impact of your changes
/agileflow:impact
 
# Run the recommended tests
# If any fail, fix before submitting PR

After code review feedback

# You made changes based on review
/agileflow:impact
 
# Make sure nothing broke
# Re-run affected tests

Before merging to main

# Final check before merge
/agileflow:impact BASE=main
 
# Ensure no regressions
# All critical tests passing

Refactoring safety

# Before large refactor
/agileflow:baseline "Before refactor"
 
# Make changes
# Check impact
/agileflow:impact
 
# If breaking changes, understand them
# Update callers accordingly

Tips

Run impact early and often

# After each major change
/agileflow:impact
 
# Catch breakage early
# Easier to fix one change than many

Pay attention to indirect impacts

Direct impact: 3 affected files
Indirect impact: 8 more affected files
 
Fixing direct isn't enough - test indirects too

Test coverage matters

87% coverage = 13% of changes untested
Missing tests = potential bugs from untested paths
 
Add tests for uncovered lines

Breaking changes require coordination

⚠️  Function signature changed
Need to update 5 callers
Create stories to track the updates
  • /review - Code quality review
  • /verify - Run tests
  • /pr - Generate PR with impact notes
  • /babysit - Implementation guidance (runs impact)
  • /baseline - Create verified checkpoint