VanaAPI

← Writing

A small log inspector built with Claude Code

Agents at the terminalEN2026-10-26

A directory of application logs is a useful starting point for a small command-line tool. The task is concrete: read a file, count messages by severity, and print a summary. This walkthrough uses Claude Code to build that tool, called logcount, with explicit requirements and tests. The finished program will run locally without making model requests.

§ Step 1: Prepare an isolated workspace

Use a machine with Python 3 and Claude Code installed. Run claude --version to check that the coding assistant is available. Claude Code can work directly inside a project directory, reading files and proposing changes as you describe the task. ([code.claude.com](https://code.claude.com/docs/en/quickstart))

In a Bash or Zsh terminal, run mkdir logcount, then cd logcount and git init. Keep the directory separate from production logs and unrelated repositories. For the first pass, use synthetic log entries rather than customer data or credentials.

§ Step 2: Connect Claude Code through Vana API

Create a Vana API account and obtain an API key. For Claude Code, set ANTHROPIC_BASE_URL to the HTTPS address of api.vanaapi.com, without an additional path, and set ANTHROPIC_AUTH_TOKEN to your key. Use shell environment variables rather than placing the credential in the repository. Vana API documents this configuration for its Anthropic-compatible connection and bills requests according to the tokens used. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))

Start claude from that same terminal. Run /status and check both the Anthropic base URL and credential source. Send a short test message before asking for implementation work. This separates connection problems from problems in the program you are about to build. ([code.claude.com](https://code.claude.com/docs/en/llm-gateway-connect))

§ Step 3: Describe the command before the implementation

Give Claude Code this prompt:

Build a Python 3 command-line tool named logcount.py using only the standard library. Accept one UTF-8 log file as a positional argument. Recognize DEBUG, INFO, WARNING, ERROR, and CRITICAL only when they are the first whitespace-delimited token. Ignore blank lines, count other lines as UNKNOWN, and print every category in that fixed order, including zero counts. Missing or unreadable files should produce a concise message on stderr and exit with status 1. Add argparse help, unittest tests, and a short README. Explain your plan before editing.

The important detail is the parsing rule. Without it, a line containing “ERROR” inside an ordinary message might be counted incorrectly. Review the proposed plan before approving changes. Claude Code supports this conversational workflow for creating files, making edits, and adding tests. ([code.claude.com](https://code.claude.com/docs/en/quickstart))

§ Step 4: Establish a fixture with known results

Ask Claude Code to create sample.log containing exactly these four lines, with no leading spaces:

  • INFO service started
  • ERROR database unavailable
  • INFO message contains ERROR but is informational
  • unstructured diagnostic text

Run python3 logcount.py sample.log. The expected counts are INFO 2, ERROR 1, UNKNOWN 1, and zero for the remaining categories. Compare every category, not just the total. This fixture checks the distinction between a severity token and a severity word inside a message.

§ Step 5: Test the boundaries

Run python3 -m unittest discover -v. Ask Claude Code to add missing coverage for empty files, blank lines, tabs between tokens, invalid UTF-8, and nonexistent paths. Specify that decoding failures must follow the same stderr and exit-status convention as unreadable files.

Keep the behavior narrow: lowercase severity names should remain UNKNOWN unless you deliberately change the specification. Ask for a focused repair when a test fails, rather than a general rewrite. After each repair, rerun the full suite yourself.

§ Step 6: Review and keep the runtime local

Inspect git diff, then try python3 logcount.py --help. Confirm that the README matches the actual arguments and that no credentials, network calls, or unnecessary dependencies entered the project.

Keep the gateway credential configured only where you intend to use it: Claude Code uses an active gateway credential instead of a saved subscription login. The generated logcount program should need neither credential nor connection. That separation leaves you with a repeatable local command and a clearly bounded use of the coding assistant. ([code.claude.com](https://code.claude.com/docs/en/llm-gateway-connect))