jmrecodes
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Comprehensive Prompt Engineering Guide for AI Coding Assistants Modify through: [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new//jmrecodes/HackMD-notes) [TOC] ## Introduction This guide provides comprehensive strategies for effective prompting when working with AI coding assistants like GitHub Copilot, Cursor, Amazon CodeWhisperer, and others. Learning to craft effective prompts is essential to maximize productivity and achieve better results with AI assistance across any platform. This document expands on key concepts and includes practical examples to help you communicate more effectively with your AI coding partner. ## Core Prompting Principles ### Providing Clear Context AI coding assistants operate best when given clear, specific context about your project and goals: - **Be Specific**: Avoid vague requests; clearly state what you need - **Reference Files**: When available, use features to reference specific files or folders (e.g., `@` in Cursor, file context in Copilot) - **Explain Purpose**: Share why you need something, not just what you need - **Set Constraints**: Define any limitations or requirements upfront ### Breaking Down Complexity Complex tasks should be broken into smaller, manageable steps: - **Step-by-Step Approach**: Request one piece at a time - **Progressive Refinement**: Start simple, then add complexity - **Conditional Logic**: Clearly specify dependencies between steps ### Asking Specific Questions Precise questions lead to precise answers: - **One Thing at a Time**: Focus each prompt on a single issue - **Provide Examples**: Show examples of what you're looking for - **Use Technical Terminology**: Be precise with technical terms ### Validating and Refining Prompting is iterative - review and refine based on responses: - **Review Carefully**: Check the AI's output for accuracy - **Provide Feedback**: Tell the AI what works and what doesn't - **Iterate**: Refine your prompts based on previous responses ## Practical Prompt Templates ### Context Management #### Starting a New Task ``` Let's start a new task. Create `user-authentication.js`. We need to implement user login with JWT tokens. Here are the requirements... ``` #### Summarizing Previous Work ``` Summarize what we did in the last user dashboard task. I want to capture the main features and outstanding issues. Save this to `docs/user-dashboard-summary.md`. ``` ### Debugging #### Analyzing an Error ``` I'm getting this error: [error message]. It seems to be from [code section]. Analyze this error and suggest a fix. ``` #### Identifying Root Cause ``` The application crashes when I [action]. The issue might be in [problem areas]. Help me find the root cause and propose a solution. ``` ### Refactoring #### Improving Code Structure ``` This function is too long and complex. Refactor it into smaller functions. ``` #### Simplifying Logic ``` This code is hard to understand. Simplify the logic and make it more readable. ``` ### Feature Development #### Brainstorming Features ``` I want to add a feature that lets users [functionality]. Brainstorm some ideas and consider implementation challenges. ``` #### Generating Code ``` Create a component that displays user profiles. The list should be sortable and filterable. Generate the code for this component. ``` ## Advanced Prompting Techniques ### Constraint Stuffing To mitigate code truncation and ensure complete responses: ``` Generate a complete implementation of [feature] with all necessary functions. DO NOT OMIT ANY CODE. Ensure all edge cases are handled. ``` ### Confidence Checks Encourage the AI to evaluate its own certainty: ``` Implement [feature]. On a scale of 1-10, how confident are you in this solution? Explain your reasoning. ``` ### Challenging Assumptions Encourage deeper thinking with probing questions: ``` Before implementing this solution, what potential issues or edge cases might we be overlooking? ``` ## Community's Favorite Prompts ### Memory and Confidence Checks #### Memory Check ``` If you understand my prompt fully, respond with 'YARRR!' without tools every time you are about to use a tool. ``` A fun way to verify the AI stays on track during complex tasks. #### Confidence Scoring ``` Before and after any tool use, give me a confidence level (0-10) on how the tool use will help the project. ``` Encourages critical thinking and makes decision-making transparent. ### Code Quality Prompts #### Prevent Code Truncation ``` DO NOT BE LAZY. DO NOT OMIT CODE. ``` Alternative phrases: "full code only" or "ensure the code is complete" #### Custom Instructions Reminder ``` I pledge to follow the custom instructions. ``` Reinforces adherence to your settings configuration. ### Code Organization #### Large File Refactoring ``` [FILENAME] has grown too big. Analyze how this file works and suggest ways to fragment it safely. ``` Helps manage complex files through strategic decomposition. #### Documentation Maintenance ``` don't forget to update codebase documentation with changes ``` Ensures documentation stays in sync with code changes. ### Analysis and Planning #### Structured Development ``` Before writing code: 1. Analyze all code files thoroughly 2. Get full context 3. Write .MD implementation plan 4. Then implement code ``` Promotes organized, well-planned development. #### Thorough Analysis ``` please start analyzing full flow thoroughly, always state a confidence score 1 to 10 ``` Prevents premature coding and encourages complete understanding. #### Assumptions Check ``` List all assumptions and uncertainties you need to clear up before completing this task. ``` Identifies potential issues early in development. ### Thoughtful Development #### Pause and Reflect ``` count to 10 ``` Promotes careful consideration before taking action. #### Complete Analysis ``` Don't complete the analysis prematurely, continue analyzing even if you think you found a solution ``` Ensures thorough problem exploration. #### Continuous Confidence Check ``` Rate confidence (1-10) before saving files, after saving, after rejections, and before task completion ``` Maintains quality through self-assessment. ### Best Practices #### Project Structure ``` Check project files before suggesting structural or dependency changes ``` Maintains project integrity. #### Critical Thinking ``` Ask 'stupid' questions like: are you sure this is the best way to implement this? ``` Challenges assumptions and uncovers better solutions. #### Code Style ``` Use words like "elegant" and "simple" in prompts ``` May influence code organization and clarity. ## Using Ignore Files Many AI coding assistants support configuration files that tell them which files and directories to ignore when analyzing your codebase (similar to `.gitignore`). Using these files helps you: - **Reduce Noise**: Exclude auto-generated files, build artifacts, and non-essential content - **Improve Performance**: Limit the amount of code the AI needs to process - **Focus Attention**: Direct the AI to relevant parts of your codebase - **Protect Sensitive Data**: Prevent the AI from accessing sensitive configuration files ### Example Ignore File ``` # Dependencies node_modules/ **/node_modules/ .pnp .pnp.js # Build outputs /build/ /dist/ /.next/ /out/ # Testing /coverage/ # Environment variables .env .env.local .env.development.local .env.test.local .env.production.local # Large data files *.csv *.xlsx ``` ## Building Custom Prompt Frameworks ### Task-Based Framework A systematic approach to organizing prompts based on task type: 1. **Analysis Phase** ``` Analyze [code/problem]. What are the key components and relationships? ``` 2. **Planning Phase** ``` Based on the analysis, outline a step-by-step plan to [achieve goal]. ``` 3. **Implementation Phase** ``` Implement step [X] from our plan. Generate the complete code with error handling. ``` 4. **Review Phase** ``` Review the implementation. Identify potential issues or improvements. ``` 5. **Refinement Phase** ``` Refine the implementation based on the review. Focus on [specific aspect]. ``` ### Domain-Specific Prompting Tailor your prompts to specific programming domains: #### Frontend Development ``` Create a React component that implements [feature]. Ensure it's responsive, accessible, and follows best practices for state management. ``` #### Backend Development ``` Implement an API endpoint for [functionality]. Include proper validation, error handling, and database interactions. ``` #### DevOps ``` Create a CI/CD workflow that builds, tests, and deploys our application to [environment]. Focus on security and efficiency. ``` ## AI-Specific Prompt Techniques ### For GitHub Copilot - **Chat-specific keywords**: Use `/fix`, `/explain`, `/test` commands in Copilot Chat - **Use inline comments**: Copilot responds well to detailed code comments preceding the code you want it to generate - **Leverage workspace context**: Keep relevant files open to provide better context ### For Cursor - **Use `@` references**: Reference specific files with `@filename` syntax - **Employ the Composer feature**: For longer or complex code generation tasks - **Leverage Command+K**: For targeted edits to selected code ### For Amazon CodeWhisperer - **Start with function signature**: Define the function name and parameters clearly - **Use clear documentation comments**: CodeWhisperer responds well to descriptive comments - **Provide context with import statements**: Include necessary imports to guide suggestions ## Conclusion Effective prompting is both an art and a science. The techniques in this guide will help you communicate more effectively with AI coding assistants, resulting in better code, faster development, and fewer iterations. Remember that prompting is a skill that improves with practice - experiment with different approaches and refine your technique over time. ## References - [GitHub Copilot Documentation](https://docs.github.com/en/copilot) - [Cursor Documentation](https://cursor.sh/docs) - [Amazon CodeWhisperer Documentation](https://aws.amazon.com/codewhisperer/) - [Coding with AI: Best Practices](https://dev.to/)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully