AI Prompts for Avoiding Duplicate Function Creation

20 of the best prompts for avoiding duplicate function creation, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.

AI Prompts for Avoiding Duplicate Function Creation

20 of the best prompts for avoiding duplicate function creation, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.

Scroll to explore

Published June 28, 2026

Most people try to use AI for Avoiding Duplicate Function Creation with a single vague prompt and get generic results. This guide takes a different approach: 4 targeted stages, from Diagnose the Wall through Prevent Recurrence, each with a prompt that gives the AI exactly the context it needs. GitHub Copilot sometimes suggests creating a new function that already exists elsewhere in the codebase under a different name, leading to redundancy and potential confusion. This can cause maintenance challenges and bugs due to inconsistent function usage. These prompts help developers identify and resolve such duplications efficiently. Works with ChatGPT, Claude, and Gemini.

Diagnose the Wall

Identify if a function already exists in the codebase before accepting Copilot's suggestion.

Check Function Existence

Please check if a function named [FUNCTION_NAME] exists in the currently open files. If it does, provide the exact location where it is defined, including the file name and line number. Additionally, summarize the purpose of the function based on its definition, highlighting any relevant comments or documentation that may provide context. Format the response clearly, so I can easily understand the findings.

Diagnose the Wall

Identify Similar Functions

Please analyze the open files in the project and identify any functions that perform similar tasks to [FUNCTION_NAME]. For each similar function, provide its name and the file location where it can be found. Additionally, include a brief description of what each function does and how it relates to [FUNCTION_NAME]. Format the output as a structured list for easy reference.

Diagnose the Wall

Compare Function Signatures

Please compare the signature of the function [FUNCTION_NAME] with the signatures of existing functions in the currently open files. Identify any matches or near matches, and provide details on the functions that are similar, including their names and the specific parameters that align or differ. Additionally, explain any potential implications of having duplicate or similar function signatures in the codebase, such as confusion for future developers or issues with function calls. Format your findings in a clear, structured report.

Diagnose the Wall

Search for Function Usage

Please search through the open files in the project and identify all instances where the function [FUNCTION_NAME] is used. Provide a detailed list of each location, including the file names and line numbers. Additionally, summarize the context in which the function is used in each instance, highlighting any relevant comments or surrounding code that may provide insight into its purpose. Format the output as a clear, organized report.

Diagnose the Wall

Detect Function Redundancy

Identify any redundancy in the functions related to [FUNCTION_NAME] within the open files. Provide a detailed analysis of the overlapping functionality, including specific examples of where the redundancy occurs. Explain how these functions are similar or identical in their implementation and the potential impact of this redundancy on code maintainability and performance. Additionally, suggest possible refactoring strategies to eliminate the duplicate functions while preserving the intended functionality.

Diagnose the Wall

Isolate and Fix

Focus on resolving the duplication by either renaming or refactoring.

Rename Existing Function

Suggest a new name for the existing function [FUNCTION_NAME] that will help avoid conflicts with the suggested function. Provide at least three alternative names that reflect the purpose of the function while ensuring clarity and uniqueness. Additionally, include a brief explanation for each suggested name, outlining how it relates to the function's intended use or behavior.

Isolate and Fix

Refactor Duplicate Logic

Refactor the logic of [FUNCTION_NAME] by merging it with the existing function [EXISTING_FUNCTION_NAME]. Provide a step-by-step explanation of the changes made, including any adjustments to parameters or return values. Ensure that the new function maintains the original functionality while eliminating redundancy. Additionally, include comments in the code to clarify the purpose of each section and highlight any potential edge cases that should be considered.

Isolate and Fix

Remove Redundant Function

Evaluate whether the function [FUNCTION_NAME] should be removed due to its redundancy with [EXISTING_FUNCTION_NAME]. Provide a detailed justification for your recommendation, considering factors such as code maintainability, potential impacts on functionality, and any performance implications. Additionally, suggest any alternative approaches or modifications that could enhance the overall code quality while addressing the redundancy issue.

Isolate and Fix

Consolidate Functionality

Help me consolidate the functionality of two functions: [FUNCTION_NAME] and [EXISTING_FUNCTION_NAME]. Analyze the purpose and structure of both functions, identifying any overlapping logic or features that can be merged. Provide a detailed plan for creating a single, efficient function that maintains the necessary functionality while reducing redundancy. Include code snippets to illustrate how the new function will be structured and any necessary adjustments to ensure compatibility with existing code.

Isolate and Fix

Update Function References

Identify all instances where the function [FUNCTION_NAME] is referenced in the codebase and outline the necessary updates required to consolidate it with [EXISTING_FUNCTION_NAME]. Provide a detailed list that includes the file names, line numbers, and a brief description of how each reference will change. Additionally, highlight any potential impacts on the code functionality and suggest best practices for implementing these updates to ensure smooth integration.

Isolate and Fix

Verify the Resolution

Ensure the duplication issue is resolved and the code functions correctly.

Confirm Function Removal

