CLI Reference¶
CodeCarbon provides a command-line interface for tracking emissions without modifying code.
Commands¶
codecarbon config¶
Create or modify a .codecarbon.config configuration file interactively.
Usage:
codecarbon config
Prompts you to enter your configuration settings such as API credentials, project name, and tracking preferences. You can re-run this command to modify existing settings.
codecarbon login¶
Authenticate with the CodeCarbon API and save credentials to your config file.
Usage:
codecarbon login
Opens a browser or provides a login link to authenticate with the CodeCarbon API. Saves your API token and creates a default experiment in .codecarbon.config.
codecarbon monitor¶
Monitor emissions from your entire machine continuously.
Usage:
codecarbon monitor [OPTIONS]
Displays real-time emissions data for all processes on your machine. Press Ctrl+C to stop.
Options:
| Option | Type | Default | Description |
|---|---|---|---|
--no-api |
flag | false | Do not send data to the API (local-only measurement) |
--offline |
flag | false | Run without internet access |
--country-iso-code |
string | - | ISO 3166-1 alpha-3 country code (required in offline mode) |
--log-level |
choice | INFO | Log level: DEBUG, INFO, WARNING, ERROR |
Examples:
# Monitor with API (default)
codecarbon monitor
# Monitor locally without sending to API
codecarbon monitor --no-api
# Monitor offline
codecarbon monitor --offline --country-iso-code FRA
# Monitor with debug logging
codecarbon monitor --log-level DEBUG
codecarbon monitor -- <command>¶
Track emissions for a specific command or process.
Usage:
codecarbon monitor -- <your_command>
Runs your command and tracks the emissions produced by that process only. The double hyphen -- separates CodeCarbon options from the command to run.
Examples:
# Run a Python script with tracking
codecarbon monitor -- python train_model.py
# Run a shell script
codecarbon monitor -- bash benchmark.sh
# Run a command with arguments
codecarbon monitor -- node app.js --port 8080
Options:
Same options as codecarbon monitor apply (see above).
codecarbon detect¶
Detect and print hardware information.
Usage:
codecarbon detect
Displays detected RAM, CPU, GPU, and other hardware information that CodeCarbon uses to estimate energy consumption. Useful for verifying that CodeCarbon can see all your hardware.