Loading lesson…
Tie it all together. A command-line tool that reads a file, calls Claude, and prints a summary. Real code, real errors, real polish.
A good capstone is a script you'll actually use. This one reads any text file and streams a Claude summary to your terminal, with sensible errors and retries.
pip install anthropic export ANTHROPIC_API_KEY=sk-ant-One dependency, one env var. That is the setup.# summarize.py import argparse import sys import time from pathlib import Path import anthropic def read_text(path: Path) -> str: if not path.exists(): sys.exit(f"error: {path} does not exist") if path.stat().st_size > 500_000: sys.exit(f"error: {path} is larger than 500 KB") return path.read_text(encoding="utf-8") def summarize(text: str, bullets: int, tries: int = 3) -> None: client = anthropic.Anthropic() prompt = ( f"Summarize the following text in exactly {bullets} bullet points. " f"Each bullet under 20 words.\n\n{text}" ) for attempt in range(1, tries + 1): try: with client.messages.stream( model="claude-opus-4-7", max_tokens=1024, messages=[{"role": "user", "content": prompt}], ) as stream: for chunk in stream.text_stream: print(chunk, end="", flush=True) print() return except anthropic.APIStatusError as e: if e.status_code in (429, 529) and attempt < tries: wait = 2 ** attempt print(f"\n[retry in {wait}s: {e.status_code}]", file=sys.stderr) time.sleep(wait) continue raise def main() -> None: p = argparse.ArgumentParser(description="Summarize a text file with Claude.") p.add_argument("file", type=Path) p.add_argument("--bullets", type=int, default=5) args = p.parse_args() text = read_text(args.file) summarize(text, bullets=args.bullets) if __name__ == "__main__": main()argparse for args, streaming for UX, exponential backoff on 429/529, size guard on input. Production-ish in 40 lines.# usage python summarize.py README.md --bullets 3 python summarize.py meeting-notes.txt --bullets 7One script, many files. The kind of tool you keep on your PATH.The big idea: programming with AI is still programming. The skills you built across this track — types, tests, error handling, prompting — all show up in one small script that actually does something useful.
6 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-progx-python-ai-builder-capstone-creators
What is the main idea of "Capstone — Python CLI That Summarizes With Claude"?
Which concept is most central to "Capstone — Python CLI That Summarizes With Claude"?
What should a careful learner remember about "Always review AI output"?
You want to use AI after this lesson. What is the safest next step?
How should AI output about CLI be treated?
Name one way to verify an AI answer about CLI.