Python

Verified against Claude Code · 2026-07-28

Turn a one-off Python script into a proper CLI tool

A prompt that converts a script with hardcoded values or manual sys.argv indexing into a Typer or Click CLI with real help text, validation, and exit codes.

Claude CodeChatGPT (GPT-5.1)GitHub Copilot ChatCursor 2.1

The prompt

Ready to copy — highlighted parts are example details you can swap.

Convert the script described below into a real command-line tool — not a script with sys.argv indexing, and not one that still has hardcoded values a user has to edit before running it.

CURRENT SCRIPT
A script that reads a folder path and a threshold hardcoded at the top, then deletes log files older than the threshold.

FRAMEWORK
Use Typer. If it's Typer, define arguments as type-hinted function parameters — that's Typer's actual mechanism — rather than manually building a parser. If it's Click, use the @click.command() and @click.option/@click.argument decorators. If it's argparse, use argparse.ArgumentParser with explicit type=, required=, and help= on every argument.

COMMANDS NEEDED
single command: clean, with options for folder, days-old threshold, and file extension filter

REQUIREMENTS
1. Every option has a help string a stranger could act on without reading the source.
2. Every option with a sensible default gets one; every option that doesn't must be required and say so, rather than silently defaulting to None and failing three lines later with an unrelated error.
3. Validate inputs at the CLI boundary (file exists, path is a directory not a file, number is in range) and exit with a clear message and a non-zero exit code — never a raw traceback as the user-facing output.
4. Use meaningful exit codes: 0 for success, and distinct non-zero codes for distinct failure classes if there's more than one, documented in a comment.
5. If the tool does anything destructive (deletes files, overwrites data), add a --dry-run flag and default destructive behavior to off unless --yes or --force is passed.

OUTPUT FORMAT
1. The CLI entry point code.
2. The exact pyproject.toml [project.scripts] entry needed to install it as a real command.
3. Three example invocations: one happy path, one that fails validation, one using --dry-run if applicable.
Customize the highlighted detailsoptional — the prompt above already works

Why this works

Naming the exact mechanism for the chosen framework — Typer's type-hinted parameters versus Click's decorator-based options versus argparse's explicit ArgumentParser calls — stops the model from defaulting to whichever pattern shows up most in its training data regardless of which library was actually requested, a common mismatch when a prompt just says "use Typer" with no further detail. Requiring a --dry-run flag and an explicit opt-in for destructive behavior is a real safety practice lifted from how production CLI tools are actually built, and it's the detail a bare "turn this into a CLI" request reliably skips. Requiring the pyproject.toml [project.scripts] entry, not just the code, is what makes the result an installable command a user runs by name, rather than something still invoked as python script.py with a longer argument list.

What you get back

import typer from pathlib import Path from datetime import datetime, timedelta app = typer.Typer() @app.command() def clean( folder: Path = typer.Argument(..., exists=True, file_okay=False, help="Folder to clean."), days_old: int = typer.Option(30, help="Delete files older than this many days."), extension: str = typer.Option(".log", help="Only delete files with this extension."), dry_run: bool = typer.Option(False, "--dry-run", help="Show what would be deleted without deleting."), ) -> None: cutoff = datetime.now() - timedelta(days=days_old) targets = [f for f in folder.glob(f"*{extension}") if datetime.fromtimestamp(f.stat().st_mtime) < cutoff] if dry_run: typer.echo(f"Would delete {len(targets)} files.") raise typer.Exit(code=0) for f in targets: f.unlink() typer.echo(f"Deleted {len(targets)} files.") [project.scripts] logclean = "logclean.cli:app"

Verified against

Claude Code Sonnet 4.6 · 2026-07-28

ChatGPT GPT-5.1 · 2026-07-29

Changelog

  • 2026-07-29 Initial publish, verified against Claude Code (Sonnet 4.6) and ChatGPT (GPT-5.1) on Typer 0.13.

Need this built into your business?

If a prompt isn't enough — custom software, built and maintained for you — that's Scult's day job.

EXPLORE CUSTOM SOFTWARE
All Python prompts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY