Skip to main content

Project

Ship a Summarizer CLI

Build a small command-line tool that summarises any text file you point it at — clean argument parsing, streaming output, and a useful exit code.

CLIPythonSummarization~40 min

By the end of this project you'll have a summarize command on your $PATH. Pipe it a file or paste text in via stdin and it returns three bullets — the format you keep coming back to in real work.

Tip

This project assumes you can already make a model call. If not, do Build a Chatbot first.

Step-by-step

The build

  1. 1. Scaffold the CLI

    Create a summarize script with a shebang. Use argparse (Python) or commander (Node) for one positional argument: a file path. If no path is given, read from stdin. Return version with --version.

  2. 2. Write the summarise prompt

    Three bullets, no jargon, action-oriented. Reuse the Plain-English summary prompt from the Library — that's exactly what it's for.

  3. 3. Stream the output

    Use the streaming API and print tokens as they arrive. Flushing is important — pipe-friendly tools must not buffer until the end.

  4. 4. Set proper exit codes

    Empty input → exit 2. Model error → exit 1. Success → exit 0. This makes summarize file.md && echo done work as expected in scripts.

  5. 5. Install it on your PATH

    chmod +x summarize, drop it in ~/bin (or pipx install .), and use it tomorrow morning instead of opening a chat window.

What you learned

  • CLIs are good interfaces for AI tools — composable, scriptable, no app to babysit.
  • Streaming matters; humans tolerate latency much better when they see progress.
  • Exit codes are how you turn a one-off script into a piece of infrastructure.