AgileFlow

Dead Feature Branch Analyzer

PreviousNext

Dead feature branch analyzer for hardcoded false conditions, dead feature flags, unreachable code after return/throw, and large commented-out blocks

Dead Feature Branch Analyzer

The Completeness Analyzer: Dead Feature Branch agent is a specialized analyzer focused on dead conditional logic and feature branches. It finds hardcoded false conditions that disable features, dead feature flags that never change, unreachable code after return/throw statements, and large commented-out code blocks that should be removed.

When to Use

Use this agent when:

  • You need to identify hardcoded false conditions that always skip code
  • You want to find dead feature flags that were left in the codebase
  • You're looking for unreachable code after return/throw statements
  • You need to identify and remove commented-out blocks
  • You're cleaning up technical debt from feature rollouts

How It Works

  1. Reads conditional code - Scans all if/else, ternary, && and || operators
  2. Evaluates constants - Checks if conditions depend only on constants
  3. Identifies dead branches - Finds branches that can never execute
  4. Finds feature flags - Looks for flag-like variables that are hardcoded
  5. Detects unreachable code - Finds code after return/throw/break
  6. Finds dead comments - Identifies large commented-out blocks
  7. Reports findings - Lists dead code with context and suggested removal

Focus Areas

  • Hardcoded false conditions: if (false), if (FEATURE_ENABLED === false) where FEATURE_ENABLED is never true
  • Dead feature flags: Flags that were left with hardcoded values after rollout
  • Unreachable code: Code after return, throw, or break statements
  • Large commented-out blocks: Commented code that should be deleted
  • Unreachable branches: Else clauses that can never execute

Tools Available

This agent has access to: Read, Glob, Grep

Example Analysis

Given code like:

// Hardcoded false condition
if (false) {
  logErrorToService();
}
 
// Dead feature flag
if (BETA_UI === false) {
  // Old UI code that will never run
  return <LegacyUI />;
}
 
// Unreachable code
if (user) {
  return user.name;
}
// Code below never executes
const fallback = 'Guest';
 
// Commented-out block
/*
function deprecatedApiCall() {
  return fetch('/old-api-endpoint').then(r => r.json());
}
*/

The Dead Feature Branch analyzer would identify:

Finding: Hardcoded false condition in error logging

Location: src/lib/logger.js:45 Severity: P2 (dead code) Confidence: HIGH

Issue: The condition if (false) on line 45 is always false. The error logging code inside never executes. This should either be enabled (remove false) or deleted.

Suggested Fix: Remove the dead branch

// Before
if (false) {
  logErrorToService();
}
 
// After
logErrorToService(); // Enabled and always runs

Finding: Dead feature flag after rollout

Location: src/App.tsx:28 Severity: P1 (misleading code) Confidence: HIGH

Issue: BETA_UI is hardcoded to false, making the entire if-branch unreachable. Feature flag was left behind after beta was disabled. Should be removed.

Code:

const BETA_UI = false;
if (BETA_UI) {
  // This code path never executes
  return <BetaUI />;
}

Suggested Fix: Remove the dead flag and its branch

return <ProductionUI />;

Finding: Unreachable code after return

Location: src/utils/validators.js:120 Severity: P2 (dead code) Confidence: HIGH

Issue: Code after line 122 (const fallback = 'Guest') is unreachable because all paths return.

Code:

if (user) {
  return user.name;
}
const fallback = 'Guest'; // ← Unreachable
return fallback;

Suggested Fix: Move assignment inside condition or restructure

// Option 1: Move into condition
const fallback = 'Guest';
if (user) {
  return user.name;
}
return fallback;
 
// Option 2: Use ternary
return user?.name ?? 'Guest';

Finding: Large commented-out code block

Location: src/api/clients/user.js:200 Severity: P2 (technical debt) Confidence: HIGH

Issue: 47-line commented block of old API code. Should be deleted or migrated to version control.

Suggested Action: Delete and use git history to recover if needed

Best Practices

  • Remove hardcoded false conditions - they indicate incomplete cleanup
  • Delete feature flags after rollout is complete
  • Use source control instead of commenting out code
  • Remove unreachable code immediately after refactoring
  • Document why branches exist if they're intentionally unreachable

Output Format

For each finding, the agent provides:

  • Location: File path and line number
  • Type: Hardcoded false, dead flag, unreachable code, or commented block
  • Severity: P0 (incorrect behavior), P1 (misleading), or P2 (dead code)
  • Confidence: HIGH, MEDIUM, or LOW
  • Code: Exact code snippet
  • Issue: Why it's dead and why it matters
  • Suggested Fix: How to remove or restructure

Example Usage

Task(
  description: "Find dead feature branches in user service",
  prompt: "Scan src/ for dead conditional logic including hardcoded false conditions, dead feature flags, unreachable code after return/throw, and large commented-out blocks.",
  subagent_type: "agileflow-completeness-analyzer-conditional"
)