This prompt is for an AI coding agent or a developer-assisted workflow that has just been pointed at a new, unfamiliar repository. The job-to-be-done is to produce a structured, high-confidence inventory of the repository's top-level anatomy—directories, build manifests, configuration files, and primary entry points—before any code is modified or any deeper analysis is attempted. The ideal user is an AI engineer integrating a coding agent into a CI/CD pipeline, a developer onboarding tool, or an automated code review system. The reader needs the agent to build a reliable mental model of the project structure without hallucinating files, misclassifying generated code as source, or missing critical configuration that controls builds, deployments, or security posture.
Prompt
Repository Discovery and Initial Scan Prompt Template

When to Use This Prompt
Define the job, reader, and constraints for the Repository Discovery and Initial Scan prompt.
Use this prompt when the agent has read access to the repository root but no prior context about the project's language, framework, build system, or monorepo layout. It is designed for the initial cold-start scan: the moment after git clone and before any task-specific reasoning. The prompt expects the agent to traverse the top-level directory tree, identify standard signals (e.g., package.json, Makefile, Dockerfile, .github/workflows/, src/, tests/), and report findings in a structured schema. Do not use this prompt for deep semantic analysis, dependency graph construction, or security vulnerability scanning—those are downstream tasks that depend on the inventory this prompt produces. Do not use it when the repository is already indexed by a language server or when a compile_commands.json or LSP workspace is available; in those cases, a symbol-indexing or build-system-specific prompt is more appropriate.
The prompt includes explicit constraints to prevent common failure modes: it instructs the agent to ignore .git/, node_modules/, vendor/, and other dependency directories; to flag when a critical file is missing rather than inventing one; and to report confidence levels for each finding. Before wiring this into an automated pipeline, you must pair it with a validation harness that cross-references the agent's output against a manual ls -la or tree listing of the repository root. If the agent misses a Dockerfile or misidentifies a src/ directory as application code when it contains only generated protobuf stubs, the harness should flag the output for human review. For repositories with compliance or security sensitivity, require a human to confirm the inventory before any subsequent edit or analysis prompt is executed.
Use Case Fit
Where the Repository Discovery and Initial Scan prompt works and where it introduces risk. Use these cards to decide if this prompt fits your agent's current task before wiring it into a pipeline.
Good Fit: First Contact with an Unknown Repo
Use when: an agent is dropped into a repository with no prior context and must produce a structured inventory before any edit or deeper analysis. Guardrail: always run this prompt before any file-modification task; treat its output as the agent's initial working memory.
Bad Fit: Incremental Updates After Initial Scan
Avoid when: the agent already has a recent scan and only a few files changed. Re-running full discovery wastes context and time. Guardrail: use a diff-based or git-history prompt instead; reserve full scans for new sessions or major branch switches.
Required Inputs: Filesystem Access and Tool Permissions
What to watch: the prompt assumes the agent can run ls, tree, cat on config files, and read top-level directory structures. Guardrail: confirm tool permissions before invoking; if the agent lacks filesystem access, route to a human-provided repo map instead.
Operational Risk: Ignored Critical Paths
What to watch: the model may skip directories that appear empty, generated, or vendorized but contain critical build or deploy config. Guardrail: cross-reference the scan output against a manual file listing or .gitignore exceptions; flag any directory present on disk but absent from the inventory.
Operational Risk: Monorepo Misidentification
What to watch: in monorepos, the prompt may treat the entire tree as one project, missing per-package build systems, separate entry points, or nested package managers. Guardrail: after the initial scan, run the Build System and Package Manager Identification prompt on each detected subdirectory that contains its own config files.
Operational Risk: Stale or Incomplete Output in Long Sessions
What to watch: the scan output ages as the agent modifies files or pulls new changes. Later tasks may rely on outdated structure. Guardrail: attach a timestamp and git commit hash to every scan output; invalidate and re-run when the working tree changes beyond a configured threshold.
Copy-Ready Prompt Template
A reusable prompt template with square-bracket placeholders for generating a structured inventory of a new repository.
This prompt template is the core instruction set for an AI coding agent to perform an initial, read-only discovery scan on an unfamiliar repository. It is designed to be dropped into an agent harness that has already mounted the repository filesystem and has access to standard discovery tools like ls, cat, grep, and git. The prompt forces the agent to produce a structured JSON output, which your application can then parse, validate, and use to populate a context map for subsequent agent tasks.
markdownYou are a senior software engineer performing an initial discovery scan on an unfamiliar repository. Your goal is to produce a structured, high-confidence inventory of the codebase. You have access to the filesystem at the root path [REPO_PATH]. You may use standard Unix tools to explore, but you must not modify any files. First, explore the top-level directory structure. Then, identify and read key configuration files. Finally, trace the build system and entry points. Your final output must be a single JSON object conforming to this schema: { "repository_name": "string", "primary_language": "string | null", "build_system": "string | null", "package_manager": "string | null", "top_level_dirs": [ { "name": "string", "inferred_purpose": "string", "confidence": "high | medium | low" } ], "key_config_files": [ { "path": "string", "purpose": "string" } ], "entry_points": [ { "path": "string", "type": "main | server | cli | route_registration | other", "confidence": "high | medium | low" } ], "test_directories": ["string"], "ignored_paths": ["string"], "summary": "A dense, 3-5 sentence summary of the repository's purpose, tech stack, and architecture." } Constraints: - [CONSTRAINTS]: Only use read-only commands. Do not run builds, install dependencies, or execute any code. If a directory is too large to fully scan, note it in `ignored_paths` with a reason. Prioritize accuracy over speed. - If you cannot determine a field with high confidence, set its value to `null` or an empty array and lower the confidence rating.
To adapt this template, replace the [REPO_PATH] placeholder with the actual mounted path in your agent's execution environment. The [CONSTRAINTS] block is a hook for you to inject environment-specific rules, such as a list of directories to skip entirely, a maximum scan depth, or a token budget for the final summary. After the agent runs, your harness must validate the output JSON against the schema. A critical next step is to run a manual or automated evaluation: compare the agent's top_level_dirs and entry_points against a known-good listing to measure recall and precision. If the agent misses a critical path like a hidden .github directory or a non-standard build file, add that as a negative example to your evaluation set and consider refining the prompt's exploration instructions.
Prompt Variables
Required inputs for the Repository Discovery and Initial Scan prompt. Each placeholder must be populated before the prompt is sent. Validation notes describe how to verify the input is correct before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[REPO_ROOT_PATH] | Absolute path to the repository root on the agent's filesystem | /home/agent/workspace/project-api | Must be a readable directory. Check with |
[SCAN_DEPTH] | Maximum directory depth for the initial traversal | 3 | Must be an integer between 1 and 6. Depths above 6 risk context overflow in large monorepos. Default to 3 if not specified. |
[EXCLUDE_PATTERNS] | Glob patterns for directories and files to skip during discovery | ["node_modules", "*.pyc", ".git", "dist", "pycache"] | Must be a valid JSON array of glob strings. Validate each pattern compiles without error. Warn if critical paths like |
[TARGET_FILE_TYPES] | File extensions or names to prioritize during the scan | ["package.json", "go.mod", "Makefile", "Dockerfile", ".yaml", ".toml"] | Must be a valid JSON array. Each entry must be a literal filename or a glob with a single wildcard. Reject patterns with recursive wildcards like |
[OUTPUT_FORMAT] | Desired structure for the scan results | markdown-tree-with-annotations | Must be one of: |
[MAX_FILE_COUNT] | Hard limit on the number of files to include in the output | 200 | Must be a positive integer. The harness must truncate and log a warning if the actual file count exceeds this limit. Set to 0 for no limit but require explicit approval. |
[INCLUDE_EMPTY_DIRS] | Whether to include directories with no matching files in the output | Must be |
Implementation Harness Notes
How to wire the repository discovery prompt into an agent loop with validation, retries, and safe defaults.
This prompt is designed as the first step in an agent's orientation sequence. Wire it as a synchronous preflight call before any file modification, test execution, or dependency installation is permitted. The agent should invoke this prompt immediately after confirming it has a valid working directory and read access. The output is a structured inventory that downstream prompts—entry-point detection, build system identification, test runner discovery—consume as their [CONTEXT] block. Treat the discovery output as a snapshot, not a live index; re-run it when the agent changes branches, pulls new commits, or after any scaffold or dependency generation step that alters the top-level repository shape.
Validation is mandatory before the agent acts on the discovery output. Implement a post-processing validator that checks: (1) every returned directory path exists on disk, (2) key config files like package.json, pyproject.toml, Cargo.toml, or Makefile are present in the output if they exist in the repository root, (3) the entry-points array is non-empty for application repositories, and (4) no generated or vendor directories (node_modules, pycache, .venv, vendor/, dist/) appear in the top-level directory listing unless explicitly requested. If validation fails, retry the prompt once with an explicit [CONSTRAINTS] amendment that lists the missing or invalid items. If the second attempt also fails, log the discrepancy, surface it to the operator, and block downstream agent actions until resolved. For high-risk repositories—those containing deployment configs, database migrations, or infrastructure-as-code—require human confirmation of the discovery output before the agent proceeds to any mutating operation.
Model choice matters here. Use a model with strong instruction-following and structured output support (GPT-4o, Claude 3.5 Sonnet, or equivalent). Set temperature to 0 or near-zero to maximize consistency across runs. The prompt expects a JSON output schema; enforce it with structured output mode or a JSON mode toggle if available. If your harness uses a model that does not support strict JSON mode, wrap the call in a retry loop with a schema validator and a repair prompt that feeds parse errors back to the model. Log the full prompt, raw response, parse errors, and validation results to your observability pipeline. This trace is invaluable when debugging why an agent misidentified a monorepo layout or missed a critical entry point. Do not cache discovery results across sessions unless you also cache the git commit SHA and re-validate on cache hit.
Expected Output Contract
Each field the prompt must return, its expected type, whether it is required, and the validation rule to apply before accepting the output into the agent's context assembly pipeline.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
repository_overview.summary | string (1-3 sentences) | Must be non-empty and under 200 characters. Reject if it contains only the repo name or a generic placeholder. | |
top_level_directories | array of objects | Array length must be >= 1. Each object must have 'name' (string) and 'inferred_purpose' (string). Reject if any 'name' is not a valid directory in the provided file listing. | |
top_level_directories[].name | string | Must match a directory name from the [FILE_LISTING] input exactly. Case-sensitive check required. | |
top_level_directories[].inferred_purpose | string | Must be non-empty. Reject if it is a verbatim copy of the directory name or a generic phrase like 'contains code'. | |
key_config_files | array of strings | Each entry must be a relative file path present in [FILE_LISTING]. Reject if any path is not found or if the array is empty when known config patterns exist in the listing. | |
entry_points | array of objects | Array length must be >= 1. Each object must have 'file_path' (string), 'entry_type' (enum: main, server, cli, route_registration, test_runner), and 'confidence' (number 0.0-1.0). Reject if confidence is below 0.5 for all entries. | |
entry_points[].confidence | number (0.0-1.0) | Must be a float between 0.0 and 1.0. Flag for human review if all entries have confidence < 0.7. | |
ignored_critical_paths | array of strings or null | If non-null, each path must be present in [FILE_LISTING]. If null, the agent asserts no critical paths were ignored. Log a warning if null and the file listing contains common critical paths not mentioned elsewhere. |
Common Failure Modes
What breaks first when an agent scans an unfamiliar repository and how to prevent cascading failures before any edit is planned.
Shallow Scan Misses Critical Entry Points
What to watch: The agent lists only top-level directories and obvious config files, missing nested entry points, monorepo packages, or build scripts in non-standard locations. Guardrail: Require the prompt to traverse at least two levels deep and cross-reference discovered files against build system targets and package manifests.
Generated and Vendor Code Treated as Application Source
What to watch: The agent includes node_modules, vendor/, __pycache__, or generated protobuf stubs in the inventory, inflating the scan and misleading downstream context assembly. Guardrail: Add explicit exclusion patterns for common generated and vendor directories, and validate that the output separates application code from dependency code.
Monorepo Misidentification as Single Project
What to watch: The agent treats a monorepo with multiple packages, languages, and build systems as one flat project, producing a single inventory that conflates unrelated modules. Guardrail: Instruct the agent to detect package boundaries via package.json, Cargo.toml, go.mod, or build.gradle files and produce a per-package breakdown.
Silent Ignore of Permission-Denied or Symlink Paths
What to watch: The agent skips directories it cannot read or follows symlinks into unrelated filesystems without reporting the gap, creating a false sense of completeness. Guardrail: Require the output to include a scan_gaps section listing paths that were inaccessible, skipped due to permissions, or resolved through symlinks.
Config File Overload Without Precedence Resolution
What to watch: The agent discovers multiple config files across environments but does not indicate which takes precedence, leading to incorrect runtime assumptions. Guardrail: Prompt the agent to note config layering and override order, and flag when environment-specific files shadow base configuration.
Hallucinated File Paths or Inferred Structure
What to watch: The agent invents file paths, module names, or directory purposes based on naming conventions rather than actual file system evidence. Guardrail: Require every listed path to be verified against a tree or ls output baseline, and add an eval check that flags any path not present in the ground-truth file listing.
Evaluation Rubric
How to test output quality before shipping the Repository Discovery and Initial Scan prompt. Each criterion targets a specific failure mode observed in coding agents entering unfamiliar repositories.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Top-level directory coverage | All non-hidden, non-ignored top-level directories are listed with a one-line purpose | Missing a directory that appears in | Diff the agent's directory list against a ground-truth |
Key config file detection | All files matching common config patterns are found and correctly classified by type | Missing a | Run a glob check for known config filenames; compare agent output against glob results |
Build artifact exclusion | No files from | Listing a file path inside an ignored or generated directory | Scan output paths against |
Entry-point identification | At least one entry-point file is identified with confidence score and supporting evidence | No entry-point listed, or entry-point is a test file misidentified as application entry | Cross-reference agent's entry-point list against |
Language and framework hints | Primary language is correctly identified; framework hints are present when config files provide them | Language misidentified or framework hint hallucinated without config file evidence | Verify language against GitHub Linguist or file extension majority; require config file citation for each framework hint |
Inventory completeness threshold | Agent reports at least 90% of the files a human would list in a manual initial scan | Agent misses more than 10% of non-generated, non-vendor source files | Run a manual file listing on a sample repo; compute recall as matched files / total expected files |
Critical path omission flag | Agent explicitly flags any standard directories that appear empty or missing | No flag when | Check for absence of standard directories; verify agent emits a warning or note for each missing expected path |
Output schema compliance | Output matches the defined [OUTPUT_SCHEMA] exactly with all required fields present | Missing required field, extra untyped field, or field with wrong type | Validate output JSON against the schema using a JSON Schema validator; fail on any schema violation |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Use the base prompt with a frontier model and no schema enforcement. Replace [OUTPUT_SCHEMA] with a plain-language description of the expected sections. Skip the completeness eval and rely on manual spot-checking.
codeYou are a coding agent entering an unfamiliar repository at [REPO_PATH]. Perform an initial discovery scan and return a structured inventory covering: - Top-level directory listing with one-line purpose guesses - Key config files (build, CI, package manager, linter) - Build artifacts and ignored directories - Likely entry points (main files, server start, route registrations) Do not read files deeply. Focus on names, paths, and conventions.
Watch for
- Missing critical paths that are nested or non-obvious
- Overly broad purpose guesses for directories with mixed concerns
- No distinction between application code and generated/vendor code

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us