agentleFS
SrejonKhanSrejonKhan/agent-skills/skills/optimize_codebase/SKILL.md

optimize_codebase

Skill3 starsChanged 2 months agoMITView on GitHub

Identifies and refactors monolithic files (>2k lines) into modular, performance-safe component structures.

1 other project uses a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 7 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill to clean up technical debt by checking for massive source files and logically breaking them down.

    line 8
  2. Very specific:

    Use list_dir to see file sizes.

    line 17
  3. Very specific:

    Use view_file_outline to understand structure before splitting.

    line 18
  4. Very specific:

    Use write_to_file to create new modular files.

    line 19
  5. Distinctive:

    Architecture Debt: Look for missing abstractions, circular dependencies, and feature envy.

    line 29
  6. Distinctive:

    Testing Debt: Check for untested critical paths or brittle, environment-dependent tests.

    line 30
  7. Distinctive:

    Before touching any code, propose a strategy:

    line 35
  8. Very specific:

    Target Folder: Create a new directory named after the monolithic file (e.g., app.js -> app/).

    line 37
  9. Very specific:

    Entry Point: Create an index file (or keep the original filename as a shell) that imports and aggregates the new modules, preserving the …

    line 44
  10. Distinctive:

    Integrity: Ensure all imports are resolved.

    line 49
  11. Distinctive:

    Functionality: Run existing tests or walk through the critical path to ensure nothing broke.

    line 50
  12. Distinctive:

    Performance: verify that splitting the file didn't introduce significant load overhead (e.g., excessive network requests in a web context …

    line 51

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Optimize Code Base

Use this skill to clean up technical debt by checking for massive source files and logically breaking them down.

Inputs

  • Scope: The directory to scan.
  • Threshold: Line count limit (Default: 2000).

Tooling Strategy

  • Use list_dir to see file sizes.
  • Use view_file_outline to understand structure before splitting.
  • Use write_to_file to create new modular files.

Workflow

1. Analysis (The "Weigh-in")

  • Scan: Identify files in the relevant scope (HTML, Python, JS, etc.) that exceed 2,000 lines.
  • Assess: correct functionality is paramount. Does this file need to be this big (e.g., a generated asset), or is it just technical debt?
  • Comprehensive Tech Debt Scan:
    • Code Debt: Identify duplicated code (copy-paste), high cyclomatic complexity (>10), deeply nested conditionals (>3 levels), and long methods (>50 lines).
    • Architecture Debt: Look for missing abstractions, circular dependencies, and feature envy.
    • Testing Debt: Check for untested critical paths or brittle, environment-dependent tests.
    • Impact Assessment: Quantify the cost (e.g., "Developer velocity is impacted by changing this logic in 5 places").

2. The Refactoring Plan

Before touching any code, propose a strategy:

  • Target Folder: Create a new directory named after the monolithic file (e.g., app.js -> app/).
  • Modules: Identify distinct logical blocks (classes, helper functions, distinct UI sections) that can be extracted.
  • Dependencies: Map out how these new modules will import/export to each other to avoid circular dependencies.

3. Execution (The "Split")

  • Create Modules: Move code into smaller, purpose-built files.
  • Entry Point: Create an index file (or keep the original filename as a shell) that imports and aggregates the new modules, preserving the original external API.
  • Constraint: Do not change the logic. This is a refactor, not a rewrite.

4. Verification

  • Integrity: Ensure all imports are resolved.
  • Functionality: Run existing tests or walk through the critical path to ensure nothing broke.
  • Performance: verify that splitting the file didn't introduce significant load overhead (e.g., excessive network requests in a web context without bundling).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.