Use this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
This skill provides a structured workflow for investigating a codebase during a code review to identify duplicated logic, reinvented utilities, and missed opportunities to reuse established patterns. By executing this workflow, you ensure that new code integrates seamlessly with the existing project architecture.
When reviewing code, perform the following steps before finalizing your review:
Analyze the new code to identify the core algorithms, utility functions, generic data structures, or UI components being introduced. Look beyond the specific business logic to see the underlying mechanics.
Think about where this type of code would live if it already existed in the project. Provide absolute paths from the repo root to disambiguate.
packages/core/src/utils/packages/cli/src/utils/packages/cli/src/ui/components/, packages/cli/src/ui/packages/core/src/services/, packages/cli/src/services/packages/core/src/config/, packages/cli/src/config/packages/core/ if functionality does not appear React UI specific.Trace Third-Party Dependencies: If the PR introduces a new import for a utility library (e.g., lodash.merge, date-fns), trace how and where the project currently uses that library. There is likely an existing wrapper or shared utility.
Check Package Files: Before flagging a custom implementation of a complex algorithm, check package.json to see if a standard library (like lodash or uuid) is already installed that provides this functionality.
Delegate the heavy lifting of codebase investigation to specialized sub-agents. They are optimized to perform deep searches and semantic mapping without bloating your session history.
To ensure a comprehensive review, you MUST formulate highly specific objectives for the sub-agents, providing them with the "scents" you discovered in Step 1.
codebase_investigator as your primary researcher. When delegating, formulate an objective that asks specific, investigative questions about the codebase, explicitly including these search vectors:
Intl.DateTimeFormat or setTimeout for similar purposes?").*Format* or *Debounce*?").generalist for detailed, turn-intensive comparisons. For example: "Review the implementation of MyNewComponent in the PR and compare it semantically against all components in packages/ui/src. Are there any existing components that could be extended or used instead?"package.json include lodash?"), perform a direct search to save time. Default to delegation for any open-ended "investigations."Check if the new code aligns with the project's established conventions.
If you discover that the PR duplicates existing functionality or ignores a best practice:
Example comment:
"It looks like this PR introduces a new
formatDateutility. We already have a robust, testedformatDatefunction insrc/utils/dateHelpers.ts.You can replace your implementation by importing it like this:
import { formatDate } from '../utils/dateHelpers'; // Then use it here: const displayDate = formatDate(userDate, 'MMM Do, YYYY');Reusing this ensures that the date formatting remains consistent with the rest of the application and handles timezone conversions correctly."