Back/Engineering/Claude/Gemini
IntermediateEngineering

How to Build a Perfectly-Contextualized Prompt for Complex Code Analysis with Repo Prompt

Build a deliberate code analysis packet by selecting the smallest sufficient set of repository files, stating the question and constraints, and giving a reasoning model exact paths and contents without hidden context or irrelevant generated code.

How to Build a Perfectly-Contextualized Prompt for Complex Code Analysis with Repo Prompt

Ryan uses Repo Prompt to select the exact application, component, library, schema, and script files needed for a maintainability question, removes generated and irrelevant content until the token set is manageable, adds an architect prompt, and sends the clearly demarcated file context to a reasoning model.

Before you start

What you need

  • A clean repository revision and a specific engineering question
  • Knowledge of the relevant entry points, schemas, interfaces, tests, and configuration
  • Repo Prompt or another tool that shows selected files and token count
  • A model with adequate context and an approved data handling boundary
  • A plan to verify every recommendation in the actual repository

What you’ll make

A reproducible prompt packet containing repository revision, selected file manifest, exact code context, task, constraints, and requested response format, plus findings that cite files and remain hypotheses until verified.

Tools used

Step by step

The workflow

Follow the sequence once, then adapt the prompts, checks, and handoffs to your own setup.

4 steps

Step01

Select Specific Files in Repo Prompt

Start from the question and select its entry point, direct callers, types, schemas, configuration, tests, and one representative implementation. Watch the token count and remove generated, vendored, or unrelated files.

Step02

Compose Your Query and Add a Persona

Write a precise request with the desired outcome, constraints, non goals, environment, and response format. Add an architect or reviewer perspective only when it improves the requested analysis.

Example prompt
Analyze the selected repository context at commit [commit] for [question]. Constraints: [constraints]. Cite exact files and symbols. Return current behavior, dependency map, risks, missing context, and two options with tradeoffs. Do not invent unprovided code or modify files.
Step03

Generate and Copy the Full Context

Generate the packet and inspect the manifest before copying it. Confirm file paths are clear, content is complete, secrets are absent, and the task appears after the context in an unambiguous format.

Step04

Paste into Your Preferred LLM

Send the packet to the approved model and treat its answer as an analysis proposal. Open every cited location, request any missing context, reproduce claimed behavior, and run focused tests before implementing a recommendation.

What good looks like

  • The selected set includes the interfaces and tests needed to understand the target behavior without dumping the entire repository.
  • Generated output, dependencies, secrets, unrelated assets, and sensitive files are excluded.
  • The model cites exact paths and symbols, identifies missing context, and distinguishes observation from recommendation.
  • A developer confirms findings in the repository and with focused tests before changing code.

Build your next product with ChatPRD

Turn an idea into a PRD, user stories, and a plan.

Try ChatPRD free

After the steps

Runbook notes

How to recover when the loop fails and where human judgment helps.

Recover

If it goes sideways

A compact packet omits an interface, caller, schema, or test that changes the conclusion
Ask the model to list missing context, trace dependencies from entry points, and add only the necessary files.
Large generated or vendored files crowd out relevant code
Exclude build output, dependencies, lockfile noise, media, and generated artifacts unless the question specifically concerns them.
The packet includes credentials, customer data, internal keys, or restricted code
Review the manifest, apply repository ignore rules, redact sensitive values, and use an approved model environment.
The answer refers to a different commit than the code being changed
Record the commit and dirty state in the packet, then regenerate after material repository changes.

Start shipping
better products.

Join 100,000+ product managers who use ChatPRD to write better docs, align teams faster, and build products users love.

Free to start
No credit card
SOC 2 certified
Enterprise ready