From harness-claude
Analyzes entropy to find and safely remove unused exports, dead files, pattern violations, orphaned dependencies, and stale constraints after refactoring or for periodic hygiene.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Entropy analysis and safe cleanup. Find unused exports, dead files, and pattern violations — then remove them without breaking anything.
Detects dead code, unused exports, orphaned files, circular dependencies, unused packages, stale TODOs, and hygiene issues across 11 categories. Use scan, safe, aggressive modes on full codebase or paths.
Diagnoses repo rot prioritizing dead code (HIGH/MEDIUM/LOW confidence), god files, hotspots, hardcoded paths, stale TODOs, lopsided imports. Language-agnostic pure diagnosis.
Identifies unused imports, variables, functions, unreachable code, dependencies, and CSS for safe removal. Generates reports categorizing safe-to-remove, potentially unused, and review-required items.
Share bugs, ideas, or general feedback.
Entropy analysis and safe cleanup. Find unused exports, dead files, and pattern violations — then remove them without breaking anything.
on_entropy_check triggers fireharness cleanup reports growing entropy in the project health dashboardRun harness cleanup to generate a full entropy report. This analyzes:
Run harness cleanup --type dead-code --json for machine-readable output focused specifically on unused code.
Check for stale constraints. Run detect_stale_constraints to identify architectural constraints referencing removed code that should also be cleaned up.
Review the report summary. Note the total count and distribution. A few dead exports are normal; dozens suggest accumulated entropy from incomplete refactorings.
When a knowledge graph exists at .harness/graph/, use graph queries for faster, more accurate dead code detection:
query_graph — perform graph reachability analysis from entry point nodes to identify truly unreachable codeget_relationships — distinguish dynamic imports from genuinely unused code by checking edge typesGraph reachability reduces false positives compared to static analysis alone, since it traces the full transitive import graph including re-exports. Fall back to file-based commands if no graph is available.
Safe to auto-fix (remove without further analysis):
export keyword or delete entirely if zero internal callersNeeds human review before removal:
For each item categorized as safe:
Remove the dead code. Delete the export, function, file, or import.
Run harness fix-drift to update any documentation references that pointed to the deleted code.
Run the full test suite. All tests must pass. If any test fails:
Run harness validate and harness check-deps. Both must pass.
Commit the cleanup. Group related removals into logical commits (e.g., "remove unused shipping utilities" not "delete dead code").
New fix types:
detect_entropy with autoFix: true, fixTypes: ['dead-exports']. The tool removes the export keyword. If the function/class has zero internal callers too, delete the entire declaration.detect_entropy with autoFix: true, fixTypes: ['commented-code']. The tool deletes commented-out code blocks. This is cosmetic and only needs lint verification.detect_entropy with autoFix: true, fixTypes: ['orphaned-deps']. The tool removes the dep from package.json. Must run pnpm install && pnpm test after to verify nothing breaks.When running standalone (not through the orchestrator), apply a single-concern convergence loop:
harness cleanup --type dead-code again.Why convergence matters: Removing dead code can create more dead code. For example:
If a knowledge graph exists at .harness/graph/, refresh it after code changes to keep graph queries accurate:
harness scan [path]
Dead code removal changes graph topology — skipping this step means subsequent graph queries (impact analysis, dependency health, test advisor) may return stale results.
For items that need human review, report:
These patterns make code APPEAR dead when it is actually in use:
// This import won't show up in static analysis
const module = await import(`./plugins/${pluginName}`);
Files in a plugins/ directory may appear unused but are loaded dynamically at runtime. Check for import() calls, require() with variables, and glob-based loading patterns.
// test-helpers.ts — only imported by test files
export function createMockUser() { ... }
Test utility files may appear unused if the analysis excludes test files. Verify that harness cleanup includes test files in its import graph.
// Only used as a type, never as a value
export interface UserConfig { ... }
Some analysis tools miss type-only imports (import type { UserConfig }). Verify before deleting any exported interface or type alias.
// index.ts — re-exports for external consumers
export { createClient } from './client';
The entry point of a package re-exports things for external consumers. These exports may have zero internal imports but are the public API.
// polyfills.ts — imported for side effects, not for exports
import './polyfills';
Some files are imported for their side effects (polyfills, global registrations, CSS). They have no exports but are not dead.
// Only used when FEATURE_FLAG_X is enabled
if (process.env.FEATURE_FLAG_X) {
const handler = require('./experimental-handler');
}
Code behind feature flags or environment checks may appear dead in the default configuration.
harness cleanup — Full entropy analysis. Reports dead exports, unused files, pattern violations, and orphaned dependencies.harness cleanup --type dead-code — Focused analysis on unused code specifically.harness cleanup --type dead-code --json — Machine-readable output for automation.harness fix-drift — Update documentation after removing dead code. Ensures deleted items are not still referenced in docs.harness validate — Run after cleanup to verify project structure remains valid.harness check-deps — Run after cleanup to verify no dependency violations were introduced.harness cleanup reports zero dead exports and zero unused files (or all remaining items are documented as intentional)harness validate and harness check-deps pass after cleanupThese are common rationalizations that sound reasonable but lead to incorrect results. When you catch yourself thinking any of these, stop and follow the documented process instead.
| Rationalization | Why It Is Wrong |
|---|---|
| "This export has zero static imports, so it is definitely dead and safe to remove" | Zero static imports does not mean zero consumers. Dynamic imports, type-only imports, side-effect imports, and package entry points all create false positives. |
| "I removed the dead code and the tests pass, so I do not need to run harness validate and check-deps" | Both harness validate and harness check-deps must pass after every cleanup. Dead code removal can introduce dependency violations. |
| "The convergence loop found new dead code after my fixes, but it is probably just noise from the tool" | Removing dead code creates more dead code. The convergence loop exists to catch these cascades. If the issue count decreased, loop back. |
| "The entropy report has 60 items but I can clean them all up in one pass to be thorough" | When the report is very large (>50 items), pick the highest-confidence dead code first. Attempting everything at once risks compound errors. |
Entropy report:
DEAD EXPORT: src/utils/string-helpers.ts
- capitalizeFirst() — 0 imports found
- truncateWithEllipsis() — 0 imports found
- slugify() — 3 imports found (ACTIVE, not dead)
Action: Remove capitalizeFirst and truncateWithEllipsis from the file. Keep slugify. Run tests — all pass. Commit: "remove unused capitalizeFirst and truncateWithEllipsis from string-helpers"
Entropy report:
UNUSED FILE: src/plugins/markdown-renderer.ts
- 0 static imports found
- File contains: export default class MarkdownRenderer
Investigation: Check for dynamic imports:
// src/plugins/index.ts
const renderer = await import(`./${format}-renderer`);
Result: False positive. The file is loaded dynamically based on the format variable. Mark as intentional and add a comment in the file explaining the dynamic loading pattern.
Entropy report:
ORPHANED DEPENDENCY: moment (package.json)
- 0 imports of 'moment' found in src/
- Last imported in commit abc123 (removed 3 months ago)
Action: Remove moment from package.json dependencies. Run npm install to update lockfile. Run tests — all pass. Commit: "remove unused moment dependency"