Dev.to · 4 min read

6 Ways to Get Dramatically Better Results From Claude

6 Ways to Get Dramatically Better Results From Claude

Some developers treat Claude like autocomplete: paste some code, get some code back, iterate blindly. The gap between a mediocre response and a genuinely great one usually isn't the model — it's how you're prompting it. Here are six concrete techniques, each with a real before/after you can use in the API, Claude Code, or claude.ai. 1. Give explicit success criteria, not just a task Vague prompts get vague code, because Claude has to guess what "done" means — and it'll guess conservatively. Before: "Write a function to validate emails." After: Write a TypeScript function `validateEmail(input: string): boolean`. Requirements: - RFC 5322-compatible, but reject addresses without a TLD - No external dependencies - Include 3 unit tests covering valid, invalid, and edge cases (e.g. plus-addressing) Now you get a function that matches your actual constraints instead of a generic regex you have to rewrite anyway. 2. Wrap code and context in XML tags When a prompt mixes instructions with pasted source, Claude can blur which is which — especially in long files. Tags remove the ambiguity. [paste file contents] TypeError: Cannot read properties of undefined (reading 'userId') Using only the file above, find the line that causes this error and explain why. This is also how you should structure multi-file context: one block per file, each labeled with its path. 3. Ask for a plan before code on nontrivial tasks For anything beyond a one-liner — a new feature, a refactor, a tricky bug — ask Claude to reason through the approach before writing code. This surfaces bad assumptions before they're baked into 200 lines. Before: "Add caching to this API endpoint." After: "Before writing code, outline your approach to caching this endpoint: what to cache, invalidation strategy, and where the cache lives. Then implement it." You catch a wrong assumption ("cache the whole response" when only one field is expensive) at the plan stage, not the PR review stage. 4. Use few-shot examples to lock in your code style If you want Claude's output to match your codebase's conventions, show it a pattern instead of describing it. Before: "Write an error handler for this endpoint." After: Follow this existing pattern from our codebase: export const getUser = async (req, res) => { try { const user = await db.users.find(req.params.id); if (!user) return res.status(404).json({ error: 'not_found' }); return res.json(user); } catch (e) { return res.status(500).json({ error: 'internal_error' }); } }; Now write `getOrder` following the exact same structure and error shape. One good example saves you a round trip of "actually, use our error format." 5. Chain big tasks instead of one mega-prompt Asking for an entire feature in one shot tends to produce something shallow or inconsistent. Splitting into stages — plan, implement, review, fix — gets a stronger result because each step has one job. Before: "Build a rate limiter for our API." "Propose 2-3 rate-limiting strategies for a Node/Redis stack, with tradeoffs." "Implement the sliding-window approach as Express middleware." "Review this middleware for race conditions and edge cases." "Fix the issues you found." Each step is easy to verify on its own, which is exactly why the end result holds together. 6. Manage context deliberately (especially in Claude Code) Long agentic sessions degrade when context fills with irrelevant history — a fix for bug A that's still sitting in context while you debug unrelated bug B. Fix: run /clear between unrelated tasks in Claude Code instead of continuing the same thread. Fix: if you've corrected Claude twice on the same issue and it's still wrong, /clear and write a better initial prompt with what you learned, rather than correcting a third time. For instructions that should apply to every session (coding conventions, test commands, directory layout), put them in a CLAUDE.md file instead of repeating them in every prompt. The takeaway None of this is a magic prompt template — it's giving Claude the same things you'd give a new teammate: clear requirements, relevant context, your existing patterns, and room to think before acting. Try one of these on your next prompt and see how much less cleanup you have to do afterward.

This is a summary aggregated from Dev.to. Read the complete article on the original site:

Read full article at Dev.to

More AI & Machine Learning News