ShellGPT — AI Assistant in Your Terminal
ShellGPT generates shell commands, code, and docs from natural language in your terminal. 11.9K+ stars. Chat, REPL, local models. MIT.
What it is
ShellGPT is a command-line tool that generates shell commands, code, and documentation from natural language prompts. You type what you want in plain English, and ShellGPT returns the exact command or script to run. It supports chat mode for multi-turn conversations, a REPL for interactive sessions, and local model backends.
It targets developers, sysadmins, and DevOps engineers who spend significant time looking up CLI syntax, writing one-off scripts, or translating intent into shell commands.
How it saves time or tokens
Instead of searching Stack Overflow or man pages for the right flags, ShellGPT gives you the command immediately. The shell integration means you can execute generated commands without copy-pasting. For repetitive tasks like log parsing, file manipulation, or system diagnostics, ShellGPT turns a 5-minute search into a 5-second prompt. The token estimate for a typical session is around 297 tokens per interaction.
How to use
- Install ShellGPT:
pip install shell-gpt
- Set your API key and run a query:
export OPENAI_API_KEY=sk-...
sgpt 'find all Python files modified in the last 7 days'
- Use shell mode for executable commands:
sgpt --shell 'compress all .log files in /var/log older than 30 days'
# ShellGPT returns: find /var/log -name '*.log' -mtime +30 -exec gzip {} \;
# [E]xecute, [D]escribe, [A]bort?
Example
Using the REPL for multi-turn code generation:
sgpt --repl code
>>> Create a Python function that reads a CSV and returns rows where column 'status' is 'active'
import csv
def get_active_rows(filepath):
with open(filepath) as f:
reader = csv.DictReader(f)
return [row for row in reader if row['status'] == 'active']
>>> Now add error handling for missing files
import csv
from pathlib import Path
def get_active_rows(filepath):
path = Path(filepath)
if not path.exists():
raise FileNotFoundError(f'{filepath} not found')
with open(path) as f:
reader = csv.DictReader(f)
return [row for row in reader if row['status'] == 'active']
Related on TokRepo
- Automation tools — CLI and workflow automation resources
- AI coding tools — AI-powered development assistants
Common pitfalls
- Running generated commands without review can be dangerous. Always use the describe option before executing destructive operations like
rm -rforDROP TABLE. - ShellGPT defaults to OpenAI models. To use local models, configure the backend URL to point to Ollama or other compatible endpoints.
- Chat history grows quickly in REPL mode. Long sessions accumulate context that increases token usage and cost.
Frequently Asked Questions
Yes. You can point ShellGPT to any OpenAI-compatible API endpoint, including Ollama, LM Studio, or vLLM. Set the OPENAI_API_BASE environment variable to your local server URL.
ShellGPT always shows the generated command before execution and asks for confirmation. However, you should review every command carefully, especially on production systems. Never auto-execute without understanding what the command does.
ShellGPT works with bash, zsh, fish, and PowerShell. It detects your current shell and generates commands in the appropriate syntax.
ShellGPT itself is free and open source (MIT license). Costs come from the LLM API you use. A typical query uses a few hundred tokens. Using local models eliminates API costs entirely.
Yes. Use the --code flag or REPL code mode to generate Python, JavaScript, SQL, and other languages. ShellGPT returns clean code without markdown formatting, ready to pipe into files.
Citations (3)
- ShellGPT GitHub— ShellGPT generates shell commands, code, and docs from natural language
- ShellGPT README— Supports chat mode, REPL, and local model backends
- OpenAI API Reference— OpenAI-compatible API for local model integration
Related on TokRepo
Source & Thanks
TheR1D/shell_gpt — 11,900+ GitHub stars
Discussion
Related Assets
Moodle — Open-Source Learning Management System
The most widely used open-source learning platform, providing course management, assessments, and collaboration tools for educators and organizations worldwide.
Sylius — Headless E-Commerce Framework on Symfony
An open-source headless e-commerce platform built on Symfony and API Platform, designed for developers who need a customizable and API-first commerce solution.
Akaunting — Free Self-Hosted Accounting Software
A free, open-source online accounting application built on Laravel for small businesses and freelancers to manage invoices, expenses, and financial reports.