ShellGPT

CLI that sends prompts to LLMs (OpenAI by default, Ollama supported) to generate shell commands, code, and answers, with stdin piping and chat sessions.

install· pip

ShellGPT (sgpt) is a command-line client for large language models. It takes a prompt from command-line arguments, stdin, or redirection operators (<, heredocs, <<<) and returns generated shell commands, code snippets, or plain answers. It uses OpenAI's API by default, with the key stored in ~/.config/shell_gpt/.sgptrc. Local models can be run through a backend such as Ollama, though the README notes the tool is not optimized for local models. It supports Linux, macOS, and Windows, and works with shells including PowerShell, CMD, Bash, and Zsh.

The --shell (-s) option generates a command suited to your OS and $SHELL, then prompts to [E]xecute, [D]escribe, or [A]bort. For example, "update my system" yields a softwareupdate command on macOS and an apt command on Ubuntu. --no-interaction prints the command to stdout so it can be piped, for instance to pbcopy. The --code (-c) option returns code only, which can be redirected to a file. Piped input works with both modes, such as git diff | sgpt "Generate git commit message, for my changes" or docker logs -n 20 my_app | sgpt "check logs, find errors, provide possible solutions".

Shell integration, installed with sgpt --install-integration, adds lines to .bashrc or .zshrc. Pressing Ctrl+l by default replaces the current input line with a suggested command, which you can edit before running. For conversation state, --chat <name> keeps a named session that can be combined with --code or --shell to refine output over several prompts. --repl <name> opens an interactive loop on the same session object, with multiline input using triple quotes. --list-chats and --show-chat list and inspect sessions. The tool suits developers and sysadmins who want to look up command syntax, draft snippets, or analyze logs and diffs without leaving the terminal.

Installation

# via pip
pip install shell-gpt

ShellGPT REPL mode

Alternatives & related tools

add a badge to your README

Maintain ShellGPT? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/shell-gpt.svg)](https://www.trmn.sh/tools/shell-gpt?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/shell-gpt?utm_source=badge"><img src="https://www.trmn.sh/badge/shell-gpt.svg" alt="Featured on trmn" height="20"></a>