Esta página se muestra en inglés. Una traducción al español está en curso.
SkillsApr 8, 2026·3 min de lectura

Tidy First — AI Code Refactoring Skill for Agents

Skill teaching AI agents Kent Beck's Tidy First methodology. Make small structural improvements before behavior changes to keep codebases clean and maintainable over time.

Listo para agents

Instalación con revisión previa

Este activo requiere revisión. El prompt copiado pide dry-run, muestra escrituras y continúa solo tras confirmación.

Needs Confirmation · 66/100Política: confirmar
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Tidy First — AI Code Refactoring Skill for Agents
Comando con revisión previa
npx -y tokrepo@latest install 905bfdbf-dbb4-45e5-b3e3-601ab52d9ef1 --target codex

Primero dry-run, confirma las escrituras y luego ejecuta este comando.

TL;DR
Tidy First teaches AI agents to make small structural tidyings before behavioral changes, following Kent Beck's refactoring philosophy.
§01

What it is

Tidy First is an AI agent skill that encodes Kent Beck's refactoring methodology into a structured set of instructions for AI coding assistants. The core idea: before making a behavioral change to code, consider making small structural improvements first. These tidyings make the subsequent change easier, safer, and more readable.

The skill targets developers using AI coding agents like Claude Code or Cursor who want their agents to follow disciplined refactoring practices rather than making ad-hoc changes to messy code.

§02

How it saves time or tokens

Without the Tidy First discipline, AI agents tend to make behavioral changes directly into tangled code, producing patches that are hard to review and prone to regressions. By training the agent to tidy first, each change becomes two small, reviewable commits: one structural (renaming, extracting, reordering) and one behavioral (the actual feature or fix).

This separation reduces code review time, makes git history more meaningful, and prevents the accumulation of technical debt that eventually slows down entire teams.

§03

How to use

  1. Save the Tidy First skill as ~/.claude/skills/tidy-first/SKILL.md in your AI agent's skill directory.
  2. The skill activates automatically when the agent encounters code that would benefit from structural improvement before a behavioral change.
  3. The agent will propose tidyings first (extract function, rename variable, reorder declarations), then make the behavioral change in a separate step.
§04

Example

# Tidy First Skill

Before making behavioral changes, consider small structural tidyings.
Apply these patterns when code is messy:
§05

Tidying patterns

  • Guard clauses: replace nested if/else with early returns
  • Extract helper: pull repeated logic into a named function
  • Rename for clarity: make variable names reveal intent
  • Reorder declarations: group related code together
  • Remove dead code: delete unused functions and variables
§06

Workflow

  1. Read the code that needs changing
  2. Identify structural issues that make the change harder
  3. Apply 1-3 tidyings in a separate commit
  4. Make the behavioral change in a clean commit
§07

Related on TokRepo

§08

Common pitfalls

  • Over-tidying: the skill should apply 1-3 small tidyings before a change, not refactor the entire file. Scope discipline is critical.
  • Tidying without tests: structural changes can introduce subtle bugs. Ensure tests pass after each tidying commit before proceeding to behavioral changes.
  • Mixing tidying and behavior in one commit defeats the purpose. The value comes from separation -- one commit per concern.

Preguntas frecuentes

What is the Tidy First methodology?+

Tidy First is Kent Beck's approach to software design where you make small, safe structural improvements to code before making behavioral changes. The idea is that clean structure makes behavioral changes easier, cheaper, and less risky.

Which AI coding agents support this skill?+

The skill is formatted as a SKILL.md file compatible with Claude Code, and can be adapted for other AI coding tools that support skill or rule files such as Cursor (.cursorrules) or Gemini CLI.

How many tidyings should I make before a change?+

The recommended practice is 1-3 small tidyings. Each should take less than a minute to review. If you find yourself doing more than three, the code may need a dedicated refactoring effort rather than opportunistic tidying.

Does this replace comprehensive refactoring?+

No. Tidy First is about opportunistic, small structural improvements done right before a behavioral change. Large-scale refactoring efforts still have their place but are planned separately from feature work.

How does Tidy First affect code review?+

Code reviews become easier because each commit has a single purpose -- either structural improvement or behavioral change. Reviewers can verify structural tidyings quickly and focus their attention on the behavioral change.

Referencias (3)
🙏

Fuente y agradecimientos

Based on Kent Beck's "Tidy First?" (2023).

tidyfirst.substack.com — Kent Beck's newsletter

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados