Claude: Investigate Before Answering

A system-prompt snippet that makes Claude open and read referenced files before answering questions about a codebase, to avoid speculative or hallucinated claims.

  • 🤖 Claude
  • 🗂️ Coding

Prompt by Anthropic — Claude prompting best practices · Original source (opens in a new tab)

Claude: Investigate Before Answering — prompt preview

The prompt

prompt
<investigate_before_answering>
Never speculate about code you have not opened. If the user references a specific file,
you MUST read the file before answering. Make sure to investigate and read relevant
files BEFORE answering questions about the codebase. Never make any claims about code
before investigating unless you are certain of the correct answer - give grounded and
hallucination-free answers.
</investigate_before_answering>

What it is

A short prompt block wrapped in <investigate_before_answering> tags. It tells Claude never to speculate about code it has not opened, to read any file the user references before answering, and to investigate relevant files before making claims about the codebase. The only exception is when Claude is certain of the correct answer. The goal is grounded, hallucination-free answers.

Who it's for

  • Developers using Claude to ask questions about an existing codebase
  • Teams building coding assistants or agents that have file-reading ability
  • Prompt engineers who want to reduce speculative claims about code

Requirements

Requirements

  • Access to Claude, for example through a system prompt or a prompt you control
  • A way for Claude to open and read files (the prompt says to read files, but the source does not specify the tooling)
  • A codebase or files the user can reference in questions

Examples

Question about a specific file

Prompt
prompt
<investigate_before_answering>
Never speculate about code you have not opened. If the user references a specific file,
you MUST read the file before answering. Make sure to investigate and read relevant
files BEFORE answering questions about the codebase. Never make any claims about code
before investigating unless you are certain of the correct answer - give grounded and
hallucination-free answers.
</investigate_before_answering>

What does the function calculateInvoiceTotal in src/billing/invoice.ts do with discount codes?

Expected output: Claude should open src/billing/invoice.ts first, then describe how calculateInvoiceTotal handles discount codes based on the actual code.

Debugging a referenced error

Prompt
prompt
<investigate_before_answering>
Never speculate about code you have not opened. If the user references a specific file,
you MUST read the file before answering. Make sure to investigate and read relevant
files BEFORE answering questions about the codebase. Never make any claims about code
before investigating unless you are certain of the correct answer - give grounded and
hallucination-free answers.
</investigate_before_answering>

My tests in tests/auth/login.test.js fail with "token undefined". Can you tell me why?

Expected output: Claude should read the test file and the relevant authentication code before proposing a cause, rather than guessing.

Broad codebase question

Prompt
prompt
<investigate_before_answering>
Never speculate about code you have not opened. If the user references a specific file,
you MUST read the file before answering. Make sure to investigate and read relevant
files BEFORE answering questions about the codebase. Never make any claims about code
before investigating unless you are certain of the correct answer - give grounded and
hallucination-free answers.
</investigate_before_answering>

Where in this project is user session expiry configured, and how is it enforced?

Expected output: Claude should look through the relevant files to find where session expiry is configured and enforced, then answer based on what it found.

Pros & cons

Pros

  • Pro:Directly targets speculation by requiring files to be read before answering
  • Pro:Short and easy to drop into an existing prompt
  • Pro:Allows an exception when Claude is certain, so it does not force a lookup for every trivial question
  • Pro:Aims for grounded, hallucination-free answers about the codebase

Cons

  • Con:Only works if Claude can actually read files, and the source does not describe how
  • Con:May lead to extra file reads before answering, since it requires investigating relevant files
  • Con:The 'unless you are certain' exception still leaves some judgment to Claude
  • Con:The source does not provide measured results for how much it reduces hallucinations

Tips

  • Keep the XML-style tags so the instruction stays clearly delimited from the rest of your prompt
  • Reference specific files in questions, since the prompt requires reading any file the user references
  • Ask about concrete code to benefit most from the grounding requirement

Variations

  • Remove the 'unless you are certain of the correct answer' clause if you want investigation to be mandatory in every case (this is a change to the original wording, not part of the source)
  • Combine it with other instructions in your system prompt, keeping this block as its own tagged section