AI Prompts for Resolving Duplicate Function Creation

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

AI Prompts for Resolving Duplicate Function Creation

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

Scroll to explore

Published June 28, 2026

Lovable sometimes creates a new function that already exists elsewhere in the codebase under a different name, leading to confusion and errors. This duplication can cause unexpected behavior and maintenance challenges. These prompts help developers diagnose, fix, verify, and prevent this issue effectively. Built across 4 distinct stages covering Diagnose the Wall, Isolate and Fix, Verify the Resolution and more, this guide gives you one expert prompt per step so you never have to write from scratch or guess what the AI needs. The prompts work in ChatGPT, Claude, and Gemini and are designed to get usable output on the first try.

Diagnose the Wall

Check the codebase for functions with similar functionality but different names.

Identify Duplicate Functions

Please analyze the current codebase and identify all functions that perform similar tasks. Create a comprehensive list that includes the names of these functions, along with a brief description of their functionality. Highlight any functions that have different names but exhibit similar behavior, and provide examples of how they overlap in terms of their operations. Additionally, suggest potential ways to consolidate these functions to improve code efficiency and maintainability.

Diagnose the Wall

Check Function Usage

Please review the codebase and provide a detailed analysis of where each function is called. Identify any instances of multiple functions that contain similar logic and are being used interchangeably. For each identified function, summarize the key similarities and differences in their logic. Additionally, suggest which function could be consolidated or refactored to improve code efficiency and maintainability. Present your findings in a structured report format.

Diagnose the Wall

Analyze Recent Changes

Please analyze the recent changes made to the codebase. Provide a detailed summary of any new functions that have been added, including their purpose and functionality. Compare these new functions with existing ones, highlighting similarities and differences in their implementation and usage. Additionally, include any potential impacts these changes may have on the overall system performance and maintainability.

Diagnose the Wall

Review Function Definitions

Please review the function definitions related to [FUNCTION NAME]. Identify and list all functions, and highlight any that appear to duplicate existing functionality within the codebase. For each duplicate, provide a brief explanation of how it overlaps with the existing functions and suggest potential ways to consolidate or refactor them for improved efficiency. Format your response as a structured report with sections for each function and its analysis.

Diagnose the Wall

Inspect Component Reprocessing

Analyze the reprocessing of components in our system to determine if it is causing function duplication. Provide a detailed explanation of how this duplication may have contributed to the current issues we are facing. Include examples of specific components that may be affected, the potential impact on overall functionality, and any patterns or trends that indicate a correlation between reprocessing and duplication. Summarize your findings in a structured report format.

Diagnose the Wall

Isolate and Fix

Focus on removing the duplicate function and ensuring the correct one is used throughout the codebase.

Remove Duplicate Function

Please identify and remove the newly added function that duplicates existing functionality in the codebase. After deletion, ensure that all references throughout the code are updated to point to the original function instead. Additionally, provide a summary of the changes made, including the locations of the updated references and any potential impacts on the overall code functionality. Format this summary in a clear and organized manner for easy review.

Isolate and Fix

Rename Conflicting Functions

Please help me rename a conflicting function in my codebase. The original function is called [ORIGINAL_FUNCTION_NAME] and it conflicts with another function named [CONFLICTING_FUNCTION_NAME]. I want to choose a new name that clearly reflects its purpose and avoids any confusion. After renaming, ensure that all references to the original function throughout the code are updated to the new name. Provide a summary of the changes made and any potential impacts on the code.

Isolate and Fix

Consolidate Function Logic

Please help me consolidate the logic of the duplicate functions in my codebase. Identify the key functionalities of each duplicate function and determine how they can be merged into a single, well-named function that maintains all necessary features. Ensure that this new function is used consistently throughout the code. Provide a clear example of how to implement this function, including any necessary parameters and return values, and explain how to replace the old functions with the new one in the existing code.

Isolate and Fix

Update Function Calls

Identify all occurrences of the duplicate function being called in the codebase. For each instance, provide the line number and context of the call. Then, replace the duplicate function calls with the correct function, ensuring that the new calls maintain the original functionality. Include a summary of the changes made and any potential impacts on the overall code structure or performance.

Isolate and Fix

Document Function Purpose

Please document the purpose of the function [FUNCTION NAME] by adding detailed comments within the code. Explain why this function should not be duplicated, highlighting the potential issues that could arise from duplication. Additionally, provide clear examples of correct usage for this function, illustrating how it should be implemented in various scenarios. Ensure that the comments are concise yet informative, making it easy for other developers to understand the function's role and importance.

Isolate and Fix

Verify the Resolution

Ensure that the duplicate function issue is resolved and the codebase functions correctly.

Run Functionality Tests

