AI-powered command line troubleshooting tool
Project description
CmdRx - AI-Powered Command Line Troubleshooting Tool
CmdRx is a command line tool designed to assist IT personnel in analyzing CLI command outputs and providing troubleshooting steps and suggested fixes using artificial intelligence. It supports multiple LLM providers including OpenAI, Anthropic Claude, Grok, and custom on-premises solutions.
Features
- Multiple Input Modes: Analyze command output directly or via piped input
- AI-Powered Analysis: Uses advanced language models to provide intelligent troubleshooting
- Multiple LLM Providers: Support for OpenAI, Anthropic, Grok, and custom endpoints
- Secure Configuration: Safe storage of API keys using system keyring
- Detailed Logging: Timestamped analysis logs with comprehensive information
- Automated Fix Scripts: Generates executable shell scripts with suggested fixes
- User-Friendly TUI: Text-based configuration interface for easy setup
- Cross-Platform: Works on Linux and macOS
Installation
From PyPI (Recommended)
pip install cmdrx
From Source
git clone https://github.com/ryantischer2/cmdrx.git
cd cmdrx
pip install -e .
Package Managers
Ubuntu/Debian:
sudo apt update
sudo apt install cmdrx
Fedora/RHEL:
sudo dnf install cmdrx
macOS (Homebrew):
brew install cmdrx
Quick Start
1. Configure CmdRx
Run the configuration wizard to set up your LLM provider:
cmdrx --config
This will guide you through:
- Selecting an LLM provider (OpenAI, Anthropic, Grok, or custom)
- Entering your API credentials securely
- Configuring output directories and preferences
2. Analyze Command Output
Standalone Mode (CmdRx executes the command):
cmdrx systemctl status httpd
cmdrx journalctl -xe
cmdrx docker ps -a
Piped Mode (analyze output from another command):
systemctl status httpd | cmdrx
journalctl -xe | cmdrx
docker logs my-container | cmdrx
3. Review Results
CmdRx will display:
- Analysis of the command output
- Identified issues
- Troubleshooting steps
- Suggested fixes with risk levels
- Generated log files and fix scripts
Usage Examples
Troubleshooting a Failed Service
$ cmdrx systemctl status apache2
Output:
╭─ Analysis (ERROR) ────────────────────────────────────────╮
│ Apache2 service is failed due to configuration syntax │
│ error in /etc/apache2/sites-enabled/000-default.conf │
╰───────────────────────────────────────────────────────────╯
╭─ Issues Identified ───────────────────────────────────────╮
│ • Configuration syntax error in virtual host │
│ • Service failed to start │
│ • Port conflict possible │
╰───────────────────────────────────────────────────────────╯
╭─ Troubleshooting Steps ───────────────────────────────────╮
│ 1. Check configuration syntax │
│ Command: apache2ctl configtest │
│ This will show specific syntax errors │
│ │
│ 2. Review error logs │
│ Command: journalctl -u apache2 -n 20 │
│ Check for detailed error messages │
╰───────────────────────────────────────────────────────────╯
Generated Files:
📄 Log file: ~/.cmdrx_logs/cmdrx_analysis_20241201_143022.log
🔧 Fix script: ~/.cmdrx_logs/cmdrx_fix_20241201_143022.sh
Run with: bash ~/.cmdrx_logs/cmdrx_fix_20241201_143022.sh
Analyzing Docker Issues
$ docker ps | cmdrx
Custom Analysis with Piped Input
$ cat /var/log/syslog | tail -50 | cmdrx
Configuration
LLM Providers
CmdRx supports multiple LLM providers:
OpenAI
- Models: gpt-4, gpt-3.5-turbo, etc.
- Requires: OpenAI API key
- Configuration: Select "openai" in config menu
Anthropic Claude
- Models: claude-3-sonnet, claude-3-haiku, etc.
- Requires: Anthropic API key
- Configuration: Select "anthropic" in config menu
Grok (xAI)
- Models: grok-beta, etc.
- Requires: xAI API key
- Configuration: Select "grok" in config menu
Custom/On-Premises
- Any OpenAI-compatible API endpoint
- Examples: Ollama, LocalAI, custom deployments
- Configuration: Select "custom" and provide endpoint details
Configuration File
Configuration is stored in ~/.config/cmdrx/config.json:
{
"llm_provider": "openai",
"llm_model": "gpt-4",
"log_directory": "~/cmdrx_logs",
"verbose": false,
"auto_fix_scripts": true,
"command_timeout": 30
}
Secure Credential Storage
CmdRx offers multiple secure methods for storing API keys and tokens:
Method 1: System Keyring (Preferred)
- Linux: Secret Service (GNOME Keyring, KWallet)
- macOS: Keychain
- Windows: Windows Credential Store
- Setup: Use
cmdrx --configto store credentials securely
Method 2: Environment Variables
Perfect for development and CI/CD environments:
# OpenAI
export CMDRX_OPENAI_API_KEY="sk-your-openai-key"
# Anthropic Claude
export CMDRX_ANTHROPIC_API_KEY="sk-ant-your-claude-key"
# Grok (xAI)
export CMDRX_GROK_API_KEY="xai-your-grok-key"
# Custom providers
export CMDRX_CUSTOM_API_KEY="your-custom-key"
export CMDRX_CUSTOM_BEARER_TOKEN="your-bearer-token"
Method 3: Credentials File
For manual credential management:
# Create secure credentials file
mkdir -p ~/.config/cmdrx
cat > ~/.config/cmdrx/credentials.json << 'EOF'
{
"openai_api_key": "sk-your-openai-key",
"anthropic_api_key": "sk-ant-your-claude-key",
"grok_api_key": "xai-your-grok-key"
}
EOF
# Secure the file (owner-only access)
chmod 600 ~/.config/cmdrx/credentials.json
Priority Order
CmdRx will search for credentials in this order:
- System keyring
- Environment variables (
CMDRX_*) - Credentials file (
~/.config/cmdrx/credentials.json)
Setting Up API Keys
Option A: Interactive Configuration with Storage Choice (Recommended)
cmdrx --config
When configuring an API key, CmdRx will present you with storage method options:
| Option | Method | Security | Best For |
|---|---|---|---|
| 1 | System Keyring | High | Desktop users, single-user systems |
| 2 | Environment Variable | Medium | Development, CI/CD, automation |
| 3 | Credentials File | Medium | Manual management, shared systems |
The interface will:
- Show available storage methods for your system
- Display security levels for each method
- Provide setup instructions for your chosen method
- Automatically secure file permissions (if using file storage)
- Fall back to alternative methods if the preferred method fails
Option B: Environment Variables (Quick Setup)
# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
echo 'export CMDRX_OPENAI_API_KEY="sk-your-actual-key"' >> ~/.zshrc
source ~/.zshrc
Option C: One-time Usage
CMDRX_OPENAI_API_KEY="sk-your-key" cmdrx your-command
Command Line Options
cmdrx [OPTIONS] [COMMAND...]
Options:
-c, --config Open configuration interface
-v, --verbose Enable verbose output
--version Show version and exit
--log-dir PATH Override default log directory
--dry-run Analyze without creating fix scripts
--help Show help message
Generated Files
CmdRx generates several types of output files:
Log Files
- Location:
~/cmdrx_logs/(configurable) - Format:
cmdrx_analysis_YYYYMMDD_HHMMSS.log - Content: Complete analysis with system info, command output, and AI response
Fix Scripts
- Location:
~/cmdrx_logs/(configurable) - Format:
cmdrx_fix_YYYYMMDD_HHMMSS.sh - Content: Executable bash script with suggested fixes
- Safety: Includes confirmations and risk warnings
Security Considerations
- Credential Storage: Multiple secure options (system keyring, environment variables, encrypted file)
- File Permissions: Credentials files automatically secured with
chmod 600(owner-only access) - No Plain Text: API keys never stored in configuration files or logs
- Input Validation: Commands are validated to prevent injection attacks
- Fix Scripts: Generated with safety confirmations and warnings
- HTTPS: All remote API calls use HTTPS encryption
- No Auto-Execution: Fixes require explicit user approval
- Fallback Security: If keyring fails, secure alternatives are available
Troubleshooting
Common Issues
Configuration Error: No LLM provider configured
cmdrx --config # Run configuration wizard
API Key Issues
# Method 1: Interactive configuration
cmdrx --config
# Method 2: Environment variable (quick fix)
export CMDRX_OPENAI_API_KEY="sk-your-key"
# Method 3: Check which credential source is being used
cmdrx --verbose echo "test" # Shows credential source in output
# Method 4: Verify credential file
ls -la ~/.config/cmdrx/credentials.json
Keyring Problems If system keyring is unavailable, CmdRx automatically falls back to:
# Use environment variables instead
export CMDRX_OPENAI_API_KEY="sk-your-key"
# Or create credentials file
mkdir -p ~/.config/cmdrx
echo '{"openai_api_key": "sk-your-key"}' > ~/.config/cmdrx/credentials.json
chmod 600 ~/.config/cmdrx/credentials.json
Connection Problems
# Test your configuration
cmdrx --config # Use "Test Configuration" option
Verbose Mode
For detailed debugging information:
cmdrx --verbose your-command
Log Files
Check the generated log files for complete analysis details:
ls -la ~/cmdrx_logs/
cat ~/cmdrx_logs/cmdrx_analysis_*.log
Development
Setting Up Development Environment
git clone https://github.com/ryantischer2/cmdrx.git
cd cmdrx
pip install -e ".[dev]"
Running Tests
pytest
pytest --cov=src/cmdrx
Code Quality
black src/ tests/
isort src/ tests/
flake8 src/ tests/
mypy src/
Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Documentation: cmdrx.readthedocs.io
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Changelog
See CHANGELOG.md for version history and changes.
Disclaimer: CmdRx provides AI-generated suggestions. Always review and understand commands before executing them. The authors are not responsible for any system damage or data loss.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cmdrx-0.2.1.tar.gz.
File metadata
- Download URL: cmdrx-0.2.1.tar.gz
- Upload date:
- Size: 38.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42fd094cccec3e6301aa0ab84a4375036c042ce7efa8db1f0492fd8eff8ca245
|
|
| MD5 |
2940fa38ab0c98e15266e038194f330a
|
|
| BLAKE2b-256 |
f83c9d25dc3d627e55f8c0d1b93b0f1f85d58c58242025d79f21b0f59014e961
|
File details
Details for the file cmdrx-0.2.1-py3-none-any.whl.
File metadata
- Download URL: cmdrx-0.2.1-py3-none-any.whl
- Upload date:
- Size: 35.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e8681a9b9e353a86221c80d833740133c0e74194f1b642ccf657010d22819b4
|
|
| MD5 |
346b4bf1fd63ad40891c079c93880e9c
|
|
| BLAKE2b-256 |
4e8549017f7a25c7f4430e4a9020afd68ad9429a7df7614004b18eec01744efa
|