This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Basic usage
python cmswitcher.py --cpuminer <path_to_cpuminer_binary>
# With options
python cmswitcher.py --cpuminer cpuminer --log-level DEBUG --log-file cmswitcher.log
# Benchmark only
python cmswitcher.py --cpuminer cpuminer --benchmark-only
# Force re-benchmark
python cmswitcher.py --cpuminer cpuminer --force-benchmarkpip install -r requirements.txt
# or for development
pip install -e .- Python 3.7+ with packages:
requests,tabulate - cpuminer binary (cpuminer-opt or cpuminer-multi)
cmswitcher/
├── __init__.py # Package initialization
├── config.py # Configuration management
├── models.py # Data models (Miner, Pool, BenchmarkResult)
├── api_client.py # cpuminer API communication
├── pool_api.py # Pool API interaction
├── benchmark.py # Benchmarking logic
├── profit.py # Profitability calculations
├── mining_session.py # Mining process management
├── logger.py # Logging configuration
└── main.py # Main application and CLI
- Config (
config.py): Manages all configuration loading with type-safe property access - Miner (
models.py): Represents a mining software configuration with benchmark results - Pool (
models.py): Represents a mining pool with API integration - MinerAPIClient (
api_client.py): Handles communication with cpuminer's API (port 40101) - Benchmarker (
benchmark.py): Manages algorithm benchmarking process - ProfitabilityCalculator (
profit.py): Calculates profits and fetches Bitcoin prices - MiningSession (
mining_session.py): Manages mining process lifecycle - CMSwitcher (
main.py): Main application class that orchestrates everything
-
Initialization:
- Load configuration files from
data/directory - Create Miner and Pool instances
- Fetch pool API data to discover supported algorithms
- Load configuration files from
-
Benchmarking:
- Find common algorithms between miners and pools
- Skip blacklisted algorithms
- Run benchmarks and save results to
benchmark-<miner>.json
-
Mining Loop:
- Calculate profitability for all algorithm combinations
- Filter out blacklisted algorithms
- Start mining with most profitable algorithm
- Monitor performance via cpuminer API
- Switch when better algorithm becomes available
- API_PORT: 40101 (cpuminer API)
- Default session timeout: 600 seconds
- Default minimum profitability: $0.05/day
- Retry logic for API connections
- Graceful handling of miner crashes
- Fallback Bitcoin price if APIs fail
- Comprehensive logging throughout
To test changes:
- Ensure
data/directory has all required JSON files - Run with valid cpuminer binary path
- Check benchmarking completes successfully
- Verify profit switching behavior
- Monitor logs for any errors
- Add pool configuration to
data/pools.json - Ensure API endpoint returns compatible format
- Test algorithm name matching
- Add miner configuration to
data/miners.json - Define launch pattern and supported algorithms
- Test API communication on port 40101
- Use
--log-level DEBUGfor detailed logging - Check
--log-fileoutput for full trace - Monitor cpuminer output if crashes occur