Workflow Refactoring

Extract a Function

Workflow for safely extracting code into a reusable function

refactoringfunctionsmodularity
CLAUDE.md

When extracting code into a function:

  1. Identify the block of code to extract. It should have a single, clear purpose.
  2. Verify the code block has tests covering its behavior. If not, add tests first.
  3. Identify all inputs the block needs (parameters) and its output (return value).
  4. Create the new function with a descriptive name, clear parameters, and return type.
  5. Replace the original code block with a call to the new function.
  6. Run the tests to verify behavior is unchanged.
  7. Check if the extracted function is called from anywhere else — if so, replace those copies too.

Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.

get crystl