Pattern
prompting
core

Prompting Patterns for Agentic Coding

Effective prompt structures for different coding scenarios - features, bugs, refactoring, and more.

The Foundation

Good prompts for coding AI follow a consistent structure:

  1. Context - What exists, what you're working with
  2. Goal - What you want to accomplish
  3. Constraints - Limits and requirements
  4. Output format - How you want the response

Pattern 1: Feature Implementation

Feature Implementation

engineer

For adding new functionality

I need to implement: {{feature}}

## Current Context
- Working in: [file/module]
- Related code: [relevant files]
- Tech stack: [frameworks/libraries]

## Requirements
{{constraints}}

## Expected Deliverables
1. Implementation code
2. Explanation of key decisions
3. Suggested tests

Start by explaining your approach.
Variables:
{{feature}}
{{context}}
{{constraints}}

Pattern 2: Bug Fix

Bug Fix Request

vibecoding

For fixing specific issues

I'm seeing unexpected behavior.

## Symptom
{{symptom}}

## Expected
{{expected}}

## Actual
{{actual}}

## Relevant Code
[paste code here]

What's the minimal fix? Don't refactor—just fix the bug.
Variables:
{{symptom}}
{{expected}}
{{actual}}

Pattern 3: Code Review

Code Review Request

engineer

For reviewing code before commit

Review this code for:

1. Bugs or logic errors
2. Security vulnerabilities
3. Performance issues
4. Code style/conventions

## Code to Review
[paste code]

## Context
- This code does: [purpose]
- It will be called from: [callers]

Be specific. If something is fine, say so briefly.

Pattern 4: Refactoring

Refactoring Request

engineer

For improving existing code

Refactor this code to: {{goal}}

## Current Code
[paste code]

## Constraints
- Preserve existing behavior
- Maintain the same public interface
- {{constraints}}

## Deliverables
1. Refactored code
2. Explanation of changes
3. How to verify nothing broke
Variables:
{{goal}}
{{constraints}}

Pattern 5: Explanation

Code Explanation

vibecoding

For understanding unfamiliar code

Explain this code like I'm a developer who's new to this codebase.

## Code
[paste code]

## What I Want to Know
1. What does this code do at a high level?
2. What are the key functions/methods?
3. What are the inputs and outputs?
4. What might trip me up?

Pattern 6: Test Writing

Test Generation

engineer

For creating tests for existing code

Write tests for this function/component.

## Code to Test
[paste code]

## Testing Framework
[jest/vitest/pytest/etc]

## Requirements
- Cover happy path
- Cover edge cases
- Cover error conditions
- Use descriptive test names

Anti-Patterns to Avoid

Anti-PatternProblemBetter Approach
"Fix this"Too vagueDescribe symptom and expected behavior
"Make it better"Undefined goalSpecify what "better" means
No code contextAI guessesInclude relevant code snippets
Huge code dumpsOverwhelmingFocus on the specific area

Context Management

Too Little Context

Fix the login bug.

AI can't help without seeing the code.

Too Much Context

Here's my entire application... [10,000 lines]

AI loses focus on the actual problem.

Just Right

The login function in auth.ts (lines 45-67) throws
an error when the password contains special characters.

[paste just those lines]

Iterative Refinement

When the first response isn't right:

  1. Be specific about what's wrong

    "The solution works but uses a deprecated API. Use X instead."

  2. Add missed constraints

    "I forgot to mention: this needs to work with React 18."

  3. Ask for alternatives

    "That approach won't work because of X. What are other options?"

Verify Understanding

Before implementing, verify the AI understood:

"Before writing code, summarize:

  1. What you understand the task to be
  2. What approach you'll take
  3. Any assumptions you're making"