Please confirm whether the function [FUNCTION_NAME] has been successfully removed or merged in the codebase. Include details about any changes made to the code, such as the specific lines or files affected, and whether there are any dependencies that were impacted by this removal or merge. Additionally, provide a brief summary of the reasons for the removal or merge and any potential implications for the overall project.

Verify the Resolution

Check Function Consistency

Please review the codebase and verify that all references to [FUNCTION_NAME] are consistent with [EXISTING_FUNCTION_NAME]. Provide a detailed report that includes the locations of any inconsistencies found, the nature of the discrepancies, and suggestions for correcting them. Additionally, confirm that any changes made to [FUNCTION_NAME] align with the intended functionality of [EXISTING_FUNCTION_NAME]. Summarize your findings in a clear format that can be easily understood by the development team.

Verify the Resolution

Run Function Tests

Please execute a series of tests for the functions [FUNCTION_NAME] and [EXISTING_FUNCTION_NAME] to verify their correctness following recent changes. I need detailed results that indicate whether each function passes or fails the tests, along with any error messages or issues encountered during the execution. Additionally, provide a summary of the test coverage, including any edge cases that were considered. Format the results in a clear, structured report that highlights the key findings and recommendations for any necessary fixes.

Verify the Resolution

Validate Codebase Integrity

Please analyze the codebase for any errors related to [FUNCTION_NAME] following the recent resolution. Provide a detailed summary of your findings, including any identified issues, their potential impact on functionality, and recommendations for fixing them. Additionally, assess whether the code adheres to best practices and standards, and suggest any improvements that could enhance overall code integrity. Format your response as a report with clear sections for errors found, recommendations, and best practices.

Verify the Resolution

Review Function Usage

Please review the usage of the functions [FUNCTION_NAME] and [EXISTING_FUNCTION_NAME] in the codebase. Identify any instances where these functions may be duplicating functionality or logic. Provide a summary of your findings, including specific lines of code where duplication occurs, and suggest possible refactoring options to eliminate redundancy. Additionally, include any recommendations for best practices to avoid similar issues in the future.

Verify the Resolution

Prevent Recurrence

Create guidelines and checks to avoid future duplication issues.

Draft Naming Convention

Help me draft a comprehensive naming convention for functions that will help prevent future duplication in our codebase. The convention should include guidelines on how to structure function names, such as using prefixes or suffixes to indicate functionality, and any specific patterns to follow for different types of functions. Additionally, provide examples of well-named functions that adhere to this convention. Format this as a clear section to be added to CLAUDE.md, ensuring it is easy to understand and implement.

Prevent Recurrence

Write Code Comment

Please write a detailed comment for the function [FUNCTION_NAME]. The comment should explain the purpose of the function, how it interacts with any related functions, and provide context on its usage. Additionally, include any important notes on potential duplication issues and best practices to avoid creating similar functions in the future. Aim for clarity and thoroughness to ensure that future developers can easily understand the function's role within the codebase.

Prevent Recurrence

Create Session Checklist

Please create a comprehensive checklist for reviewing new function suggestions to prevent duplication of existing functions. The checklist should include steps such as: verifying the function name against the current repository, checking the function's purpose and parameters, reviewing documentation for similar functions, and consulting with team members for insights on existing implementations. Additionally, include a section for documenting findings and decisions made during the review process. Format this checklist in a clear and organized manner, suitable for team use.

Prevent Recurrence

Develop Function Audit Rule

Create a function audit rule for CLAUDE.md that checks for duplicate functions before they are integrated into the codebase. The rule should include criteria for identifying duplicates based on function names, parameters, and return types. Additionally, outline the steps the audit process should follow, including how to report any duplicates found and suggest alternatives or refactoring options. Ensure the rule is clear, concise, and easy to implement for developers working on the codebase.

Prevent Recurrence

Establish Review Process

Help me establish a comprehensive review process for evaluating function additions in our codebase to ensure they are unique and necessary. The process should include steps for initial assessment, criteria for uniqueness, and methods for determining necessity. Additionally, outline how to document the review findings and communicate decisions to the development team. Provide a structured format that can be easily followed and adapted as needed.

Prevent Recurrence

Frequently asked questions

How does GitHub Copilot suggest functions?+

GitHub Copilot suggests functions based on the context of the open files and the patterns it recognizes. It doesn't have full project awareness unless files are explicitly opened.

Why does Copilot suggest duplicate functions?+

Copilot may suggest duplicate functions if it doesn't recognize existing functions due to different naming or if the files containing those functions are not open.

How can I prevent Copilot from suggesting duplicates?+

Ensure relevant files are open and use naming conventions that help Copilot recognize existing functions. Regularly audit function suggestions for duplication.

What should I do if Copilot suggests a duplicate?+

Use diagnostic prompts to identify existing functions and decide whether to rename, refactor, or remove the duplicate suggestion.

Can Copilot help refactor duplicate functions?+

Yes, Copilot can assist in refactoring by suggesting ways to consolidate or merge duplicate functions into a single, efficient implementation.