Skip to content
enforce-file-limits logo

File Size Limits Enforcement

enforce-file-limits

Enforce 500-line file size limits. Warn at 400 lines. Guide splitting large files into focused modules. Apply when writing or editing code.

SKILL.md

Full skill instructions

File Size Limits Enforcement

CRITICAL: All files MUST stay under 500 lines. This is NON-NEGOTIABLE.

Why This Exists

Large files are:

  • Hard to navigate
  • Hard to test
  • Hard to maintain
  • Easy to violate Single Responsibility Principle

When to Apply

Use this skill when:

  • Creating new files
  • Editing existing files
  • Reviewing code
  • Splitting large files

How It Works

Line Limits

  • Hard limit: 500 lines (WILL BE REJECTED)
  • Warning threshold: 400 lines (PLAN TO SPLIT)
  • Optimal range: 200-300 lines

What Counts as Lines

Count EVERYTHING:

  • Code lines
  • Comment lines (including block comments)
  • Blank lines
  • Import statements
  • Type definitions

The only exception: File header comments (first 1-5 lines describing the file).

Checking Current File Size

Before editing, check line count:

wc -l path/​to/​file.ts

If output shows > 400 lines, plan to split BEFORE adding more code.

Splitting Strategies

1. Extract Utilities
// ❌ BEFORE: UserService.ts (550 lines)
class UserService {
  validateEmail() { /​* 50 lines */ }
  hashPassword() { /​* 50 lines */ }
  generateToken() { /​* 50 lines */ }
  createUser() { /​* 400 lines */ }
}

// ✅ AFTER: Split utilities
// utils/​userValidation.ts (50 lines)
export function validateEmail() {}

// utils/​passwordUtils.ts (50 lines)
export function hashPassword() {}

// utils/​tokenGenerator.ts (50 lines)
export function generateToken() {}

// UserService.ts (400 lines)
class UserService {
  createUser() { /​* uses imported utilities */ }
}
2. Extract Sub-Services
// ❌ BEFORE: UserService.ts (600 lines)
class UserService {
  // User CRUD (200 lines)
  // Password management (200 lines)
  // Profile management (200 lines)
}

// ✅ AFTER: Split by domain
// UserService.ts (200 lines)
// UserPasswordService.ts (200 lines)
// UserProfileService.ts (200 lines)
3. Extract Component Logic
// ❌ BEFORE: Dashboard.tsx (550 lines)
export function Dashboard() {
  // State management (100 lines)
  // Data fetching logic (100 lines)
  // Event handlers (100 lines)
  // Render multiple sections (250 lines)
}

// ✅ AFTER: Split into focused components
// Dashboard.tsx (200 lines) - main component
// hooks/​useDashboardData.ts (100 lines) - data fetching
// components/​DashboardStats.tsx (150 lines)
// components/​DashboardCharts.tsx (150 lines)

When File Approaching 400 Lines

STOP and plan extraction BEFORE adding more code:

  1. Identify logical boundaries (utilities, sub-domains, components)
  2. Create new files with descriptive names
  3. Move code to new files
  4. Update imports
  5. Verify tests still pass

Handling Large Files in Codebase

If you encounter a file > 500 lines:

  1. Flag it immediately: "⚠️ This file exceeds 500 lines and needs refactoring"
  2. If editing: Plan split BEFORE making changes
  3. If creating new feature: Don't add to large files - create new focused files instead

Examples

Good: Properly Sized Files

src/​features/​auth/
├── services/
│   ├── AuthService.ts (280 lines) ✅
│   ├── TokenService.ts (180 lines) ✅
│   └── PasswordResetService.ts (220 lines) ✅

Bad: Oversized Files

src/​features/​auth/
└── services/
    └── AuthService.ts (850 lines) ❌ MUST SPLIT!

Refactoring Large Files

// BEFORE: AuthService.ts (850 lines) ❌
class AuthService {
  // Login logic (200 lines)
  // Registration logic (200 lines)
  // Password reset logic (200 lines)
  // Token management (150 lines)
  // Email verification (100 lines)
}

// AFTER: Split into focused services ✅
// AuthService.ts (200 lines)
class AuthService {
  login() {}
  logout() {}
}

// RegistrationService.ts (200 lines)
class RegistrationService {
  register() {}
  verifyEmail() {}
}

// PasswordService.ts (200 lines)
class PasswordService {
  resetPassword() {}
  changePassword() {}
}

// TokenService.ts (150 lines)
class TokenService {
  generateToken() {}
  validateToken() {}
  refreshToken() {}
}

Enforcement

The code-quality-auditor will:

  • ✅ Check file line counts
  • ✅ Reject files > 500 lines
  • ✅ Warn on files > 400 lines
  • ✅ Suggest split strategies

Quick Checklist

  • File is under 500 lines (hard limit)
  • File is under 400 lines (warning threshold)
  • If approaching 400, plan extraction
  • Large files have been split before editing
  • New code added to focused files, not large files

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View