Natural language at the shell prompt — ask questions, get commands
Shell GPT (command: sgpt) is a lightweight, open-source command-line tool that puts an AI assistant directly at your shell prompt. Unlike aider, which is focused on editing files, sgpt is conversational — you ask it questions, describe what you want to do, and it responds with answers, explanations, or ready-to-run shell commands.
For a Linux SysAdmin, sgpt fills the gap between "I know roughly what I need" and "I know the exact syntax." It handles one-liners, command flags, quick explanations, and shell pipeline construction — all without leaving the terminal or opening a browser.
sgpt supports OpenAI models out of the box, and can be configured to use other backends including local models via Ollama.
sgpt itself is free and open source (MIT license). API costs depend on your backend:
sgpt is a Python package. The recommended install method is pipx to keep it isolated:
# Recommended: pipx (isolated environment) pipx install shell-gpt # Alternative: pip pip install shell-gpt # Verify sgpt --versionOn first run, sgpt will prompt you for your OpenAI API key and store it in ~/.config/shell_gpt/.sgptrc.
Alternatively, set it as an environment variable:
export OPENAI_API_KEY=your-key-hereIf you want to run sgpt without sending data to OpenAI:
# Install Ollama first (see ollama.com) ollama pull llama3 # Configure sgpt to use Ollama sgpt --model ollama/llama3 "your query here"Use --shell (or -s) to get a command ready to run:
sgpt will ask if you want to execute, describe, or abort before running anything.
Add --execute to run the command immediately after confirmation:
One of sgpt's most powerful features — pipe command output directly into it:
# Explain what's in a log snippet tail -50 /var/log/messages | sgpt "summarize any errors in this log output" # Analyze df output df -h | sgpt "which filesystems are over 80% full?" # Check a config file cat /etc/httpd/conf/httpd.conf | sgpt "are there any obvious security issues in this Apache config?"By default each sgpt call is stateless. For multi-turn conversations where context matters, use --chat with a session name:
sgpt remembers the full conversation within the named session, so follow-up questions have context. Sessions are stored locally in ~/.config/shell_gpt/chat_cache/.
debug-apache, script-backup, plan-migration. They persist between terminal sessions so you can pick up where you left off.
sgpt can integrate with your shell so you can invoke it directly from the command line with a keyboard shortcut. After installing sgpt, add the shell integration to your .bashrc:
This adds a keybinding — typically Ctrl+L — that takes whatever you've typed at the prompt, sends it to sgpt as a shell command request, and replaces your typed text with the result. The workflow becomes:
Ctrl+Lsgpt supports custom roles — system prompts that give the AI context about who you are and what kind of answers you want. Create a role file in ~/.config/shell_gpt/roles/:
Use the role in any query:
sgpt --role sysadmin "what's the safest way to clear the systemd journal when disk is full?"With a well-crafted role, sgpt's answers become more targeted and appropriately cautious for production environments.
sgpt occupies a different niche than Copilot or aider. It's not about editing files — it's about the moment-to-moment questions that come up when you're in the middle of something. "What's the rsync flag that preserves ACLs?" "Is there a one-liner to count unique IPs in an access log?" That's sgpt's territory.
The pipe integration is where it gets genuinely interesting for SysAdmins. Being able to pipe tail -f output or a config file into sgpt and ask "what's wrong here?" is a different kind of workflow than opening a browser and pasting text into Claude.ai. It keeps you in the terminal and in the flow of the work.
The shell integration (Ctrl+L) takes some getting used to — and some discipline, because it makes it fast to run commands you haven't fully reviewed. Once that habit is established, it's a genuinely faster way to work.