How to Direct Claude Code: Practical Prompting Techniques
Once, I asked Claude Code to “optimize the config files.” It rewrote both _config.yml and _config.butterfly.yml from scratch—reformatting everything, stripping comments, and even changing the theme palette. One glance at the local preview and the entire site’s layout was broken. After reverting, I thought about what went wrong: the root cause wasn’t Claude’s capability—it was my vague task specification.
The core mindset boils down to one sentence: talking to Claude Code isn’t chatting—it’s delegating a task to an agent. Chat can be ambiguous; a task spec must be crisp. Once you internalize that mental model, everything else is just technique.
Four Core Principles
Principle 1: State the Goal, Not the Steps
Claude is an executor with judgment, not a script runner that blindly follows step-by-step commands. Telling it what you want works far better than micromanaging how to do it.
Before:
First read
main.go, then inspect therouterdirectory, find the/api/usersroute, change its handler to query the database instead of returning hardcoded data, then run the tests, and commit if they pass.
After:
The
/api/usersroute currently returns hardcoded data. Update it to query the database instead, and commit once existing tests pass.
The revised prompt is shorter yet carries clearer signal. Claude knows how to read files, locate the route, edit the code, and run tests on its own—you don’t need to walk it through every step.
Principle 2: Add Constraints, Not Just Descriptions
Saying “make it better” says nothing at all. Define explicitly what “better” means.
Before:
Optimize this function.
After:
Optimize
ListUsersininternal/service/user.gowith these constraints:
- Reduce time complexity below O(n)
- Keep the function signature unchanged
- Preserve existing tests
Three concrete constraints (performance target, stable interface, test compatibility) beat a vague “optimize” every time.
Principle 3: Provide a Reference Instead of Starting from Scratch
If you already have a pattern in mind, pointing Claude to a reference file is 10x faster than describing it in prose.
Before:
Write an error-handling middleware that catches panics, returns a JSON error response, and logs the error.
After:
Following the style of
internal/middleware/auth.go, write an error-handling middleware that catches panics, returns a JSON error response, and logs the error.
Just adding “following the style of auth.go“ eliminates paragraphs of explanation about naming conventions, package layout, and error-code formats.
Principle 4: Break Complex Tasks into Stages
Three small prompts beat one giant prompt—not because Claude can’t handle long inputs, but because staged execution lets you inspect results and steer course at every checkpoint.
Take “refactor the user module” and split it into three steps:
1 | # Step 1: Analyze only, do not edit code |
Quick-Reference Cheat Sheet
Scan these four rules before writing your next prompt.
| Principle | Instinctive Prompt | Better Prompt | Key Benefit |
|---|---|---|---|
| State the goal, not steps | “Read file A, check file B, find function C, and change it to D” | “Function C currently does X; change it to do Y” | Claude plans the path itself and misses fewer details |
| Add constraints, not descriptions | “Optimize this” | “Optimize without changing the signature; keep all tests passing” | Sets clear boundaries and prevents over-editing |
| Give a reference, don’t start blank | “Write middleware that catches panics and returns JSON” | “Following auth.go, write error-handling middleware” |
Inherits code style and project conventions automatically |
| Split complex tasks | “Refactor the entire user module” | Analyze first → refactor model → update API | Lets you verify and course-correct at every step |
Advanced Techniques for Sharper Prompts
Persist Reusable Constraints in CLAUDE.md
Repeating the same constraints in every prompt gets old fast. Put project-wide rules in CLAUDE.md so Claude loads them automatically on every session. Here is a snippet from my blog repo:
1 | # CLAUDE.md snippet |
Now whenever you say “write a post,” Claude enforces these rules automatically without you repeating them in the prompt.
Reference Files Directly Instead of Describing Them
Don’t describe where code lives or what it looks like—point Claude straight to the file:
Inefficient:
My database config is in the
configdirectory inside the file starting withdb. There’s a connection pool settingmax_open_conns—change it from 100 to 200.
Effective:
Change
max_open_connsinconfig/db.gofrom 100 to 200.
Define Explicit Execution Boundaries
For risky changes, explicitly state what Claude is not allowed to touch:
1 | > Add pagination to the user API. |
An allowlist-style boundary is far more effective than saying “be careful.”
Universal Prompt Template (Copy & Paste)
In day-to-day work, most prompts fit this structure:
1 | # === Prompt Template === |
You don’t need every field every time, but put the goal on the first line and constraints right after. Build that habit and you will see a clear jump in Claude Code’s output quality.
Good prompting comes down to three things: state the goal, draw the boundaries, and supply enough context. Before sending your next Claude Code prompt, spend 10 seconds on three checks:
- Are there any vague words in my prompt? (“optimize,” “clean up,” and “make better” all count.)
- Did I make it clear what must not be touched?
- Is there an existing file I can point to as a reference?
Answer those three questions before sending, and your throughput will double.




