Show Claude the Expected Output and Let It Write the Code That Produces It
Sometimes the clearest way to specify what you want isn't describing the logic — it's showing the result. Paste the expected output into Claude and it reverse-engineers the code that produces it.
> write an API endpoint that returns this exact JSON structure:
>
> {
> "user": {
> "id": 42,
> "name": "Jane Smith",
> "plan": "pro",
> "usage": {
> "api_calls": 1547,
> "storage_mb": 234,
> "limit_percentage": 61
> },
> "recent_projects": [
> {"id": 1, "name": "Website Redesign", "updated_at": "2h ago"}
> ]
> }
> }
Claude reads the structure and writes the controller, query, resource/transformer, and any computed fields — matching the exact shape, nesting, and field names you specified. No ambiguity about what "usage data" means or how "recent" is defined, because the example makes it concrete.
This works for any kind of output:
> write a CLI command that produces this table:
>
> ┌──────────┬───────┬──────────┐
> │ Route │ Method│ Middleware│
> │ /users │ GET │ auth │
> │ /users │ POST │ auth,admin│
> └──────────┴───────┴──────────┘
> write an email template that renders like this:
> [paste the HTML or screenshot of the desired email]
> write a migration and model that lets me query data shaped like this:
> [paste the desired query result]
This approach is especially powerful for complex data transformations where describing the rules in English would be longer and less precise than just showing input and output:
> here's the raw data from the API:
> [paste raw response]
>
> transform it into this format for the frontend:
> [paste desired shape]
Claude reads both, figures out the mapping, and writes the transformation code — renaming fields, flattening nested structures, computing derived values, and formatting dates.
When the output is clear, the code writes itself — show Claude the destination and it builds the path.
via Claude Code
Log in to leave a comment.
Before jumping to implementation, describe the problem conversationally and let Claude be your thinking partner. It asks clarifying questions, surfaces tradeoffs you haven't considered, suggests approaches, and pokes holes in your plan — so by the time you say "ok, build it," both of you know exactly what to build and why.
Paste error messages with "why did this fail?" instead of "fix this" to get Claude to diagnose the root cause before applying a fix.
When you need Claude to make changes in one area without affecting another, add negative constraints — "fix the bug but don't change the public API", "refactor the internals but don't create new files", or "update the logic but don't modify any tests." Explicit exclusions prevent Claude from making well-intentioned changes you'll have to undo.