Show Claude the Expected Output and Let It Write the Code Backward
Describing what code should do is harder than showing what it should produce. When you have a clear picture of the output, show Claude the example and let it reverse-engineer the implementation.
"Write an API endpoint that returns this JSON:
{
'user': { 'id': 1, 'name': 'Jane', 'plan': 'pro' },
'usage': { 'api_calls': 1247, 'limit': 5000, 'reset_date': '2024-04-01' },
'features': ['analytics', 'webhooks', 'custom-domains']
}"
Claude reads the structure, figures out where the data comes from in your codebase, and writes the endpoint — controller, route, resource/transformer, and any queries needed to assemble that response.
This works for any kind of output:
# CLI tool output
"Write a command that produces output like this:
┌──────────┬────────┬─────────┐
│ Service │ Status │ Latency │
├──────────┼────────┼─────────┤
│ Database │ ✓ up │ 2ms │
│ Redis │ ✓ up │ 1ms │
│ S3 │ ✗ down │ timeout │
└──────────┴────────┴─────────┘"
# Email template
"Write the code that generates an email that looks like this:
[paste the HTML or text you want]"
# Log format
"Write a logging middleware that produces lines like:
[2024-03-15 14:30:22] GET /api/users 200 45ms user_id=123"
# Data transformation
"Write a function that takes this input:
[paste input]
And produces this output:
[paste output]"
For complex transformations, give multiple input/output pairs:
"Write a function where:
- Input: 'john.doe@example.com' → Output: 'JD'
- Input: 'alice.wonderland@test.io' → Output: 'AW'
- Input: 'bob@company.com' → Output: 'B'"
Claude infers the pattern from your examples and writes the function — including edge cases you might not have thought of.
When you know what the output should look like, showing is faster than telling — Claude works backward from examples better than forward from descriptions.
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.