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 the router directory, find the /api/users route, change its handler to query the database instead of returning hardcoded data, then run the tests, and commit if they pass.

After:

The /api/users route 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 ListUsers in internal/service/user.go with these constraints:

  1. Reduce time complexity below O(n)
  2. Keep the function signature unchanged
  3. 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
2
3
4
5
6
7
8
9
10
# Step 1: Analyze only, do not edit code
> Inspect internal/service/user.go (currently 800 lines).
> List the methods you think should be split out and propose a plan. Do not edit any code.

# Step 2: Update only the model layer after confirmation
> Following the plan above, extract the authentication methods into auth.go.
> Only modify the model layer—leave the API untouched—and make sure it compiles.

# Step 3: Update upper layers once the model changes are done
> Update the API layer and tests based on the new model. Make sure all tests pass.

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
2
3
4
5
6
7
8
9
10
# CLAUDE.md snippet
## Core Constraints
- Confirm before any irreversible action (deleting or overwriting unrecoverable content)
- Only do what was requested; never expand scope on your own
- Ask when uncertain—do not guess

## Post Guidelines
- Maximum 2 tags per post
- Always specify a language on fenced code blocks
- Auto commit + push after edits

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 config directory inside the file starting with db. There’s a connection pool setting max_open_conns—change it from 100 to 200.

Effective:

Change max_open_conns in config/db.go from 100 to 200.

Define Explicit Execution Boundaries

For risky changes, explicitly state what Claude is not allowed to touch:

1
2
3
> Add pagination to the user API.
> Constraints: only modify internal/handler/user.go and internal/service/user.go;
> do not touch the database schema or frontend.

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
2
3
4
5
6
7
8
9
10
11
12
13
# === Prompt Template ===
# [Goal] What you want done (one clear sentence)
# [Context] Relevant file paths and current state
# [Constraints] What must not change and what must hold
# [Reference] File or style to follow (optional)
# [Acceptance] Definition of done (tests passing? manual check?)

# === Concrete Example ===
# [Goal] Add pagination to the user list API
# [Context] ListUsers method in internal/handler/user.go
# [Constraints] Do not change the database schema; preserve the existing response format
# [Reference] Follow the ListOrders pagination implementation in internal/handler/order.go
# [Acceptance] Unit tests pass + manual check confirms the returned data is correct

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:

  1. Are there any vague words in my prompt? (“optimize,” “clean up,” and “make better” all count.)
  2. Did I make it clear what must not be touched?
  3. Is there an existing file I can point to as a reference?

Answer those three questions before sending, and your throughput will double.


Series Navigation