Your First Automation
Stop reading. Start doing. Run your first real Python automation right now — from Claude Code prompt to actual renamed files.
Reading about automation is not the same as running automation.
This section is different from everything before it. There is nothing to study here. There is only one thing to do: run a real Python script that solves a real problem.
By the end of this page, you will have:
- Asked Claude Code to write a Python script
- Run that script on actual files
- Seen files renamed automatically
- Handled an error (we're going to manufacture one so you learn the repair workflow)
This takes about 20 minutes. No shortcuts.
The Task
You have 20 PDF files in a folder. Someone sent them to you with random names. You need them renamed to a numbered, sequential format — padded to 3 digits so they sort correctly: Invoice_001.pdf before Invoice_010.pdf before Invoice_020.pdf.
Normally: open each file, right-click, rename, type the new name. Twenty times. Roughly 10 minutes if you're fast.
We will do all 20 in under 2 seconds.
Invoice_10.pdf sorts before Invoice_2.pdf in Windows Explorer because computers sort text character by character. Invoice_010.pdf sorts correctly because 0 comes before 1. This is the kind of practical detail that separates scripts that work from scripts that require manual cleanup.Step 1: Create Test Files
We need test files to work with. We will create them using the command prompt so you don't need to find 20 real PDFs.
Navigate to the Desktop
Open your command prompt and type cd Desktop and press Enter.
Create the project folder
Type mkdir first-automation and press Enter. Then cd first-automation and press Enter.
Create the test-invoices subfolder
Type mkdir test-invoices and press Enter. Then cd test-invoices and press Enter.
Create 20 dummy PDF files
Run this command to create 20 files with random-looking names (these are not real PDFs — just files with the .pdf extension, which is all we need for renaming practice):
for %i in (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) do echo dummy > invoice_random_%i.pdf
Verify they all exist
Type dir and press Enter. You should see 20 files listed.
Return to the project folder
Type cd .. and press Enter. You are now in Desktop\first-automation\. The test files are in Desktop\first-automation\test-invoices\.
Step 2: Open Claude Code
Open VS Code
Launch VS Code from the Start menu.
Open the Claude Code terminal
Press Ctrl+Shift+P, type Claude Code, press Enter. Or open your regular terminal and type claude.
Step 3: Give Claude Code the Prompt
Type this prompt exactly. Do not paraphrase — be precise:
"Write a Python script that renames all PDF files in C:\Users[YourUsername]\Desktop\first-automation\test-invoices. Rename them to Invoice_001.pdf, Invoice_002.pdf, up to Invoice_020.pdf — padded to 3 digits. Before making any changes, show me a preview list of every old name to new name pair. Only proceed after I type 'yes'."
Replace [YourUsername] with your actual Windows username. To find it, open the command prompt and type echo %USERNAME%. Whatever it prints — that is your username. The path must be exact — a single wrong character will cause the script to report that the folder doesn't exist.
Step 4: What Claude Will Generate
Claude Code will produce a Python script. Read through it before running and find these three things:
- The folder path — confirm it matches your actual path
- The preview section — the code that prints old name to new name pairs
- The confirmation check — the code that waits for you to type
yes
If any of these three are missing, ask Claude to add them before you save the script.
Step 5: Save the Script
Claude Code may have already created the file for you. If not:
Open Notepad
Press Windows key + R, type notepad, press Enter.
Paste the code
Copy the entire script Claude generated. Click inside Notepad and press Ctrl+V to paste.
Save as a Python file
Go to File > Save As. Navigate to Desktop\first-automation\. Change "Save as type" to "All Files". Set the filename to rename_invoices.py. Click Save.
Verify it saved correctly
In the command prompt (in the first-automation folder), run dir. You should see rename_invoices.py listed.
rename_invoices.py.txt. Python won't recognize it. The .py extension is what makes it a Python file.You should see rename_invoices.py in the list.
Step 6: Run the Script
Navigate to the right folder
In the command prompt, make sure you are in Desktop\first-automation\. If not, run cd Desktop\first-automation.
Run the script
Type python rename_invoices.py and press Enter. The script starts.
Read the preview carefully
The script will show you every old name and its corresponding new name. Read each line. Ask yourself: does this look right? Are the numbers sequential? Are they padded to 3 digits?
Confirm with yes
If the preview looks correct, type yes and press Enter. Watch the output as it renames each file.
Verify the results
Run dir test-invoices in the command prompt. You should see Invoice_001.pdf through Invoice_020.pdf. Sorted, sequential, clean.
Twenty files. Named correctly. Under 2 seconds of actual work.
test-invoices folder. See the files in Explorer sorted cleanly. That physical result — real files, renamed — is the proof that what you just did was real automation, not a simulation.Step 7: Handling an Error (The Repair Workflow)
Every developer, at every skill level, encounters errors. The question is not "will I get errors" — the answer is yes. The question is "what do I do when I get one."
Let's see a real error and fix it.
Manufacture an error
Open rename_invoices.py in Notepad. Find the line that sets the folder path. Change it to point to a folder that doesn't exist — for example, change test-invoices to test-invoices-typo.
Save and run
Save the file. In the command prompt, run python rename_invoices.py again.
Read the error
You will see a clear error message saying the folder was not found. This is the script catching a problem cleanly rather than silently failing. Note the exact wording.
Fix it
Change the path back to the correct folder name. Save. Run again.
The files were already renamed in Step 6. So if you run the script again, it will try to rename Invoice_001.pdf to Invoice_001.pdf (no change needed). A well-written script handles this gracefully — it detects that the files are already in the right format and either skips them or reports them.
Step 8: What to Do When Claude's Code Has a Real Error
Sometimes — not often, but sometimes — Claude generates code that doesn't work as expected. Here is the exact repair workflow:
If the script crashes with a Python error (a "traceback"):
Copy the entire error message. Go back to Claude Code. Paste it and say: "I ran the script and got this error. Fix it." Claude will explain what went wrong and give you the corrected code.
If the script runs but produces wrong output:
Say: "The script ran but renamed the files incorrectly — it produced [describe what you see] instead of [describe what you expected]. Fix the renaming logic."
If you're not sure what it did or what went wrong:
Say: "The script ran but I'm not sure if it did the right thing. Walk me through what it did step by step and tell me if anything went wrong."
The key insight: you are not debugging Python. You are describing symptoms to Claude, and Claude fixes the Python. Your job is to notice when the output is wrong and describe it accurately.
What Just Happened
Stop and register what you just did.
You had a folder with 20 chaotically named PDF files. You asked Claude Code to write a script in plain English. You read the script at a high level and understood what it was doing. You ran it. You saw a preview. You confirmed. The files were renamed — all 20 — in under 2 seconds.
The next time you have 500 files to rename, you now know the workflow:
Describe the task to Claude Code
Be specific about folder paths, filename patterns, and what "done" looks like.
Read the preview carefully
Never type yes without reading every old name to new name pair.
Confirm
Type yes and press Enter.
Verify the output
Run dir and confirm the results match what the preview promised.
The next time you have a folder of Excel files to combine, you know the workflow. The next time you need to validate a list of GST numbers, you know the workflow. The next time you need to send 200 client emails from a spreadsheet, you know the workflow.
The workflow is always the same. Only the task changes.
Taking This Further
The script you just ran is a starting point. Here are natural next steps — each one is a single Claude Code prompt away:
Add logging to a file: Instead of just printing what happened, write the results to a log file so you have a record of every run. Ask Claude: "Extend the script to write the results to a log file called rename_log.txt with the timestamp and the old/new names."
Read filenames from an Excel sheet: Instead of numbering sequentially, use a column in Excel to specify exactly what each file should be renamed to. Ask Claude: "Modify the script to read target filenames from column B of rename_list.xlsx, where column A is the current filename."
Run automatically on a schedule: Windows Task Scheduler can run a Python script at a set time — every Monday morning, every month on the 1st, etc. Ask Claude: "Write instructions for scheduling this script to run every Monday at 8am using Windows Task Scheduler."
Ask Claude Code for any of these extensions. Claude will extend the script. You run it. The capability grows.
The compound effect: Every automation you build saves you time. That saved time can be spent building more automations. The first one takes 20 minutes. The tenth one takes 5 minutes. The fiftieth one takes 2 minutes — because you know exactly how to describe what you want, and Claude Code gives you working code on the first try more often.
This is the compound effect of knowing what to ask for.
Module Complete
You have finished the Power of Code module.
- You controlled your computer with words
- You saw Python eliminate hours of manual work in seconds
- You ran your first real automation
- You learned the repair workflow for when things go wrong
Everything from here — React, Supabase, building web apps — is built on this foundation. Code is precise instructions that computers follow exactly. You now feel what that means.
The next module: AI Basics — understanding tokens, context windows, and how to give Claude Code the most powerful instructions possible.