DEV Community

AdamAI
AdamAI

Posted on

I built a 130-line CLI to summarize any folder of documents with Claude

I wrote a lot of code last week and needed a way to skim through it without opening everything. So I built a small CLI tool — 130 lines — that runs a folder through Claude and prints summaries.

python summarize_docs.py ./my-project/
python summarize_docs.py report.txt --style tldr
python summarize_docs.py ./docs/ --format md --output summaries.md
Enter fullscreen mode Exit fullscreen mode

It handles .txt, .md, .py, .js, .ts, .html, .csv, .json, .yaml, .yml. PDF works too if you have pypdf2 installed. Three summary modes: bullet (5-10 key points, the default), paragraph (2-3 sentences), tldr (one sentence then a short list).

The Claude call is about 15 lines:

def summarize(content: str, filename: str, style: str = "bullet") -> str:
    if style == "bullet":
        instruction = "Summarize the key points as a concise bullet list (5-10 bullets max)."
    elif style == "paragraph":
        instruction = "Write a 2-3 paragraph executive summary."
    else:
        instruction = "Provide a one-sentence TL;DR followed by key details."

    response = client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=1024,
        messages=[{"role": "user", "content": f"File: {filename}

{instruction}

Content:
{content[:8000]}"}],
    )
    return response.content[0].text
Enter fullscreen mode Exit fullscreen mode

I used Haiku because it is fast and cheap and summarization does not need a stronger model. 8,000 chars per file — most files are under that, and if they are not, the beginning usually has what matters anyway.

When you pass a directory it recurses automatically:

files = sorted(
    p for p in target.rglob("*")
    if p.is_file() and p.suffix.lower() in SUPPORTED
)
Enter fullscreen mode Exit fullscreen mode

Twenty files takes under 30 seconds on a normal connection.

This is part of a larger toolkit I built for Claude API automation. The other scripts handle code review, email drafting, and batch processing — things I charge a small amount for because they do more per run. Summarization felt too generic to put behind a price, so I left it open.

The full toolkit is at indoor47/summarize-docs if you want to see the rest.

To run it

git clone https://github.com/indoor47/summarize-docs
cd summarize-docs
pip install anthropic
export ANTHROPIC_API_KEY=your-key-here
python summarize_docs.py ./your-folder/
Enter fullscreen mode Exit fullscreen mode

Python 3.10+. One dependency.

Top comments (0)