Skip to main content

A powerful CLI tool for developers using Claude AI with multi-API routing, test generation, code review, and usage tracking

Project description

Claude Dev CLI

A powerful command-line tool for developers using Claude AI with multi-API routing, test generation, code review, and comprehensive usage tracking.

Features

🔑 Multi-API Key Management

  • Secure Storage: API keys stored in system keyring (macOS Keychain, Linux Secret Service, Windows Credential Locker)
  • Route tasks to different Claude API keys (personal, client, enterprise)
  • Automatic API selection based on project configuration
  • Automatic migration from plaintext to secure storage

🧪 Developer Tools

  • Test Generation: Automatic pytest test generation for Python code
  • Code Review: Comprehensive code reviews with security, performance, and best practice checks
  • Debug Assistant: Analyze errors and get fixes with explanations
  • Documentation: Generate docstrings and README documentation
  • Refactoring: Get suggestions for code improvements
  • Git Integration: Generate conventional commit messages from diffs

📊 Usage Tracking

  • Track token usage per API key
  • Cost estimation based on current pricing
  • Filter by date range and API config
  • Detailed breakdowns by model, date, and API

💬 Interaction Modes

  • Single-shot: Quick questions with piping support
  • Interactive: Chat mode with conversation history
  • Streaming: Real-time responses

🎒 TOON Format Support (Optional)

  • Token Reduction: 30-60% fewer tokens than JSON
  • Cost Savings: Reduce API costs significantly
  • Format Conversion: JSON ↔ TOON with CLI tools
  • Auto-fallback: Works without TOON installed

Installation

Basic Installation

pip install claude-dev-cli

With TOON Support (Recommended for Cost Savings)

# Install with TOON format support for 30-60% token reduction
pip install claude-dev-cli[toon]

Quick Start

1. Set Up API Keys

# Add your personal API key
export PERSONAL_ANTHROPIC_API_KEY="sk-ant-..."
cdc config add personal --default --description "My personal API key"
# 🔐 Stored securely in system keyring

# Add client's API key
export CLIENT_ANTHROPIC_API_KEY="sk-ant-..."
cdc config add client --description "Client's Enterprise API"

# List configured APIs (shows storage method)
cdc config list

# Manually migrate existing keys (automatic on first run)
cdc config migrate-keys

2. Basic Usage

# Ask a question
cdc ask "explain asyncio in Python"

# With file context
cdc ask -f mycode.py "review this code"

# Pipe input
cat error.log | cdc ask "what's causing this error?"

# Interactive mode
cdc interactive

# Use specific API
cdc ask -a client "generate tests for this function"

3. Developer Commands

# Generate tests
cdc generate tests mymodule.py -o tests/test_mymodule.py

# Code review
cdc review mymodule.py

# Debug errors
python script.py 2>&1 | cdc debug

# Generate documentation
cdc generate docs mymodule.py

# Refactor suggestions
cdc refactor legacy_code.py

# Git commit message
git add .
cdc git commit

4. Usage Tracking

# View all usage
cdc usage

# Last 7 days
cdc usage --days 7

# Filter by API
cdc usage --api client

5. TOON Format (Optional - Reduces Tokens by 30-60%)

# Check if TOON is installed
cdc toon info

# Convert JSON to TOON
echo '{"users": [{"id": 1, "name": "Alice"}]}' | cdc toon encode
# Output:
# users[1]{id,name}:
# 1,Alice

# Convert file
cdc toon encode data.json -o data.toon

# Convert TOON back to JSON
cdc toon decode data.toon -o data.json

# Use in workflows
cat large_data.json | cdc toon encode | cdc ask "analyze this data"

Configuration

Secure API Key Storage

🔐 Your API keys are stored securely and never in plain text.

  • macOS: Keychain
  • Linux: Secret Service API (GNOME Keyring, KWallet)
  • Windows: Windows Credential Locker
  • Fallback: Encrypted file (if keyring unavailable)

Keys are automatically migrated from plaintext on first run. You can also manually migrate:

cdc config migrate-keys

Global Configuration

Configuration metadata is stored in ~/.claude-dev-cli/config.json (API keys are NOT in this file):

{
  "api_configs": [
    {
      "name": "personal",
      "api_key": "",  // Empty - actual key in secure storage
      "description": "My personal API key",
      "default": true
    },
    {
      "name": "client",
      "api_key": "",  // Empty - actual key in secure storage
      "description": "Client's Enterprise API",
      "default": false
    }
  ],
  "default_model": "claude-3-5-sonnet-20241022",
  "max_tokens": 4096
}

Project-Specific Configuration

Create .claude-dev-cli in your project root:

