Rzemiosło · The Craft
What is The CraftLevelsGet startedChapters Search Download PLEN
Level 3 · Codex ~2 min read

In one sentence: When it’s worth building a skill, and when to refactor — and how to do it without breaking working code.

This chapter in plain terms

A chapter about two habits that keep code in check.

Skills are saved “recipes” for repeatable actions that the assistant runs with one command (e.g. /run-tests). You build a skill when you do something at least three times, or when the order of steps is easy to get wrong — then the AI doesn’t guess, it runs a proven procedure. (Mind the difference: a skill is a recipe for the assistant; a Hook — Automation in the tool’s configuration that always fires on a specific event (e.g. after a file edit). Anything that must happen “always after something” shouldn’t depend on the assistant remembering. more in the glossary → is an automation run by the tool — “from now on always do X after Y” is a hook, not a skill.)

Refactoring is tidying code without changing what it does — and it has its discipline: write so the code “reads like the code next to it”; don’t mix cleanup with a new feature in one Commit — A saved, labelled point in the project’s history — a confirmation of a specific batch of changes. Small, described commits make a history you can return to any working state from. more in the glossary → (easier to undo then); first check whether the thing already exists somewhere (reuse before rewriting); work in small steps with green tests.

There’s also SOLID — Five code design principles (single responsibility, open for extension, substitutability, narrow interfaces, dependency inversion). They help keep the next change cheap — applied in proportion, not as a cult. more in the glossary → — five design principles, but treated not as dogma, rather as five tests: will the change be cheap? Without overdoing it the other way: five layers of abstraction for a simple form is also a mistake.

Example: moving files into new folders? Leave “redirects” (shims) from the old paths, so other people’s calls still work — you don’t break the entry points other code relies on.

Read more: the SOLID principles · refactoring · slash commands in Claude Code.

02 — Skills and refactoring

Commandments I and X: automate what repeats; refactor so the code reads like its neighbor.

Skills (slash-commands)

  1. Build a skill when a procedure repeats (≥3 times), its order is easy to get wrong (Migration (database) — A controlled change to the database layout — adding a column, a table or moving data — step by step. Like a renovation to plan: rebuilding data in a set order so nothing “collapses”. more in the glossary →: number → SQL — The query language for a database — the way you “ask” the database for data or change it. The universal standard for talking to a database. A badly written query can bog down the whole app. more in the glossary → → apply → AI_README — A map file in every code directory: what’s here, what it’s for and what to watch out for — written for search. The assistant finds the right file with one search instead of reading the whole directory. more in the glossary → → Commit — A saved, labelled point in the project’s history — a confirmation of a specific batch of changes. Small, described commits make a history you can return to any working state from. more in the glossary →), or it carries a project-specific gotcha (PYTHONIOENCODING=utf-8 on Windows, --runInBand while a server runs).
  2. A skill has an output contract (exit 0 = green, otherwise what failed) and prints anything destructive it does.
  3. A skill is a recipe for the agent; a Hook — Automation in the tool’s configuration that always fires on a specific event (e.g. after a file edit). Anything that must happen “always after something” shouldn’t depend on the assistant remembering. more in the glossary → is automation run by the harness. “Always do X after Y” = a hook in config, not a skill and not a memory.
  4. Starter set: /run (server + smoke), /run-tests, /update-ai-readme, /add-migration (relational DB).

Refactoring

  1. Search for prior art first (git log -S, git blame) — an “ugly” shape often has a reason.
  2. Refactor separately from a behavior change — one commit is either cleanup or a feature.
  3. Reuse before rewrite — check whether the helper already exists.
  4. Keep old entry points working on structural moves (re-exporting shims), or update every caller in the same change.
  5. Small verified steps: refactor → tests green → commit.
  6. Apply SOLID — Five code design principles (single responsibility, open for extension, substitutability, narrow interfaces, dependency inversion). They help keep the next change cheap — applied in proportion, not as a cult. more in the glossary → proportionally: one reason to change per module; extend behind a flag rather than editing a hot path (→ 12); no abstraction before the second concrete case.
  7. Two review modes, never mixed: simplification (reuse, clarity) vs correctness (adversarial bug-hunt).

Anti-patterns

  • 🚫 A skill for something done once.
  • 🚫 A skill that silently runs something destructive.
  • 🚫 A big-bang rewrite after which nobody can say what broke.
  • 🚫 Five layers and a factory for a three-field CRUD.
Chapter deep-dive 02Why these rules, examples and stories from projects — what the core deliberately leaves out.

The canonical doctrine is written in English.