AI Prompts for Preventing Duplicate Function Creation

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

AI Prompts for Preventing Duplicate Function Creation

20 of the best prompts for preventing 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 Preventing 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. Claude Code may create a new function that already exists elsewhere in the codebase under a different name. This leads to redundancy and potential conflicts in the code. These prompts help developers guide Claude Code to identify and avoid creating duplicate functions. Works with ChatGPT, Claude, and Gemini.

Diagnose the Wall

Review the project's CLAUDE.md file and the recent changes to identify any overlooked instructions.

Check CLAUDE.md Compliance

Please review the following CLAUDE.md file content: [PASTE CONTENT]. Confirm whether all the rules outlined in this document are being followed in our current task. Identify and explain any specific rules that are relevant to the task we were just working on, and provide suggestions for ensuring compliance with those rules. Additionally, summarize the implications of any non-compliance found.

Diagnose the Wall

Identify Recent Changes

Please provide a detailed summary of all recent changes made to the codebase. Include a list of any new functions that were added, specifying their names and exact locations within the code. Additionally, describe the purpose of each new function and how it integrates with the existing code. If applicable, mention any modifications made to existing functions and the reasons behind those changes. Format this information in a clear and organized manner for easy reference.

Diagnose the Wall

Search for Function Duplicates

Please scan the codebase for functions that have similar functionality to the newly added function named [FUNCTION NAME]. Identify and list the names of these duplicate functions along with their file locations within the codebase. Additionally, provide a brief description of how each duplicate function overlaps in functionality with the new function. Format the output in a clear table with columns for Function Name, File Location, and Description.

Diagnose the Wall

Analyze Function Naming

Please analyze the names of all functions in the provided codebase. Identify any naming patterns or conventions that may have been overlooked, and provide a summary of your findings. Include examples of functions that adhere to or deviate from established conventions, and suggest improvements for consistency and clarity. Additionally, outline the potential impact of these naming patterns on code readability and maintainability.

Diagnose the Wall

Review Recent Logs

Please summarize the last few operations performed, focusing specifically on actions related to function creation. Include details such as the types of functions created, any errors encountered during the process, and the overall success rate of these operations. Additionally, highlight any patterns or trends observed in the function creation activities that could inform future improvements. Format the summary in a clear and concise manner, ideally in bullet points for easy readability.

Diagnose the Wall

Isolate and Fix

Focus on identifying and renaming or removing the duplicate function.

Locate Duplicate Function

Please locate the duplicate function in my code that was recently added. Provide the exact line number and file name where this function is defined. Additionally, include the full content of the function so I can review it for any necessary fixes or adjustments.

Isolate and Fix

Compare Function Implementations

Compare the new function [NEW_FUNCTION_NAME] with the existing function [EXISTING_FUNCTION_NAME]. Analyze their implementations in detail, highlighting any differences or similarities in terms of structure, logic, and performance. Discuss how each function handles inputs, outputs, and any edge cases that may arise. Additionally, provide insights on which implementation may be more efficient or easier to maintain, and suggest any improvements that could be made to either function. Present your findings in a structured format with clear headings for each section.

Isolate and Fix

Rename or Remove Duplicate

Identify the duplicate function in the provided code. Analyze the purpose and usage of this function within the overall codebase to determine whether it is more appropriate to rename it for clarity or remove it entirely if it is redundant. Explain the reasoning behind your decision in detail, including any potential impacts on the code's functionality. Once the decision is made, execute the necessary changes in the code and provide the updated version.

Isolate and Fix

Update References

Please review the codebase and identify all instances where the duplicate function is referenced. For each reference, update it to point to the correct function, ensuring that the functionality remains intact. Provide a summary of the changes made, including the locations of the updates and any potential impacts on the overall code structure. Additionally, include any necessary comments or documentation to clarify the updates for future reference.

Isolate and Fix

Re-evaluate Function Necessity

Please evaluate the necessity of the new function named [FUNCTION NAME] in the codebase. Determine if it is redundant by comparing its functionality with existing functions. If you conclude that it is indeed unnecessary, remove it from the codebase. After making this change, confirm that the codebase remains fully functional by running the relevant tests and providing a summary of the results.

Isolate and Fix

Verify the Resolution

Ensure the duplicate function issue is resolved and the codebase is consistent.

Confirm Function Removal

Please verify that the duplicate function has been successfully removed or renamed in the codebase. Provide the updated code, highlighting the changes made to ensure clarity. Additionally, include a brief explanation of why the function was considered a duplicate and any potential impacts on the overall functionality of the code. Make sure to format the response clearly for easy understanding.