Please execute a comprehensive set of functionality tests to ensure that the removal of the duplicate function has not adversely affected any existing features. Outline the specific areas of the application that need to be tested, including user interactions, data processing, and any integrations with other systems. Provide a detailed report of the test results, highlighting any issues encountered, along with recommendations for resolving them. Ensure that the tests cover both positive and negative scenarios to validate the overall stability of the application.

Verify the Resolution

Confirm Function Usage

Please review the codebase and confirm that all instances of the function [FUNCTION NAME] have been updated to point to the correct, consolidated version. Provide a detailed report that includes the following: a list of all instances where the function was used, any discrepancies found, and confirmation that the updated function is functioning as intended. Additionally, include any recommendations for further improvements or checks that should be performed to ensure consistency across the codebase.

Verify the Resolution

Review Codebase Consistency

Please review the entire codebase for [PROJECT NAME] to identify any duplicate functions and ensure that the logic is consistent throughout. Provide a detailed report that includes the names and locations of any duplicate functions found, along with an explanation of how they can be consolidated or refactored. Additionally, assess the overall logic for consistency and highlight any discrepancies or areas for improvement. Format the report as a structured document with sections for duplicates, logic consistency, and recommendations.

Verify the Resolution

Validate Component Behavior

Please reproduce the scenario that initially led to the creation of a duplicate function in the component. Detail the steps taken to recreate the issue, including any specific inputs or conditions that were present. After reproducing the scenario, confirm whether the duplicate function behavior still occurs or if it has been resolved. Provide a summary of your findings, including any relevant observations or changes made to the component.

Verify the Resolution

Check for Silent Failures

Please analyze the build process for any silent failures that may arise due to recent changes in function implementations. Identify specific areas where these failures could occur and provide a detailed report on potential risks. Include recommendations for testing strategies to ensure that all functions operate correctly without unnoticed errors. Additionally, suggest monitoring practices that can help catch these silent failures in real-time.

Verify the Resolution

Prevent Recurrence

Implement measures to prevent the creation of duplicate functions in future sessions.

Create Function Naming Convention

Help me draft a comprehensive naming convention for functions that ensures clarity and prevents duplication. The convention should include guidelines on how to structure function names, such as using descriptive verbs, indicating the purpose of the function, and incorporating relevant context. Additionally, provide examples of well-named functions and a brief explanation of why each name adheres to the convention. Format this as a clear section that can be directly added to CLAUDE.md.

Prevent Recurrence

Add Function Duplication Rule

Create a rule for CLAUDE.md that prevents the creation of functions with similar logic but different names. The rule should include specific criteria for identifying similar logic, such as comparing the function's input parameters, output types, and core algorithm. Additionally, provide examples of what constitutes similar logic and outline the consequences for violating this rule. Ensure the rule is clear and can be easily understood by developers to maintain code quality and avoid redundancy.

Prevent Recurrence

Develop Pre-Session Checklist

Please develop a comprehensive pre-session checklist that I can use to review existing functions before adding new ones. The checklist should include specific criteria to evaluate the current functions, such as their effectiveness, any potential overlaps, and areas for improvement. Additionally, include steps to ensure that new functions align with existing workflows and do not create redundancy. Format the checklist in a clear, organized manner with bullet points for easy reference during each session.

Prevent Recurrence

Insert Code Comments

Please provide comments for critical functions in my code that warn against duplication. The comments should clearly explain the importance of avoiding duplicate functions and include specific examples of potential issues that could arise from duplication. Aim for comments that are concise yet informative, ideally no more than two sentences each. Format the output as a list of comments, specifying which function each comment corresponds to, and include placeholders for the function names where necessary, such as [FUNCTION_NAME].

Prevent Recurrence

Establish Function Review Process

Help me establish a comprehensive function review process to prevent duplication of functions in our project. The process should include steps for reviewing new functions against existing ones, criteria for identifying duplicates, and guidelines for documenting decisions made during the review. Additionally, outline how this process will be communicated to the team and integrated into our project workflow. The final output should be formatted as a clear section to be added to our project guidelines, ensuring it is easy to understand and implement.

Prevent Recurrence

Frequently asked questions

Why does Lovable create duplicate functions?+

Lovable may create duplicate functions due to its internal agent misidentifying existing functionality. This often happens when similar functions have different names. Ensuring clear naming conventions and reviewing existing functions can mitigate this.

How can I stop Lovable from reintroducing duplicates?+

Implement a rule in CLAUDE.md to check for existing functions before adding new ones. This helps Lovable recognize and avoid creating duplicates.

What should I do if Lovable silently fails on a build?+

Request Lovable to display detailed build logs and errors. This helps identify if the failure is related to duplicate functions or another issue.

How can I ensure function consistency across the codebase?+

Regularly review and refactor the codebase to consolidate similar functions. Use Lovable to identify and merge duplicate logic into a single function.

What naming conventions should I use to avoid duplication?+

Adopt a clear and descriptive naming convention for functions. Include this convention in your CLAUDE.md to guide Lovable in maintaining consistency.