Agent skill

Refactor Large Function

by rajbos in rajbos/ai-engineering-fluency

Pick one large function flagged by ESLint max-lines-per-function and refactor it into smaller, focused helpers without breaking tests.

MITAuto-check passedDevelopment

Install Refactor Large Function

skills CLI
$ npx skills add rajbos/ai-engineering-fluency --skill refactor-large-function -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install rajbos/ai-engineering-fluency refactor-large-function --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/rajbos/ai-engineering-fluency.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/refactor-large-function .claude/skills/refactor-large-function && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
refactor-large-function
GitHub stars
115
Token cost
~1.3k tokens
SKILL.md length
605 words
Files
1
Skills in repo
22
Repo updated
First seen
Licence
MIT

At a glance

Pick one large function flagged by ESLint max-lines-per-function and refactor it into smaller, focused helpers without breaking tests.

  • Works in 9 steps: Identify the target → Read the instructions file → Understand the function → …
  • Tasks that involve Refactoring
  • SKILL.md covers Step 1 - Identify the target, Step 2 - Read the instructions…, Step 3 - Understand the function and Step 4 - Run the baseline tests, plus 6 more sections
  • Calls eslint, npm and node

What it does

Refactor Large Function is an agent skill from rajbos/ai-engineering-fluency. Pick one large function flagged by ESLint max-lines-per-function and refactor it into smaller, focused helpers without breaking tests.

Its SKILL.md is about 1.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Refactoring and Linting and formatting. It works with ESLint. The repository describes itself as: Extension that shows information about the estimated token usage and more of AI in editors/CLI's. The licence is MIT.

When your agent uses it

  • Tasks that involve Refactoring
  • Tasks that involve Linting and formatting

Example prompts

  • “/refactor-large-function”

Workflow steps

9 steps, taken from the step headings in SKILL.md.

  1. Identify the target
  2. Read the instructions file
  3. Understand the function
  4. Run the baseline tests
  5. Refactor
  6. Lint the changed file
  7. Run the full test suite and build
  8. Commit
  9. Open a PR

What it can do on your machine

Read from SKILL.md and the folder at commit 6933e2a. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • eslint
    • npm
    • node

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Refactor Large Function loads about 1.3k tokens when it runs. Until then it costs about 40 tokens; SKILL.md has 605 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~40
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from rajbos/ai-engineering-fluency at commit 6933e2a, republished under its MIT licence (© rajbos). 605 words, ~1,312 tokens.

