CLAUDE CODE AGENTS: FUNDAMENTALS - Chapter 5, Exercise 2 Rewriting "Clean Up the Payment Module" as a Well-Scoped Brief ==================================================================================== QUESTION: Rewrite the brief "clean up the payment module" into a well-scoped coding-agent brief, including acceptance criteria and an explicit boundary on what shouldn't change. SOLUTION / EXPLANATION: "Clean up the payment module" fails this chapter's own requirements on every count: it names no specific target within the module, gives no acceptance criteria (there's no way to know when "clean" has been achieved), and sets no boundary on what should stay untouched - exactly the kind of open-ended request this chapter's tip box warns can lead a coding agent to "improve" things nearby that were never actually part of the request. A well-scoped rewrite: "In src/payments/processor.ts, the function chargeCustomer has three levels of nested if/else handling different payment provider error codes. Refactor this specifically into a single switch statement (or an equivalent lookup-based dispatch) on the error code, to make the branching logic easier to follow. Acceptance criteria: the existing test suite in src/payments/processor.test.ts must still pass unchanged, and the function's public signature and return behavior must stay exactly the same. Do not touch any other function in this file, do not change the payment provider API calls themselves, and do not add new error codes or handling not already present." This satisfies every element the chapter calls for: a specific named target (chargeCustomer's nested conditional structure, not the whole module), concrete acceptance criteria (the existing tests still pass, the public behavior is unchanged), and explicit boundaries (only this one function, nothing else in the file, no new functionality added). This gives the coding agent a task it can actually complete and be verified against, rather than an open-ended invitation to reorganize the module however it sees fit. -------------------------------------------------------------------------- WHY THIS WORKS AS AN ANSWER: It doesn't just rephrase "clean up" more politely - it supplies a specific target, genuine acceptance criteria (tests passing, unchanged behavior), and an explicit scope boundary, directly addressing each gap the original vague brief had per this chapter's own requirements.