DEV Community

CyberMax
CyberMax

Posted on

Make a Claude skill run a script so the totals are right

Language models are unreliable at arithmetic over a long list. A Claude skill can bundle a script, so the totals come from code and Claude only explains them.

Unofficial. Not affiliated with or endorsed by Anthropic.

The pattern

A skill is a folder with a SKILL.md. Put the script next to it, pre-approve exactly that command, and tell Claude to run it:

---
name: invoice-aging-report
description: "Build an invoice aging report from a CSV of invoices. Use when the user wants to see who owes them money."
allowed-tools: Bash(python3 ${CLAUDE_SKILL_DIR}/scripts/aging.py *) Read
---
1. The CSV needs columns invoice, customer, due, amount, paid.
2. Run `python3 ${CLAUDE_SKILL_DIR}/scripts/aging.py <file.csv> --as-of YYYY-MM-DD`.
3. Show the bucket totals, then draft a polite chase message for each overdue customer.
Enter fullscreen mode Exit fullscreen mode

${CLAUDE_SKILL_DIR} expands to the skill's folder, so the same text works whether the skill lives in ~/.claude/skills/ or in a plugin.

The core of the script

from datetime import datetime
from decimal import Decimal

def bucket(days):
    return "Current" if days <= 0 else "1-30" if days <= 30 else "31-60" if days <= 60 else "61-90" if days <= 90 else "90+"

def age(rows, as_of):
    totals = {}
    for r in rows:
        owed = Decimal(r["amount"]) - Decimal(r["paid"] or "0")
        if owed <= 0:
            continue
        days = (as_of - datetime.strptime(r["due"], "%Y-%m-%d").date()).days
        totals[bucket(days)] = totals.get(bucket(days), Decimal("0")) + owed
    return totals
Enter fullscreen mode Exit fullscreen mode

Test the edges, not just the happy path

Invoices due exactly 30 or 31 days ago are where aging reports go wrong. Test them: 0 days is Current, 1 and 30 are 1-30, 31 and 60 are 31-60, 91 is 90+. Also test a part-paid invoice (count only the balance) and an unreadable row (report it, keep going).

Why bother

The model decides when to call the script and how to word the chase email; the script guarantees the numbers. The same pattern works for sorting a bank CSV into categories.

A finished, tested version of this (aging report, an expense categoriser and 11 more skills for marketing, hiring and real estate) is in the Claude Skills Pack for Small Business. Related: Skills Pack for Claude Code on our store.


Published automatically by CyberMax. Every number above comes from the linked public data; nothing is estimated.

Top comments (0)