Building a Python CLI with Claude in 4 hours

I built a Python CLI in one session with Claude, going from blank directory to working tool in about four hours of wall-clock time. The tool is for parsing my morning agent’s logs into a CSV I can graph. Not a hard problem, but not trivial either. Here’s the session.

The starting point

Blank directory. No code. A clear spec in my head: read all .log files in a directory, parse each line as timestamp,level,message, write a CSV with the columns date,level,count.

The spec is small. The value of the agent is the boring 80% (parsing, edge cases, error handling, tests) that I would have written but would have taken another 4 hours if I’d done it by hand.

The prompts I used

The session was about 25 prompt-response cycles. The interesting ones:

1. The plan

Write a Python CLI that reads all .log files in a given directory, parses each line as timestamp,level,message where timestamp is ISO 8601, and writes a CSV with columns date,level,count where date is the day, level is the log level, and count is the number of messages at that level on that day. Use only the standard library. Don’t write any code yet. Plan the file layout and the test approach.

The plan was 8 numbered items. I approved it. This was the most important prompt of the session because it set the structure.

2. The first chunk

Implement the parser in parse_logs.py with full type hints and docstrings. Don’t write the tests yet.

I let it write the parser. The output was 70 lines. I read every line. It used the right libraries. It handled the timestamp,level,message split correctly. It crashed on lines that didn’t match the format. Good. I would have done the same.

3. The error handling

Now handle malformed lines. Log a warning to stderr and skip the line. Add a --strict flag that exits non-zero if any lines are skipped.

The agent added the flag, the warning, and a counter for skipped lines. The diff was 15 lines. I would have done something similar but I would have spent 10 more minutes on it.

4. The CLI entry point

Wrap it in a CLI with argparse. The script should accept a directory path (required) and an output path (default to stdout). Use if __name__ == "__main__" so the parser is importable for tests.

The CLI was clean. The argparse setup was correct. The __main__ guard was there. This is the kind of boilerplate I would have copy-pasted from an old project.

5. The tests

Write pytest tests in test_parse_logs.py. Cover: happy path, malformed line, empty file, multiple files, the —strict flag.

The tests were good. I caught two issues reading them:

  • The test for test_multiple_files had a hardcoded path that wouldn’t work on any machine
  • The test for test_strict_flag didn’t actually test the exit code

I sent these back to the agent. It fixed both. 5 minutes.

6. The final review

Run the tests. If anything fails, fix it. Then give me a one-paragraph summary of what you built and any decisions you made I should know about.

The tests passed. The summary mentioned two decisions I would have made anyway (using csv.writer instead of building strings, using pathlib for the file iteration). It also mentioned one I would have missed: it added a --version flag to the CLI for free. I kept it.

What the agent saved

The 4 hours break down roughly as:

  • 30 minutes: the plan
  • 90 minutes: the parser + CLI + tests, with me reviewing every diff
  • 60 minutes: me reading the diffs, asking follow-ups, sending back the 2 test issues
  • 30 minutes: the final review and the README

If I’d done it by hand, the same work would have taken 6-8 hours. The agent saved me about half. Not 10x. Half. The win is real but not magical.

What I’d do differently

I let the agent write the tests in one prompt. Next time I’ll write the first test myself, then ask the agent to write the rest in the same style. The agent’s test style was fine, but the first test I write establishes the conventions for the rest. Doing it that way means fewer round-trips.


← back to all posts