Fixes code organization issues including high complexity, large files, deep nesting, and barrel file problems. Use when functions are too complex, files too long, or directory structure is problematic.
Detects and fixes code organization issues like high complexity, large files, deep nesting, and barrel file problems. Use when functions are too complex, files exceed 350 lines, or directory structure needs flattening.
/plugin marketplace add mgd34msu/goodvibes-plugin/plugin install goodvibes@goodvibes-marketThis skill inherits all available tools. When active, it can use any tool Claude has access to.
scripts/analyze-organization.jsscripts/find-large-files.jsFixes for code structure and organization issues. Well-organized code is easier to understand, test, and maintain.
| Issue | Priority | Impact |
|---|---|---|
| High complexity | P1 | Hard to test, prone to bugs |
| Large files (>350 lines) | P2 | Hard to navigate |
| Deep nesting (>5 levels) | P3 | Hard to find files |
| Barrel file issues | P3 | Import path problems |
Detection: complexity ESLint rule or manual review.
Pattern: Functions with many branches (if/else, switch, loops).
// PROBLEM - high cyclomatic complexity
function processOrder(order: Order): Result {
let result: Result;
if (order.type === 'standard') {
if (order.priority === 'high') {
if (order.items.length > 10) {
result = processBulkHighPriority(order);
} else {
result = processHighPriority(order);
}
} else {
result = processStandard(order);
}
} else if (order.type === 'subscription') {
// ... more nesting
}
return result;
}
Fix Strategy 1: Strategy Pattern with early returns.
// SOLUTION - strategy pattern
interface OrderProcessor {
canHandle(order: Order): boolean;
process(order: Order): Result;
}
const processors: OrderProcessor[] = [
new BulkHighPriorityProcessor(),
new HighPriorityProcessor(),
new StandardProcessor(),
new SubscriptionProcessor(),
];
function processOrder(order: Order): Result {
const processor = processors.find(p => p.canHandle(order));
if (!processor) {
throw new Error(`No processor for order type: ${order.type}`);
}
return processor.process(order);
}
Fix Strategy 2: Extract functions with guard clauses.
// SOLUTION - extracted functions with guards
function processOrder(order: Order): Result {
if (order.type === 'subscription') {
return processSubscription(order);
}
if (order.priority === 'high') {
return processHighPriorityOrder(order);
}
return processStandardOrder(order);
}
function processHighPriorityOrder(order: Order): Result {
if (order.items.length > 10) {
return processBulkHighPriority(order);
}
return processHighPriority(order);
}
Complexity Reduction Techniques:
| Technique | When to Use |
|---|---|
| Extract function | Repeated logic or distinct responsibility |
| Strategy pattern | Multiple variants of similar behavior |
| Early return | Reduce nesting depth |
| Lookup table | Replace switch/if-else chains |
| Polymorphism | Type-based branching |
Detection: File exceeds 350 lines.
Pattern: Single file with multiple responsibilities.
// PROBLEM - monolithic file
src/
orderService.ts (500 lines: types + validation + processing + API)
Fix Strategy: Extract by responsibility.
// SOLUTION - separated concerns
src/
orders/
types.ts (50 lines)
validation.ts (80 lines)
processing.ts (120 lines)
api.ts (100 lines)
index.ts (20 lines - barrel)
Extraction Guide:
| Content Type | Target Location |
|---|---|
| Type definitions | types.ts |
| Constants | constants.ts |
| Validation logic | validation.ts |
| Data transformation | transform.ts |
| API/IO operations | api.ts or client.ts |
| Business logic | service.ts or feature name |
| Utilities | utils/ directory |
File Size Guidelines:
Detection: Path depth exceeds 5 levels.
Pattern: Over-categorized directory structure.
// PROBLEM - too deep
src/
modules/
orders/
services/
processing/
handlers/
webhook/
stripe.ts (6 levels)
Fix Strategy: Flatten with descriptive names.
// SOLUTION - flattened
src/
orders/
webhook-handlers/
stripe.ts (3 levels)
Flattening Rules:
src/Feature-Based Structure:
src/
features/
authentication/
components/
hooks/
api.ts
types.ts
index.ts
orders/
components/
hooks/
api.ts
types.ts
index.ts
shared/
components/
utils/
types/
Issue #31: Barrel file with 0% test coverage.
Fix: Add export verification test.
// __tests__/index.test.ts
import * as exports from '../index';
describe('barrel exports', () => {
it('exports expected functions', () => {
expect(exports.processOrder).toBeDefined();
expect(exports.validateOrder).toBeDefined();
expect(typeof exports.processOrder).toBe('function');
});
it('does not export internal utilities', () => {
expect((exports as Record<string, unknown>)._internal).toBeUndefined();
});
});
Issue #34: Long re-export lists.
Fix: Group exports with comments.
// BEFORE - long list
export { a } from './a';
export { b } from './b';
// ... 30 more
// SOLUTION - grouped
// Types
export type { User, Order, Product } from './types';
// Services
export { UserService } from './services/user';
export { OrderService } from './services/order';
// Utilities
export { formatDate, formatCurrency } from './utils/format';
export { validate } from './utils/validation';
Pattern: Same logic repeated in multiple places.
// PROBLEM - duplicated in each hook
// pre-commit.ts
const results = await runChecks(stagedFiles);
if (results.failed) {
console.error(formatErrors(results.errors));
process.exit(1);
}
// pre-push.ts (same logic)
const results = await runChecks(changedFiles);
if (results.failed) {
console.error(formatErrors(results.errors));
process.exit(1);
}
Fix Strategy: Extract shared function.
// SOLUTION - shared runner
// hooks/runner.ts
export interface HookContext {
name: string;
files: string[];
checks: Check[];
}
export async function runHook(context: HookContext): Promise<void> {
const results = await runChecks(context.files, context.checks);
if (results.failed) {
console.error(`${context.name} failed:`);
console.error(formatErrors(results.errors));
process.exit(1);
}
console.log(`${context.name} passed`);
}
// pre-commit.ts
await runHook({
name: 'pre-commit',
files: stagedFiles,
checks: [lintCheck, typeCheck],
});
Pattern: Function with multiple overloads doing different things.
// PROBLEM - overloaded signatures
function getUser(id: string): Promise<User>;
function getUser(email: string, byEmail: true): Promise<User>;
function getUser(identifier: string, byEmail?: boolean): Promise<User> {
if (byEmail) {
return getUserByEmail(identifier);
}
return getUserById(identifier);
}
Fix Strategy: Split into separate well-named functions.
// SOLUTION - separate functions
async function getUserById(id: string): Promise<User> {
return database.users.findById(id);
}
async function getUserByEmail(email: string): Promise<User> {
return database.users.findByEmail(email);
}
When overloads are justified:
node scripts/analyze-organization.js /path/to/src
node scripts/find-large-files.js /path/to/src --max-lines 350
node scripts/check-depth.js /path/to/src --max-depth 5
Before extracting code:
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.