ScriptsApr 1, 2026·1 min read

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.

TL;DR
ShellGPT turns natural language into shell commands, code snippets, and docs directly in your terminal.
§01

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.

§02

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.

§03

How to use

  1. Install ShellGPT:
pip install shell-gpt
  1. Set your API key and run a query:
export OPENAI_API_KEY=sk-...
sgpt 'find all Python files modified in the last 7 days'
  1. 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?
§04

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']
§05

Related on TokRepo

§06

Common pitfalls

  • Running generated commands without review can be dangerous. Always use the describe option before executing destructive operations like rm -rf or DROP 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

Does ShellGPT work with local LLMs?+

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.

Is ShellGPT safe to use with production servers?+

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.

What shells does ShellGPT support?+

ShellGPT works with bash, zsh, fish, and PowerShell. It detects your current shell and generates commands in the appropriate syntax.

How much does ShellGPT cost to run?+

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.

Can ShellGPT generate code besides shell commands?+

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)
🙏

Source & Thanks

TheR1D/shell_gpt — 11,900+ GitHub stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets