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.
Safe staging for this asset
This asset is staged first. The copied prompt tells the agent to inspect the staged files and ask before activating scripts, MCP config, or global config.
npx -y tokrepo@latest install b48a2103-8192-468f-8a8e-1d69d74c64b8 --target codexStages files first; activation requires review of the staged README and plan.
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
Harlequin — The SQL IDE for Your Terminal
A terminal-based SQL IDE with autocomplete, syntax highlighting, and a results viewer for DuckDB, SQLite, PostgreSQL, and more.
Gladys Assistant — Privacy-First Open-Source Home Automation
A self-hosted home assistant that runs locally on a Raspberry Pi, providing device control, scenes, automation rules, and a clean dashboard without cloud dependency.
xterm.js — Terminal Emulator Component for the Web
A TypeScript library that provides a fully featured terminal emulator in the browser, powering the integrated terminals of VS Code, Hyper, and dozens of web-based IDEs and SSH clients.
Sampler — Real-Time Terminal Dashboards from Shell Commands
Sampler is a tool for shell commands execution, visualization, and alerting, turning any CLI output into live-updating terminal charts and gauges.