{
  "name": "My Project",
  "api_config": "client",
  "system_prompt": "You are a Python expert focused on data science.",
  "allowed_commands": ["all"]
}

The tool will automatically use the client's API when you run commands in that project!

API Routing Strategy

Scenario: Client Work with Enterprise API

# 1. Set up client's API
export CLIENT_ANTHROPIC_API_KEY="sk-ant-..."
cdc config add client --description "Client Enterprise API"

# 2. Create project config
cd /path/to/client/project
cat > .claude-dev-cli << 'EOF'
{
  "name": "Client Project",
  "api_config": "client",
  "system_prompt": "You are a senior Python developer."
}
EOF

# 3. All commands in this directory now use client's API
cdc generate tests app.py  # Uses client's API
cdc review code.py         # Uses client's API

# 4. Your personal projects use your API
cd ~/my-personal-project
cdc generate tests app.py  # Uses your personal API

What the Client Can See

When using a client's Enterprise API:

They CAN see:

  • Total API calls and token usage
  • Costs associated with the API key
  • Potentially conversation history (if enabled by admin)

They CANNOT see:

  • Which machine you used
  • Your other API keys or projects
  • Local files unless you sent the content

Command Reference

Core Commands

Command Description
cdc ask <prompt> Ask Claude a question
cdc interactive Start interactive chat
cdc usage Show usage statistics

Configuration

Command Description
cdc config add <name> Add API configuration
cdc config list List all API configs

Code Generation

Command Description
cdc generate tests <file> Generate pytest tests
cdc generate docs <file> Generate documentation

Code Analysis

Command Description
cdc review <file> Review code
cdc debug -f <file> -e <error> Debug code
cdc refactor <file> Refactoring suggestions

Git Helpers

Command Description
cdc git commit Generate commit message

Options

Common Options

  • -a, --api <name>: Use specific API config
  • -m, --model <name>: Use specific Claude model
  • -s, --system <prompt>: Set system prompt
  • -f, --file <path>: Include file in prompt
  • -o, --output <path>: Save output to file

Models

  • claude-3-5-sonnet-20241022 (default)
  • claude-3-opus-20240229
  • claude-3-haiku-20240307

Examples

Test Generation

# Generate tests for a module
cdc generate tests src/calculator.py -o tests/test_calculator.py

# Review the tests
cdc review tests/test_calculator.py

Code Review Workflow

# Review before committing
cdc review mycode.py

# Fix issues, then generate commit message
git add mycode.py
cdc git commit

Debugging

# Run script and analyze errors
python buggy_script.py 2>&1 | cdc debug

# Or debug a specific file
cdc debug -f buggy_script.py -e "NameError: name 'x' is not defined"

Using Multiple APIs

# Personal work
cdc ask "explain decorators" -a personal

# Client work
cdc generate tests client_code.py -a client

# Check usage per API
cdc usage --api personal
cdc usage --api client

Environment Variables

Variable Description
{NAME}_ANTHROPIC_API_KEY API key for config named "name"
ANTHROPIC_API_KEY Default API key

Usage Log Format

Usage logs are stored in ~/.claude-dev-cli/usage.jsonl:

{
  "timestamp": "2024-12-28T03:00:00.000000",
  "api_config": "client",
  "model": "claude-3-5-sonnet-20241022",
  "prompt_preview": "Generate tests for...",
  "input_tokens": 1523,
  "output_tokens": 2847,
  "duration_ms": 3421
}

Development

# Clone the repository
git clone https://github.com/thinmanj/claude-dev-cli
cd claude-dev-cli

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/
ruff check src/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE for details.

Author

Julio (@thinmanj)

Acknowledgments

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_dev_cli-0.5.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_dev_cli-0.5.0-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file claude_dev_cli-0.5.0.tar.gz.

File metadata

  • Download URL: claude_dev_cli-0.5.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for claude_dev_cli-0.5.0.tar.gz
Algorithm Hash digest
SHA256 50c09097c3accac58bb5820a5ee8cc20dd1babea839b12083049d7059831b75b
MD5 43abf8b824fc6c2e9b795816d07bf169
BLAKE2b-256 75fb1fbeb2e2e412a9eb9bc4c7563e67545be8652e631915c8c566d495e2f6b5

See more details on using hashes here.

File details

Details for the file claude_dev_cli-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: claude_dev_cli-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for claude_dev_cli-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 01778adc636aa1049ef2098294b9d625101f6d892b25622ba88918eb1103e64c
MD5 1cbd06ca95255437fc6c7e2174cddbdc
BLAKE2b-256 8d188b9193749dae864715bfe0dc19a45dfe03675e778bfb6eef239a3d29c824

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page