Skip to main content

Capstone: Build an Automation Script

Time: 30-60 minutes | Skills: Headless Mode, PowerShell Scripting, JSON Processing

The Scenario

You are a developer who just inherited a project folder full of text files -- notes, logs, documentation drafts, and random snippets. Nobody has time to read through all of them to figure out what is important. Your job is to build a PowerShell script that uses Claude Code in headless mode to automatically process every file in the folder: summarize it, categorize it, and generate a clean report.

By the end of this capstone, you will have a working automation script that demonstrates everything you learned in Module 11.

Why does this matter?

In real-world work, you often need to process many files quickly. Maybe it is reviewing pull request descriptions, summarizing meeting notes, or categorizing support tickets. The script you build here is a template you can adapt for any of those tasks.


Prerequisites

Before you begin, make sure you have completed all three lessons in Module 11:

  • You can run claude -p "test" successfully in PowerShell
  • You understand JSON output and ConvertFrom-Json
  • You know how to loop over files and handle errors in PowerShell

Step-by-Step Instructions

Step 1 -- Set Up the Project Folder

Open PowerShell and create a new folder for this capstone:

mkdir $env:USERPROFILE\Documents\claude-tutorials\capstone-11
cd $env:USERPROFILE\Documents\claude-tutorials\capstone-11

Step 2 -- Create Sample Files

Create at least 5 sample text files that simulate the messy project folder. You can use these or make your own:

"Meeting with design team on Monday. Discussed new landing page layout. Action items: update wireframes, send color palette to Sarah, schedule follow-up for Friday." | Out-File notes1.txt

"ERROR 2025-03-15 14:22:01 - Database connection timeout after 30 seconds. Retried 3 times. Service restarted automatically." | Out-File log1.txt

"# API Documentation Draft`nThe /users endpoint returns a JSON array of user objects. Each user has an id, name, and email field. Authentication is required via Bearer token." | Out-File api-docs.txt

"TODO: Fix the login bug where users get redirected to a 404 page after password reset. Priority: HIGH. Reported by 3 customers this week." | Out-File bug-report.txt

"Weekly metrics: 1,200 active users (up 15%), 45 new signups, average session duration 8 minutes, 99.2% uptime." | Out-File metrics.txt

Step 3 -- Build the Automation Script

Create a file called process-files.ps1 using Notepad or any text editor:

notepad process-files.ps1

Your script must do the following:

  1. Accept a folder path as a parameter (default to the current directory)
  2. Find all .txt files in the folder
  3. For each file, call claude -p in headless mode with JSON output to:
    • Summarize the file in one sentence
    • Categorize it as one of: meeting-notes, log, documentation, bug-report, metrics, or other
  4. Parse the JSON response and extract the result
  5. Track the total cost across all files
  6. Handle errors gracefully (skip files that fail, do not crash)
  7. Generate a report file called report.md that includes:
    • A timestamp of when the report was generated
    • A table or list of each file with its category and summary
    • The total cost at the bottom
Prompt design hint

You can ask Claude to return structured text that is easy to parse. For example:

Analyze this file. On the first line write ONLY one of these categories: meeting-notes, log, documentation, bug-report, metrics, other. On the second line, write a one-sentence summary.

Then in your script, split the response by newline to get the category and summary separately.

Step 4 -- Test the Script

Run your script against the sample files:

pwsh -File process-files.ps1 -FolderPath "."

Check that:

  • The terminal shows progress as each file is processed
  • No errors cause the script to crash
  • A report.md file is created with all five files listed
  • The total cost is displayed

Step 5 -- Open and Review the Report

Open the generated report:

notepad report.md

Verify that each file has a sensible category and summary. If any file is miscategorized, think about how you could improve the prompt to get better results.

Step 6 -- Add Error Handling

Test your error handling by adding a file that might cause problems:

"" | Out-File empty-file.txt

Run the script again. It should handle the empty file without crashing -- either by skipping it or by noting it in the report.

Step 7 -- Stretch Goal: Add a Budget Limit

Add an optional -MaxBudget parameter to your script. If the running total cost exceeds the budget, stop processing and print a warning:

param(
[string]$FolderPath = ".",
[double]$MaxBudget = 0.50
)

This teaches you to think about cost control in automated workflows -- a critical real-world skill.


Self-Assessment

Use this checklist to confirm you covered all the essentials:

  • Created a PowerShell script that calls Claude in headless mode with -p
  • Script uses --output-format json and parses the response with ConvertFrom-Json
  • Script loops over multiple files and processes each one
  • Script handles errors gracefully (does not crash on bad input)
  • Script generates a report.md file with categories and summaries
  • Script tracks and displays the total cost
  • Tested the script end-to-end with at least 5 files
How did it go?

If you checked all seven boxes, you have built a real automation tool. This is the kind of script that saves hours of manual work in a real job. If you got stuck, re-read Lessons 1 and 2 of this module, then try again -- the repetition will help.


Congratulations!

You have completed Module 11. You now know how to run Claude Code without an interactive session, write scripts that call Claude automatically, and even integrate Claude into CI/CD pipelines. These skills turn Claude from a chat tool into a powerful automation engine.

In Module 12, you will learn how to use Claude Code inside your code editor (VS Code and JetBrains IDEs) for an even smoother development experience.


Help Us Improve

How was this lesson? Take 2 minutes to share your feedback — it helps us make the tutorials better for everyone.

Give Feedback →