Download SKILL.mdSave it as .claude/skills/refactor-large-function/SKILL.md (or your agent's skills folder).
name
refactor-large-function
description
Pick one large function flagged by ESLint max-lines-per-function and refactor it into smaller, focused helpers without breaking tests.

Refactor Large Function

An ESLint complexity or max-lines-per-function rule is producing warnings for functions that are too long. Pick one of those functions (not from extension.ts, which is intentionally monolithic) and refactor it into smaller, focused private helpers.

Step 1 - Identify the target

Run ESLint with the complexity rules to get the current list of violations:

bash
cd vscode-extension && node_modules/.bin/eslint src --rule '{"max-lines-per-function": ["warn", 80]}' --format stylish 2>&1 | grep "Lines/Fn\|max-lines-per-function" | head -20

Or, if the project already has the rule configured, just run:

bash
cd vscode-extension && node_modules/.bin/eslint src 2>&1 | grep "max-lines-per-function\|Lines/Fn" | head -20

Choose one function to refactor, following these priorities:

  1. Skip src/extension.ts - it is intentionally large and hard to test in isolation.
  2. Prefer files that already have unit tests (check test/unit/ for a matching test file).
  3. Among the remaining candidates, pick the one with the clearest logical sections (wizard steps, processing phases, format branches, etc.) - those decompose most cleanly.

Step 2 - Read the instructions file

Before touching any code, read the relevant sub-project instructions file. For vscode-extension/ work, read .github/instructions/vscode-extension.instructions.md.

Step 3 - Understand the function

Read the full function body and identify natural decomposition boundaries:

  • Wizard / multi-step UI flows: each step becomes a private method returning null on cancellation.
  • Format dispatch (e.g. JSONL vs JSON vs delta): each format branch becomes its own function.
  • Multi-phase processing: setup / main loop / finalization each become their own function.
  • Complex sub-operations inside a branch that push complexity above the threshold: extract them too.

Introduce small result interfaces or types at the top of the file (not exported) to carry data between steps cleanly, rather than long parameter lists.

Step 4 - Run the baseline tests

Before changing anything, compile and run the existing unit tests to establish a green baseline:

bash
cd vscode-extension
node_modules/.bin/tsc.cmd --noEmit          # type-check
npm run test:node                            # unit tests

Record which tests cover the target file so you know what to watch.

Step 5 - Refactor

Apply the extraction. Rules:

  • The public/exported API must not change - only internal structure changes.
  • Each extracted helper should have a single clear responsibility, stated in its name.
  • Private methods use a leading _ prefix to signal they are internal helpers.
  • Return null (not undefined) from a helper to signal user cancellation or an unrecoverable error; the caller does an early if (!result) { return; } guard.
  • Do not add new comments unless the code is genuinely non-obvious after extraction.
  • Keep new helpers in the same file unless they are independently reusable - do not create new files just to reduce line counts.
Show full SKILL.md (228 more words)Show less

Step 6 - Lint the changed file

bash
cd vscode-extension && node_modules/.bin/eslint src/path/to/changed-file.ts

All new warnings introduced by your changes must be resolved before proceeding. Pre-existing warnings on other functions in the same file are acceptable - do not fix unrelated code.

Step 7 - Run the full test suite and build

bash
cd vscode-extension
node_modules/.bin/tsc.cmd --noEmit          # type-check
npm run test:node                            # unit tests
node esbuild.js --production                # production bundle

All tests must pass and the build must succeed. If a test fails, fix the refactoring - do not modify the tests unless the test itself was wrong before your change.

Step 8 - Commit

Write a commit in this format:

refactor: extract <FunctionName> into focused private methods

<One or two sentences describing which logical sections were extracted
and why the split makes sense.>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Step 9 - Open a PR

Open a pull request to main. The PR description should:

  • Lead with the motivation (ESLint rule violation, cognitive overhead).
  • List the extracted helpers in a small table (method name | responsibility).
  • Confirm that all unit tests pass and the production build succeeds.
  • Note any pre-existing warnings that were not introduced by this change.

Constraints

  • Only modify the one source file being refactored (plus its test file if a test needs updating to import a newly-exported helper, which should be rare).
  • Do not fix pre-existing ESLint warnings on other functions in the same file.
  • Do not change any exported function signatures or public class method signatures.
  • Do not add new test files - rely on the existing test suite to verify correctness.
  • If tsc or unit tests fail after your change, revert and choose a different decomposition strategy rather than patching around the failure.

© rajbos, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/refactor-large-function of rajbos/ai-engineering-fluency.

Open the folder on GitHubat commit 6933e2a

Compare with similar skills

Refactor Large Function next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Refactor Large Function compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Refactor Large Function this skillrajbos/ai-engineering-fluency115—~1.3kAutomated safety check: PassMIT
Fantasia Two Level Architecturevishiri/fantasia-archive409—~983Automated safety check: PassGPL-3.0
Sonarjsmanagedcode/dotnet-skills486—~1.6kAutomated safety check: PassMIT
Same Results Less Codepproenca/dot-skills214—~3kAutomated safety check: PassMIT
Rust Best Practicesfarm-fe/farm5.6k3 repos~1.1kAutomated safety check: PassMIT
LobeHub Alint Rule Set Maintenancelobehub/lobehub83k—~1.9kAutomated safety check: PassCustom licence

Similar skills

  • Fantasia Two Level Architecture

    vishiri/fantasia-archive

    Migrates Fantasia Archive features to two-level functions + managers layout: pure scripts/functions/, manager.ts wiring (underscore suffix, e.g.

    409 GitHub stars~983 tokensUpdated 5 days ago
    DevelopmentAuto-check passed
  • Sonarjs

    managedcode/dotnet-skills

    Use SonarJS-derived rules in .NET repositories that ship JavaScript or TypeScript frontends and need deeper bug-risk, code-smell, or cognitive-complexity checks than a minimal ESLint baseline.

    486 GitHub stars~1.6k tokensUpdated today
    DevelopmentAuto-check passed
  • Same Results Less Code

    pproenca/dot-skills

    Same behaviour in fewer, clearer lines — covers the judgment gaps that linters cannot catch (reinvention, wrong frame, hidden duplication, derived state, procedural rebuilds, speculative generality…

    214 GitHub stars~3k tokensUpdated 1 mo ago
    DevelopmentAuto-check passed
  • Guide for writing idiomatic Rust code based on Apollo GraphQL's best practices handbook.

    5.6k GitHub starsUsed in 3 repos~1.1k tokens
    DevelopmentAuto-check passed
  • Maintains LobeHub's model-backed alint rule set: writing rules, removing false positives against real code, deciding warn versus error and tracking token cost.

    83k GitHub stars~1.9k tokensUpdated today
    DevelopmentAuto-check passed
  • Ultracite

    agustinusnathaniel/nextarter-tailwind

    Ultracite is a zero-config linting and formatting preset for JavaScript/TypeScript projects.

    125 GitHub starsUsed in 2 repos~1.2k tokens
    DevelopmentAuto-check passed

More from rajbos/ai-engineering-fluency

All 22 skills in this repo
  • Check Urls

    rajbos/ai-engineering-fluency

    Find all hardcoded URLs in TypeScript source files and verify they resolve (return HTTP 2xx/3xx).

    115 GitHub stars~662 tokensUpdated yesterday
    Auto-check passed
  • Create Issue

    rajbos/ai-engineering-fluency

    Create a well-scoped GitHub issue in this repo. An agent skill from rajbos/ai-engineering-fluency.

    115 GitHub stars~2k tokensUpdated yesterday
    Auto-check passed
  • Deduplicate Code

    rajbos/ai-engineering-fluency

    Detect copy-pasted code blocks across the shared source (vscode-extension/src, the repo-root src/, cli/src) with the dependency-free check-code-duplication.js detector, then pick one duplicate group…

    115 GitHub stars~2.4k tokensUpdated yesterday
    Auto-check passed
  • Improve Tool Families

    rajbos/ai-engineering-fluency

    Analyze coverage of the vscode-extension's tool-family definitions (DEFAULTTOOLFAMILIES in vscode-extension/src/toolFamilies.ts) against the canonical tool-name list in src/toolNames.json and/or a…

    115 GitHub stars~1.3k tokensUpdated yesterday
    Auto-check passed
  • Load Cache Data

    rajbos/ai-engineering-fluency

    Load and display the last 10 cache entries as raw JSON output.

    115 GitHub stars~3.2k tokensUpdated yesterday
    Auto-check passed
  • PR Risk Review

    rajbos/ai-engineering-fluency

    Assess the risk of a changeset (a PR, a branch, or the working tree) and classify it as low, medium, or high with a written rationale.

    115 GitHub stars~2.6k tokensUpdated yesterday
    Auto-check passed

Works with

Categories

Questions about Refactor Large Function

What does Refactor Large Function do?

Pick one large function flagged by ESLint max-lines-per-function and refactor it into smaller, focused helpers without breaking tests. Refactor Large Function is an agent skill from rajbos/ai-engineering-fluency. Pick one large function flagged by ESLint max-lines-per-function and refactor it into smaller, focused helpers without breaking tests.

When should I use Refactor Large Function?

Refactor Large Function fits situations like: tasks that involve Refactoring; tasks that involve Linting and formatting.

How do I install Refactor Large Function in Claude Code?

Run `npx skills add rajbos/ai-engineering-fluency --skill refactor-large-function -a claude-code`. Or copy the skill folder (.claude/skills/refactor-large-function in rajbos/ai-engineering-fluency) into .claude/skills/refactor-large-function in your project. Claude Code loads it when a task matches its description.

How do I install Refactor Large Function in Codex?

Run `npx skills add rajbos/ai-engineering-fluency --skill refactor-large-function -a codex`. Or copy the skill folder (.claude/skills/refactor-large-function in rajbos/ai-engineering-fluency) into .agents/skills/refactor-large-function in your project. Codex loads it when a task matches its description.

Can I use Refactor Large Function in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add rajbos/ai-engineering-fluency --skill refactor-large-function -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/refactor-large-function, .gemini/skills/refactor-large-function, .github/skills/refactor-large-function and .opencode/skills/refactor-large-function in your project.

What does Refactor Large Function need to run?

Going by SKILL.md and its folder, Refactor Large Function needs the command-line tools its instructions call (eslint, npm and node).

Does Refactor Large Function access the network?

SKILL.md contains no URLs. Its commands use npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Refactor Large Function safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Refactor Large Function use?

Refactor Large Function is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Refactor Large Function use?

About 1.3k tokens (SKILL.md is roughly 5.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Refactor Large Function?

Skills that share tags, products or a category with Refactor Large Function: Fantasia Two Level Architecture (vishiri/fantasia-archive, 409 stars), Sonarjs (managedcode/dotnet-skills, 486 stars), Same Results Less Code (pproenca/dot-skills, 214 stars) and Rust Best Practices (farm-fe/farm, 5.6k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Refactor Large Function?

rajbos (a GitHub user) maintains it in rajbos/ai-engineering-fluency, which has 115 GitHub stars. The repository holds 22 skills in this directory. The repository was last updated on October 6, 2026.

Source: rajbos/ai-engineering-fluency on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.