Verify the Resolution

Run Functionality Tests

Please execute all relevant functionality tests on the updated codebase to ensure that everything is working correctly after the recent changes. Provide a detailed report of the test results, including any errors or failures encountered during the testing process. Additionally, summarize the overall performance of the code, highlighting any areas that may need further attention or improvement. Format the results in a clear and organized manner, so I can easily review the outcomes.

Verify the Resolution

Check for Remaining Duplicates

Please conduct a thorough scan of the codebase to identify any remaining duplicate functions. Provide a detailed report on your findings, including the number of duplicates found, their locations within the code, and any relevant context about their functionality. If no duplicates are present, confirm this with a statement indicating that the code is free of duplicate functions. Ensure the report is clear and structured for easy understanding.

Verify the Resolution

Validate Code Consistency

Please review the codebase for consistency in function naming and usage. Ensure that all functions adhere to the established naming conventions and document any discrepancies you find. Additionally, provide suggestions for renaming any functions that do not comply with these conventions. Summarize your findings in a report format, highlighting any areas that require attention and the rationale for your recommendations.

Verify the Resolution

Reproduce Original Scenario

Please recreate the original scenario that led to the creation of duplicate functions. Describe the specific conditions and inputs that triggered the duplication issue. After reproducing the scenario, verify that the changes implemented have resolved the issue and confirm that no duplicates are generated in the process. Provide a summary of your findings, including any relevant details about the function's behavior and performance.

Verify the Resolution

Prevent Recurrence

Implement guardrails to prevent future duplicate function creation.

Create CLAUDE.md Rule

Please create a new rule for CLAUDE.md that addresses the issue of duplicate functions in code. The rule should clearly outline the criteria for identifying duplicate functions, provide examples of what constitutes a duplicate, and specify the actions to take when duplicates are detected. Format the rule in a clear and concise manner, suitable for inclusion in the CLAUDE.md documentation. Ensure that the text is ready to be copied and pasted directly into the document.

Prevent Recurrence

Add Function Naming Checklist

Create a comprehensive checklist for function naming conventions that can be used at the beginning of any coding session. The checklist should include guidelines on how to create unique and descriptive function names, such as using specific prefixes or suffixes, avoiding common names, and incorporating the purpose of the function within the name. Additionally, provide examples of good and bad function names to illustrate the concepts. Ensure that this checklist is structured in a clear, bullet-point format for easy reference during coding.

Prevent Recurrence

Insert Code Comments

Please provide comments to insert above critical functions in my code that will warn AI assistants about existing implementations. The comments should clearly state the purpose of each function and highlight any potential issues or considerations that should be noted. Include specific examples of the types of warnings that would be appropriate for functions that may have duplicate implementations or could lead to confusion. Format the output as a list of comments, with each comment corresponding to a specific function, and ensure that the comments are concise yet informative.

Prevent Recurrence

Develop Session Opener

Please create a detailed session opener checklist that I can use to ensure I check for existing functions before adding new ones. The checklist should include specific steps such as reviewing the current codebase for duplicate functions, documenting any existing functions that may overlap with new additions, and consulting with team members to confirm the necessity of new functions. Additionally, include a section for notes on any identified duplicates and recommendations for refactoring if needed. Format this checklist in a clear and organized manner for easy reference during coding sessions.

Prevent Recurrence

Establish Project Convention

Create a project convention document that outlines best practices for function creation and naming in programming. Include sections on naming conventions, such as the use of camelCase or snake_case, guidelines for function length, and the importance of descriptive names that clearly convey the function's purpose. Additionally, provide recommendations on how to avoid creating duplicate functions, including strategies for code reuse and modular design. Format the document with clear headings and bullet points for easy reference.

Prevent Recurrence

Frequently asked questions

Why does Claude Code create duplicate functions?+

Claude Code may lose track of earlier context in large codebases due to its fixed context window. This can lead to it creating functions that already exist under different names. Ensuring CLAUDE.md rules are followed can mitigate this.

How can I stop Claude Code from losing context?+

Regularly remind Claude Code of the project's CLAUDE.md rules and the current task context. This helps maintain focus and prevents context loss.

What should I do if Claude Code gets stuck?+

Interrupt the current loop and provide specific instructions or context to guide it back on track. This can help resolve the issue without starting over.

How do I ensure Claude Code follows naming conventions?+

Include detailed naming conventions in your CLAUDE.md file and remind Claude Code of these rules at the start of each session.

Can I automate checks for duplicate functions?+

Yes, you can script automated checks using shell commands that Claude Code can execute. This helps identify duplicates before they become an issue.