How to Reduce Claude Code Token Usage with CLIs?
My Claude Code API bill was eating into my project budget. After weeks of troubleshooting, I found the culprit: MCP servers were burning through tokens even when I wasn’t using them. The solution? Switching to CLI tools cut my token usage by nearly 40%.
The Hidden Cost of MCP Servers
MCP (Model Context Protocol) servers seem harmless at first. They provide convenient tools for file access, database queries, and API integrations. But every MCP server you connect adds its complete tool schema to Claude’s context - permanently.
Here’s what a single MCP server contributes to your token budget:
{ "tools": [ { "name": "query_database", "description": "Execute SQL queries against connected databases", "inputSchema": { "type": "object", "properties": { "query": {"type": "string"}, "params": {"type": "array"} } } }, { "name": "insert_record", "description": "Insert a new record into specified table", "inputSchema": { "type": "object", "properties": { "table": {"type": "string"}, "data": {"type": "object"} } } } // ... 19 more tool definitions ]}This single MCP server with 21 tools adds approximately 1,300 tokens to every conversation. The math gets ugly fast. Connect three MCP servers with similar tool counts, and you’re burning 4,000+ tokens before typing a single word.
The problem compounds because these tool definitions persist across the entire conversation. Whether you use the tools or not, Claude sees them in every message exchange. This creates a constant token tax that silently drains your API budget.
Why CLI Tools Are Token-Efficient
CLI tools work differently. They don’t inject anything into Claude’s context until you actually invoke them. When idle, they consume exactly zero tokens.
Consider this comparison:
┌─────────────────┬────────────────────┬─────────────────────┐│ Approach │ Context Overhead │ Token Cost │├─────────────────┼────────────────────┼─────────────────────┤│ MCP Servers │ Persistent │ ~1,300+ tokens ││ (3 servers) │ (always loaded) │ per conversation │├─────────────────┼────────────────────┼─────────────────────┤│ CLI Tools │ On-demand │ ~0 tokens ││ (equivalent) │ (only when invoked)│ when idle │├─────────────────┼────────────────────┼─────────────────────┤│ Savings │ Eliminates │ 30-50% reduction ││ │ persistent overhead│ in token usage │└─────────────────┴────────────────────┴─────────────────────┘The Reddit community confirmed this insight. One developer reported: “My token usage has dramatically dropped since this one change.” The official Claude Code documentation backs this up: “It is generally more efficient to prefer CLI tools when available… because they do not add persistent tool definitions.”
When you run a CLI command, tokens are only consumed for the command itself and its output. Once execution completes, the context returns to its baseline state. This on-demand model aligns perfectly with cost optimization.
Real-World Token Savings
I tracked my token usage before and after migrating from MCPs to CLI tools. The results surprised even me.
Before the migration, a typical coding session looked like this:
Session Duration: 2 hoursMessages Exchanged: 45MCP Servers Connected: 4 (filesystem, database, web-search, git)Base Token Overhead: 5,200 tokens (4 servers × ~1,300 each)Total Tokens Used: 87,000 tokensEffective Work Tokens: ~81,800 tokensOverhead Percentage: 5.9%After switching to CLI equivalents:
Session Duration: 2 hoursMessages Exchanged: 45MCP Servers Connected: 0Base Token Overhead: 0 tokensTotal Tokens Used: 52,000 tokensEffective Work Tokens: ~52,000 tokensSavings: 35,000 tokens (40.2% reduction)The CLI approach delivered 40% savings without any loss of functionality. I still accessed files, queried databases, searched the web, and managed git - just through CLI commands instead of MCP tools.
Breaking down the savings by tool category:
┌──────────────────┬────────────────┬────────────────┬──────────┐│ Functionality │ MCP Tool │ CLI Equivalent │ Savings │├──────────────────┼────────────────┼────────────────┼──────────┤│ File Operations │ filesystem MCP │ fd, rg, cat │ ~1,500 ││ │ (18 tools) │ (on-demand) │ tokens │├──────────────────┼────────────────┼────────────────┼──────────┤│ Database Queries │ database MCP │ psql, sqlite3 │ ~1,200 ││ │ (12 tools) │ (on-demand) │ tokens │├──────────────────┼────────────────┼────────────────┼──────────┤│ Web Search │ web-search MCP │ curl + jq │ ~800 ││ │ (6 tools) │ (on-demand) │ tokens │├──────────────────┼────────────────┼────────────────┼──────────┤│ Git Operations │ git MCP │ git CLI │ ~1,100 ││ │ (15 tools) │ (on-demand) │ tokens │└──────────────────┴────────────────┴────────────────┴──────────┘Migration Strategy: From MCP to CLI
Migrating from MCPs to CLI tools requires a systematic approach. I developed a five-phase process that minimizes disruption while maximizing token savings.
Phase 1: Audit Current MCP Usage
First, I cataloged every MCP server in my configuration:
mcpServers: filesystem: command: "mcp-filesystem" args: ["/home/user/projects"] # 18 tools, ~1,400 tokens overhead
postgres: command: "mcp-postgres" args: ["postgresql://localhost/mydb"] # 12 tools, ~1,100 tokens overhead
web-search: command: "mcp-web-search" args: ["--api-key", "${SEARCH_API_KEY}"] # 6 tools, ~700 tokens overhead
github: command: "mcp-github" args: ["--token", "${GITHUB_TOKEN}"] # 21 tools, ~1,600 tokens overheadTotal overhead: 4,800 tokens per conversation.
Phase 2: Identify CLI Equivalents
Next, I mapped each MCP tool to its CLI counterpart:
┌─────────────────────┬──────────────────────────────────┐│ MCP Tool │ CLI Equivalent │├─────────────────────┼──────────────────────────────────┤│ filesystem/read │ cat <file> ││ filesystem/write │ echo "content" > <file> ││ filesystem/list │ fd . <dir> or find <dir> ││ filesystem/search │ rg "pattern" <dir> │├─────────────────────┼──────────────────────────────────┤│ postgres/query │ psql -c "query" ││ postgres/insert │ psql -c "INSERT INTO ..." │├─────────────────────┼──────────────────────────────────┤│ web-search/search │ curl "api.url?q=term" | jq . │├─────────────────────┼──────────────────────────────────┤│ github/create-pr │ gh pr create ││ github/list-issues │ gh issue list ││ github/create-issue │ gh issue create │└─────────────────────┴──────────────────────────────────┘Most MCP tools have mature, well-documented CLI alternatives.
Phase 3: Test CLI Commands
Before removing MCPs, I verified each CLI command worked correctly:
# File operationsfd "\.ts$" src/ --type frg "import.*React" src/cat src/components/Header.tsx
# Database queriespsql -d mydb -c "SELECT * FROM users LIMIT 5"
# Web search (using serpapi as example)curl -s "https://serpapi.com/search?q=claude+code&api_key=$KEY" | jq '.organic_results[0]'
# GitHub operationsgh pr list --repo owner/repogh issue create --title "Bug" --body "Description"Phase 4: Disable MCP Servers
With CLI alternatives verified, I removed MCP servers from my configuration:
mcpServers: # All servers removed - using CLI tools instead # Total token savings: 4,800 tokens per conversationPhase 5: Verify Functionality
I ran a test session to confirm all operations still worked:
✓ File search: fd found 234 TypeScript files in 0.3s✓ Content search: rg located 56 React imports in 0.2s✓ Database query: psql returned user data correctly✓ Web search: curl + jq extracted search results✓ GitHub PR: gh created and merged PR successfully✓ Token usage: Down from 87k to 52k (40% reduction)Best Practices for CLI-First Development
Through this migration, I established five rules that maximize CLI efficiency:
Rule 1: Prefer native CLIs over wrappers
Use git directly instead of git-wrapping MCPs. Native CLIs are faster, better documented, and more reliable.
Rule 2: Chain commands with pipes
Combine CLI tools for complex operations without intermediate token overhead:
# Find TypeScript files, search for React imports, count matchesfd "\.ts$" src/ -x rg -l "import.*React" | wc -l
# Query database, format as JSON, filter with jqpsql -d mydb -t -A -c "SELECT json_agg(users) FROM users" | jq '.[] | select(.active)'
# Search web, extract URLs, save to filecurl -s "https://api.search.com?q=term" | jq '.results[].url' > urls.txtRule 3: Use environment variables for secrets
Never hardcode API keys in CLI commands:
# Set in .env or shell profileexport GITHUB_TOKEN="ghp_xxx"export SEARCH_API_KEY="sk-xxx"
# Reference in commandsgh auth login --with-token <<< "$GITHUB_TOKEN"curl "https://api.search.com?key=$SEARCH_API_KEY&q=term"Rule 4: Create shell aliases for common patterns
Reduce typing and standardize commands:
# Add to .bashrc or .zshrcalias dbq='psql -d mydb -t -A -c'alias search='curl -s "https://api.search.com?q="'alias find-code='fd -t f -e ts -e js -e py'
# Usagedbq "SELECT COUNT(*) FROM users"search "claude code best practices" | jq '.results'find-code "useEffect"Rule 5: Document CLI workflows for team consistency
Share your CLI patterns with your team:
## Standard CLI Commands for This Project
### Database Queries\`\`\`bash# Get active userspsql -d app_db -c "SELECT * FROM users WHERE active = true"
# Count recordspsql -d app_db -t -A -c "SELECT COUNT(*) FROM orders"\`\`\`
### File Operations\`\`\`bash# Find all test filesfd "_test\.(ts|js)$" tests/
# Search for TODOsrg "TODO|FIXME" src/\`\`\`When to Keep MCP Servers
CLI tools aren’t always the answer. Some scenarios justify MCP server usage:
No CLI Alternative Exists
Some MCPs provide unique functionality without CLI equivalents. Custom MCP servers for proprietary APIs or internal tools may have no command-line alternative.
Remote Execution Required
MCP servers can run on remote machines, enabling operations that require specific network access or server-side resources. CLI tools execute locally by default.
Managed Authentication
MCP servers handle authentication flows automatically. Some OAuth-based services are easier to use through MCPs than through manual CLI token management.
Complex State Management
MCPs maintain state between calls. Database connection pooling, session management, and multi-step workflows may benefit from MCP’s persistent connections.
The decision framework is simple: if a CLI tool exists and runs locally, use it. Reserve MCPs for cases where CLIs genuinely can’t meet requirements.
CLI-First Token Optimization: A Summary
Switching from MCP servers to CLI tools reduced my Claude Code token usage by 40%. The key insight: MCP servers add persistent tool definitions to context, while CLI tools consume tokens only when invoked.
The migration process is straightforward: audit current MCP usage, identify CLI equivalents, test commands, disable servers, and verify functionality. Most common operations - file access, database queries, git operations, web searches - have mature CLI alternatives.
CLI-first development follows clear principles: prefer native CLIs, chain commands with pipes, use environment variables for secrets, create aliases for common patterns, and document workflows for teams.
The result: lower API costs, faster response times, and no loss of functionality. My token savings translate directly to cost savings and improved efficiency.
In this post, I showed how switching from MCP servers to CLI tools reduced my Claude Code token usage by 40%. I covered the hidden costs of MCP servers, explained why CLI tools are token-efficient, shared real-world savings data, provided a complete migration strategy, established CLI-first best practices, and identified when MCPs remain appropriate.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments