Back to course
Reading What AI Writes
Lesson 4 of 10
Free

Understanding Without Writing

Learn to read code well enough to verify it does what you asked. You don't need to write code—you need to understand it.

20 min read
Share

Claude wrote code for you. It looks like it works. But how do you know it does what you asked?

You don’t need to become a programmer. You need to develop enough literacy to verify, question, and direct. This lesson teaches you to read code the way a manager reads a report—for the key points, not every detail.

Why Reading Matters

Imagine you asked Claude to:

Rename files to include today's date, then move the originals to an Archive folder

Claude writes a script. You run it. Your files disappear.

What happened? Maybe the script deleted files instead of moving them. Maybe “Archive” was created somewhere unexpected. Maybe “today’s date” was interpreted as something other than what you meant.

If you could read the code—even superficially—you’d catch this before running it.

The Structure of Code

Most code Claude writes follows a predictable structure:

# 1. SETUP - Getting ready
import os                    # Load tools we need
from datetime import date    # Load date functionality

# 2. CONFIGURATION - Settings you might change
folder_path = "./documents"  # Where to look
date_format = "%Y-%m-%d"     # How dates look

# 3. MAIN LOGIC - What actually happens
for file in os.listdir(folder_path):    # For each file...
    new_name = date.today() + "_" + file  # Build new name
    os.rename(file, new_name)             # Rename it

# 4. OUTPUT - Reporting what happened
print("Done! Renamed 5 files.")

You don’t need to understand every symbol. You need to recognize the sections:

  1. Setup — Loading capabilities (usually at the top)
  2. Configuration — Values you might want to change
  3. Main Logic — The actual work
  4. Output — What it tells you

Reading for Intent

When scanning code, look for:

Action Words (Verbs)

These tell you what the code does:

  • read, open — Accessing files
  • write, save — Creating or modifying files
  • delete, remove — Destroying things (⚠️ pay attention!)
  • rename, move — Changing locations
  • print, log — Showing information
  • send, post — Communicating externally

Loops (Repetition)

When you see for or while, the code is doing something multiple times:

for file in files:       # Do this for each file
for line in document:    # Do this for each line
while True:              # Keep doing this forever (until stopped)

Conditions (Decisions)

When you see if, the code is making choices:

if file.endswith(".pdf"):      # Only if it's a PDF
if "confidential" in text:     # Only if this word appears
if date > deadline:            # Only if past the deadline

Practice: Reading a Real Script

Here’s a script Claude might generate. Read it and answer: What does this do?

import os
from pathlib import Path

source_folder = "./inbox"
archive_folder = "./processed"

# Create archive folder if it doesn't exist
Path(archive_folder).mkdir(exist_ok=True)

# Process each file
for filename in os.listdir(source_folder):
    if filename.endswith(".pdf"):
        # Read the file
        source_path = os.path.join(source_folder, filename)

        # Build new path
        dest_path = os.path.join(archive_folder, filename)

        # Move the file
        os.rename(source_path, dest_path)
        print(f"Moved: {filename}")

print("Processing complete.")

What it does:

  1. Sets up two folders: inbox and processed
  2. Creates the “processed” folder if it doesn’t exist
  3. For each file in inbox:
    • If it’s a PDF, move it to processed
    • Print what was moved
  4. Say “Processing complete” at the end

What it doesn’t do:

  • Process non-PDF files (they’re skipped)
  • Read the contents of files (just moves them)
  • Delete anything (rename in Python = move)

Asking Claude to Explain

You can always ask Claude to explain code:

Explain this script step by step in plain English.
Highlight anything that modifies or deletes files.

Or more specifically:

In this script, what happens to files that aren't PDFs?
Walk me through what happens when this runs on a folder
with 3 PDFs and 2 Word documents.

Red Flags to Watch For

When reading code, these should make you pause:

Deletion Commands

os.remove(file)           # Deletes a file
shutil.rmtree(folder)     # Deletes a folder and everything in it
file.unlink()             # Another way to delete

Before running: Ask where deleted files go. Usually nowhere—they’re gone.

Overwriting Files

with open(filename, 'w') as f:    # 'w' means WRITE (overwrites!)

The 'w' mode overwrites. If the file existed, its contents are replaced.

External Communication

requests.post(url, data)   # Sending data somewhere
smtplib.send_message()     # Sending email

Ask: Where is this sending data? What data exactly?

Infinite Loops

while True:
    # something

This runs forever unless there’s a break statement. Make sure you understand when it stops.

The Verification Conversation

After Claude writes code, have a verification conversation:

You: Before I run this, walk me through exactly what happens to my files.

Claude: (Explains step by step)

You: What could go wrong? What would cause this to fail or behave unexpectedly?

Claude: (Lists edge cases)

You: Can you add a “dry run” mode that shows what WOULD happen without actually doing it?

Claude: (Modifies the script)

This conversation costs nothing and might save you from data loss.

Adding Safety Features

Ask Claude to build in safeguards:

Before running the main logic, can you:
1. Print how many files will be affected
2. Ask me to confirm before proceeding
3. Create a backup of any file before modifying it

Claude will add these checks. Now you have a preview before anything happens.

Exercise: Audit This Script

Read this script and identify potential issues:

import os

folder = input("Enter folder path: ")

for file in os.listdir(folder):
    if "draft" in file.lower():
        os.remove(os.path.join(folder, file))
        print(f"Deleted: {file}")

Questions to answer:

  1. What files get deleted?
  2. Is there any confirmation before deletion?
  3. What happens if you mistype the folder path?
  4. What if a file called “draftsman_report_final.pdf” exists?

Issues:

  1. Deletes any file with “draft” anywhere in the name (including “draftsman”)
  2. No confirmation—immediately deletes
  3. If the path is wrong, it might crash or delete from an unexpected location
  4. That file would be deleted (it contains “draft”)

How to fix: Ask Claude to add confirmation, show which files match before deleting, and be more specific about what “draft” means (like filenames starting with “DRAFT_”).

What You’ve Learned

  • Code has a predictable structure: setup, configuration, logic, output
  • Look for action words to understand what code does
  • Watch for deletion, overwriting, and external communication
  • Ask Claude to explain code before running it
  • Add safety features like dry runs and confirmations

Next Lesson

Now you can read code and ask questions about it. But what happens when the code doesn’t work? The next lesson covers debugging—finding and fixing problems without needing to understand every line.