Learn

Reading a file properly

Claude

Why Claude Code reads files with its Read tool instead of cat, and how to make the most of it.

Claude Code has several ways to read a file. Understanding which one it picks, and knowing how to nudge it toward the right one, changes the quality of its answers.

The Read tool vs Bash cat

When you ask "read this file", Claude Code uses its Read tool by default, not cat. Why?

  • Read shows line numbers: it can cite a specific line and edit it afterward.
  • Read handles large files: it can read in chunks via offset and limit.
  • Read works on images: if you point it to a screenshot, it can see it.
  • Read works on PDFs and notebooks: by page range or by cell.
shell
claude

Then ask it:

Prompt CLIPointing to a specific file
Read package.json and summarize the important dependencies.

Reading only a portion

On a large file, explicitly ask for a range.

Prompt CLISpecific range
Read the first 50 lines of src/index.ts and tell me what the module does.

Why this matters

When Claude reads with Read, it keeps line numbers in memory. So if you then ask "rename foo to bar on line 42", it knows exactly where to act.

See also · claude-codeclaude-code / premier-promptReview how to write a prompt that guides Claude well

Sources

Related

See also · terminalWhat is a terminal

Check off steps to unlock what comes next

Back to course