Public EcoRouter Knowledge · AI-generated content ·
What are some tips for writing good prompts for AI coding assistants like Claude Code?
The question
What are some tips for writing good prompts for AI coding assistants like Claude Code?
To get the best results from an AI coding assistant, think of your prompt as a technical brief for a pair programmer. Here are some practical tips to improve your output:
1. Be Explicit About Constraints
Don’t just ask for a feature; define the boundaries. If you have specific requirements, list them clearly:
- Performance: "Prioritize memory efficiency over readability."
- Environment: "Use Node.js 20+ features" or "Stay within the existing directory structure."
- Libraries: "Only use standard libraries; do not add new npm dependencies."
2. Provide Context (The "Why" and "Where")
AI performs better when it understands the ecosystem. Instead of just pasting a function, tell the AI:
- Where it fits: "This function handles user authentication in the
auth-servicemodule." - What it interacts with: "It should return a JWT that is compatible with the existing
verifyTokenfunction inmiddleware.js." - Previous attempts: "I tried using
fs.promises, but it caused anEACCESerror in our Docker container."
3. Use Step-by-Step Reasoning
If you are asking for complex logic, break it down. You can use a structure like this:
- "First, analyze the current data structure in
User.ts." - "Second, outline the plan for modifying the schema to include the new field."
- "Finally, provide the code to run the migration script."
4. Ask for Iteration or Reviews
Rather than expecting perfect code on the first pass, invite the AI to critique itself:
- "Write the implementation for this API endpoint, then list three potential security vulnerabilities in your approach and how to mitigate them."
- "Review this snippet for potential race conditions."
5. Define the Output Format
Control how you receive the information:
- "Provide the code in a single block for easy copying."
- "Explain the logic in bullet points before showing the code."
- "If you need to make changes to multiple files, present them as a summary of the edits rather than rewriting the entire codebase."
6. Use "Few-Shot" Prompting
If you want the code to follow a specific style (e.g., your team's specific way of handling error logging), provide an example of that style before asking for the new task. "Here is how we handle errors in the codebase: [Example]. Now, apply this pattern to the new controller I'm writing."
A Note on "Context Window"
If you are using an assistant that can see your entire project, try to keep the prompt focused on the specific files or logic you want to change. If the prompt is too broad (e.g., "Make this project better"), the assistant may struggle to prioritize. If you are copying and pasting code manually, always include the imports and any related interfaces so the AI has enough context to resolve dependencies.
Answering this used an estimated 90% less than EcoRouter’s configured frontier baseline
- Routed to
- Efficient
- Tokens
- 221 in / 651 out
- Cost
- $0.0010
- Baseline
- $0.01
Figures recorded by EcoRouter when this answer was generated, and fixed at that moment. Cost comparisons are against a configured reference model, not a measurement of electricity, carbon or water.
Ask about this
Ask EcoRouter a follow-up using this Knowledge as context. Nothing becomes public unless you choose to publish it.
Ask a follow-upComments
No comments yet.