Using Claude Code for Software Development
Build a CSV summarizer with Claude Code, verify its data contract, and keep changes narrowly scoped.
Overview
For learners who want to complete this practical exercise with inspectable sample data and explicit checks.
- Start Claude Code in an isolated practice folder.
- Request a small feature with acceptance cases.
- Inspect the diff and independently run validation commands.
You will build: A summarize.py that totals CSV quantities and rejects negative data.
Prerequisites
- Python 3.10+, Git, and Claude Code access; install using the official quickstart.
Claude Code requires eligible account access or a billed API configuration. Follow official installation/sign-in guidance; this exercise assumes no particular plan or model.
Step-by-step tutorial
Step 1. Prepare a repository and small input
mkdir claude-csv-lab
cd claude-csv-lab
git init
claude --version
claudeIf claude is unavailable, install it using the official quickstart; installation choices vary by operating system. Create data.csv with the two rows below. Use fictional records only.
item,quantity
notebook,2
pencil,3Step 2. Request a bounded implementation
Create summarize.py: accept one CSV path argument, read UTF-8 with csv.DictReader, require non-negative integer quantity values, and print TOTAL=<sum>. Invalid data must fail clearly. Do not install libraries, call the network, or edit the source CSV. Add automated tests for valid data, a negative quantity, and a missing column. Limit changes to this exercise; do not commit.Step 3. Compare with a minimal implementation
Save the reference below as summarize.py to run the exercise without an active Claude Code session. It deliberately uses the standard library so attention stays on the data contract. Claude Code may produce a different structure, but it must satisfy the same checks.
import csv
import sys
def total(path):
with open(path, encoding="utf-8", newline="") as stream:
rows = csv.DictReader(stream)
if "quantity" not in (rows.fieldnames or []):
raise ValueError("missing quantity column")
result = 0
for row in rows:
value = int(row["quantity"])
if value < 0:
raise ValueError("negative quantity")
result += value
return result
if __name__ == "__main__":
if len(sys.argv) != 2:
raise SystemExit("usage: python3 summarize.py FILE.csv")
print(f"TOTAL={total(sys.argv[1])}")Step 4. Run success and failure paths
python3 summarize.py data.csv
python3 -m unittest -vThe first command must print TOTAL=5. The test command only matters after tests exist: verify that it does not say “Ran 0 tests.” Create bad.csv with quantity=-1 and run it; the program must fail rather than print a plausible total. Inspect the diff to ensure the script does not modify its input CSV.
Verification
- Valid input totals 5; negative input and a missing column are rejected.
- Do not accept “0 tests” as successful verification.
Troubleshooting
Claude Code proposes unrelated file changes
Cause: Task scope or working directory is ambiguous.
Fix: Restate the allowed files and inspect the proposed diff.
The CSV has a BOM or different column name
Cause: Real input does not match the UTF-8/quantity contract.
Fix: Inspect the header, decide whether to support utf-8-sig or aliases, and add a test before changing code.
Exercises & extensions
- Add empty-file and non-integer quantity tests.
- Ask Claude Code for a short usage guide based strictly on verified behavior.
The script contains no inventory or returns business policy. Use no customer data or credentials in the practice session.
