Go from never having used a coding agent to working productively and safely with one. The learner should understand what an agent is and how it differs from a chat assistant. They should choose a tool, set up a protected first project, describe tasks the agent can do well, and follow and verify its work. They should recover from bad changes, manage context, and plan bigger changes. They should also use tests as the definition of done and run everyday workflows (bug fixes, features, writing tests, codebase exploration, scripts, small tools, refactors). Throughout, they should keep secrets and systems safe and keep their own understanding growing instead of outsourcing it.
Workflow: refactoring safely with an agent card 3 of 6

The safe refactor checklist

builds on: Workflow: having the agent write tests, Tests as the definition of done, Doing a bigger change plan-first, step by step, Branches for risky or alternative attempts
1. Start from a clean state on a new branch. 2. **Pin behaviour first.** Have the agent add tests for what the code does *now*, odd cases included. Check that each one would fail if the code broke. Commit them: this is the pinning commit. 3. Refactor in small steps, one move each (say, one rename or one extracted function). After each step, run the tests, read the diff and commit. 4. In the prompt, forbid edits to tests and to the **public interface**: the names, parameters and return values that other code calls. 5. At the end, diff `tests/` against the pinning commit (expect nothing). Then check that no public function's definition changed.
Terms on this card
refactor
Changing how code is organised (names, structure, splitting functions) without changing what it does for anyone using it.
public interface
The parts of code other code relies on: function names, their parameters and what they return. Changing them can break callers.
Pin behaviour
Writing tests that record exactly what the code does now, odd results included, so any later change in behaviour makes a test fail.
pinning commit
The commit that saves the pinning tests before any refactor step. Later checks compare against it.
clean state
`git status` shows no uncommitted changes, so everything new afterwards is clearly the agent's work.
Learn this step by step on Bytewise
Lesson goal: Refactor safely by making sure tests cover the behaviour first, then asking for behaviour-preserving changes in small committed steps on a branch. Check that no test or public interface was quietly changed. · the whole lesson