When working with Claude agents like Claude Code, every interaction costs tokens. The more back-and-forth, the higher the usage. But there's a simple strategy to dramatically cut costs: write reusable scripts.
The Problem
Every time you ask Claude to perform a repetitive task, it consumes tokens for:
- Understanding your request
- Generating the solution
- Executing commands one by one
- Reporting results
This adds up quickly, especially for tasks you do regularly.
The Solution: Scripts
Instead of asking Claude to do the same tasks repeatedly, create bash or python scripts that handle common operations. Then Claude only needs to run a single command.
Example: File Operations
Instead of asking Claude to read multiple files, search for patterns, and summarize:
#!/bin/bash
# summarize-project.sh
echo "=== Project Structure ==="
find . -type f -name "*.ts" | head -20
echo ""
echo "=== Package Dependencies ==="
cat package.json | grep -A 50 '"dependencies"'
echo ""
echo "=== Recent Changes ==="
git log --oneline -10
Now Claude just runs ./summarize-project.sh — one command, minimal tokens.
Example: Development Workflow
#!/usr/bin/env python3
# dev-check.py
import subprocess
import json
def run_checks():
print("Running type check...")
subprocess.run(["npm", "run", "typecheck"], capture_output=True)
print("Running linter...")
subprocess.run(["npm", "run", "lint"], capture_output=True)
print("Running tests...")
result = subprocess.run(["npm", "test"], capture_output=True, text=True)
print(result.stdout)
if __name__ == "__main__":
run_checks()
Benefits
- Lower token usage — One command instead of multiple interactions
- Consistency — Same process every time
- Speed — Scripts run faster than conversational back-and-forth
- Reusability — Use across projects and sessions
Pro Tips
- Store scripts in a
scripts/folder in your project - Add them to your
.bashrcor PATH for easy access - Document what each script does with comments
- Let Claude help you write the script once, then reuse it forever
The best Claude interaction is the one you don't need to have. Build your toolkit of scripts, and watch your usage drop while productivity soars.