Local AI Meets the Unix Pipeline With ShellGPT Source

1---
2title: "Local AI Meets the Unix Pipeline With ShellGPT"
3date: "2026-06-18"
4published: true
5tags: ["ai", "shell-gpt", "ollama", "gemma", "local-ai", "unix", "bash", "terminal", "linux"]
6author: "Gavin Jackson"
7excerpt: "I started using ShellGPT today with a locally hosted Gemma 4 26B quantized model through Ollama on my RTX PRO 4000 Blackwell workstation. Asking questions in the terminal was fine, but the real value showed up when local AI met the Unix pipeline."
8---
9
10# Local AI Meets the Unix Pipeline With ShellGPT
11
12![Seashells scattered across sand, a visual nod to ShellGPT in the terminal](/assets/shell-gpt-seashells.png)
13
14I started using [ShellGPT](https://github.com/ther1d/shell_gpt) today, pointed at my locally hosted Gemma 4 26B quantized model through Ollama.
15
16This is running on the same NVIDIA RTX PRO 4000 Blackwell workstation I wrote about in [Running Modern Edge LLMs on an RTX PRO 4000 Blackwell](/post/running-edge-llms-rtx-pro-4000-blackwell). That setup already made local inference feel practical. ShellGPT adds a different layer on top: it puts the model directly into the terminal, where a lot of real system work already happens.
17
18The result is interesting. Not because typing a question into a terminal is magically better than typing it into a chat window. That part was fine, but not revolutionary. It felt very similar to asking Ollama directly.
19
20The useful part was composability.
21
22ShellGPT becomes much more compelling when it is chained with commands, fed real output from the machine, and used to turn human language into shell commands or bash scripts.
23
24That is where it started to click.
25
26Note - to keep this article down to a reasonable length, none of my examples actually show output from the commands, but this should get a better idea of what is possible.
27
28## What ShellGPT Does
29
30ShellGPT is a command-line productivity tool for talking to large language models from the shell. The project supports regular prompts, shell command generation, code generation, chat sessions, REPL mode, and shell integration.
31
32The command is `sgpt`, so the basic shape is simple:
33
34```bash
35sgpt "Explain what the Linux load average means in plain English"
36```
37
38That is useful enough. It means I can ask a question without leaving the terminal, switching to a browser, opening another app, or copying context around.
39
40But with a local model, the more important detail is that the question stays on the workstation. The prompt goes to Ollama on `localhost`, not to a cloud API.
41
42That matters for the sort of environments I care about. A lot of shell work involves logs, hostnames, service names, paths, configuration snippets, and operational clues that should not be casually pasted into a public SaaS tool.
43
44## Asking Questions Was Fine
45
46The first thing I tried was the obvious thing:
47
48```bash
49sgpt "What is the difference between a systemd service and a systemd target?"
50```
51
52That worked exactly as expected. It gave a reasonable explanation. I tried a few more:
53
54```bash
55sgpt "What does set -euo pipefail do in a bash script?"
56```
57
58```bash
59sgpt "Explain the difference between a bind mount and a named Docker volume"
60```
61
62This is handy, but it is not very different from:
63
64```bash
65ollama run gemma4-26b "What does set -euo pipefail do in a bash script?"
66```
67
68For standalone questions, ShellGPT is mostly a nicer terminal wrapper around a model. That is not a criticism. It is still convenient. But if that was all it did, I probably would not write a whole post about it.
69
70The real power showed up when I stopped treating it like chat and started treating it like another Unix tool.
71
72## Piping Real Output Into The Model
73
74The shell is already good at collecting evidence. It can list files, stream logs, inspect services, query APIs, and format text. ShellGPT becomes useful when it can sit at the end of that pipeline and reason over the output.
75
76The pattern is simple:
77
78> Use normal shell tools to collect the evidence, then pipe that evidence into `sgpt` and ask the model to interpret it.
79
80That feels much more useful than asking generic troubleshooting questions in isolation.
81
82For example, instead of asking a generic question about disk usage, I can give it the actual disk usage:
83
84```bash
85df -h | sgpt "Which filesystem should I investigate first? Keep the answer short."
86```
87
88Or I can give it a size breakdown:
89
90```bash
91du -xh --max-depth=1 /var 2>/dev/null \
92  | sort -h \
93  | tail -20 \
94  | sgpt "Summarise which directories are taking space and suggest the safest next checks."
95```
96
97That is a better workflow than asking "how do I troubleshoot disk space?" because the model has the current state in front of it.
98
99Failed services are another nice fit:
100
101```bash
102systemctl --failed --no-pager \
103  | sgpt "Explain these failed services and rank them by likely importance."
104```
105
106Logs are an obvious example:
107
108```bash
109journalctl -u ollama -n 120 --no-pager \
110  | sgpt "Summarise the last failure and suggest the next three commands to run."
111```
112
113For Docker:
114
115```bash
116docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' \
117  | sgpt "Explain which services are exposed and whether anything looks surprising."
118```
119
120If a specific container is misbehaving, I can hand ShellGPT the recent logs directly:
121
122```bash
123docker logs --tail 120 my-container 2>&1 \
124  | sgpt "Find the likely root cause of the error in these logs."
125```
126
127For Git:
128
129```bash
130git diff --stat \
131  | sgpt "Summarise the scope of this change in one paragraph."
132```
133
134And for quick commit-message drafting:
135
136```bash
137git diff --cached \
138  | sgpt "Write a concise git commit message for these staged changes."
139```
140
141For local AI work, GPU state is useful context:
142
143```bash
144nvidia-smi \
145  | sgpt "Summarise GPU utilisation and whether this looks healthy for local LLM inference."
146```
147
148And because Ollama exposes a local API, I can query it and ask ShellGPT to make the output more readable:
149
150```bash
151curl -s http://localhost:11434/api/tags \
152  | sgpt "List the available Ollama models and explain which one looks like the default candidate."
153```
154
155This is the part I liked most. The terminal already has the context. ShellGPT lets the local model read that context without me manually copying it somewhere else.
156
157## Generating Shell Commands From Human Language
158
159ShellGPT has a shell command mode:
160
161```bash
162sgpt --shell "find all markdown files changed in the last 7 days and print their titles"
163```
164
165or with the short flag:
166
167```bash
168sgpt -s "show me the ten largest files under /var/log modified in the last week"
169```
170
171It returns a command and then gives an interactive choice to execute, describe, or abort.
172
173That interaction is important. I do not want a local model blindly running system commands on my behalf. I want it to propose a command, let me inspect it, ask it to describe the command if needed, then decide whether to run it.
174
175One detail I appreciated is that ShellGPT is smart enough to account for the shell you are using. Bash, Zsh, and Fish all have slightly different syntax and conventions, and the generated commands or scripts can reflect that instead of treating every terminal as generic POSIX `sh`. That matters once you get into arrays, globbing, completions, aliases, functions, and shell-specific quality-of-life features.
176
177Some examples that fit my normal workflow:
178
179```bash
180sgpt -s "find markdown posts that contain the word ollama and sort them newest first"
181```
182
183```bash
184sgpt -s "show listening TCP ports with process names on Ubuntu"
185```
186
187```bash
188sgpt -s "compress all png files in this directory into a tar.gz archive named images-backup.tar.gz"
189```
190
191```bash
192sgpt -s "use curl to check whether http://localhost:11434/api/tags is responding"
193```
194
195```bash
196sgpt -s "create a one-line command to list the current GPU name, driver version, and used VRAM"
197```
198
199This is where ShellGPT feels different from a normal chatbot. I am not asking for a tutorial. I am asking for the exact command I need right now. I'm going to be using this a lot for tcpdump options - I always forget these!
200
201That is a small shift, but it changes the feel of the workflow.
202
203## Building Bash Scripts From Plain English
204
205The best use case today was using ShellGPT to draft more complex bash scripts.
206
207For example, I can ask:
208
209```bash
210sgpt --code "Write a bash script called ollama-health.sh that:
211- checks whether the Ollama API is listening on localhost:11434
212- prints the installed Ollama models
213- sends a short test prompt to gemma4-26b
214- prints GPU memory usage with nvidia-smi
215- exits non-zero if any check fails"
216```
217
218That is the sort of script I would normally write myself, but it takes a few minutes of looking up curl flags, remembering the Ollama API shape, and deciding how neat I want the error handling to be.
219
220ShellGPT can produce a first draft immediately:
221
222```bash
223#!/usr/bin/env bash
224set -euo pipefail
225
226MODEL="${1:-gemma4-26b}"
227OLLAMA_URL="${OLLAMA_URL:-http://127.0.0.1:11434}"
228
229echo "Checking Ollama API..."
230curl -fsS "$OLLAMA_URL/api/tags" >/dev/null
231
232echo "Installed models:"
233ollama list
234
235echo "Testing model: $MODEL"
236ollama run "$MODEL" "Reply with one short sentence confirming you are ready."
237
238echo "GPU memory:"
239nvidia-smi --query-gpu=name,memory.used,memory.total --format=csv
240```
241
242Would I run that blindly on a production host? No.
243
244Would I use it as a starting point, review it, tighten it, and save myself some time? Absolutely.
245
246Another useful prompt:
247
248```bash
249sgpt --code "Write a bash script that scans a directory of markdown blog posts, extracts YAML title and date fields, and prints a sorted table of date, title, and filename."
250```
251
252Or:
253
254```bash
255sgpt --code "Write a bash script that checks all Docker containers, prints unhealthy ones, shows their last 50 log lines, and exits 1 if any container is unhealthy."
256```
257
258Or:
259
260```bash
261sgpt --code "Write a bash script that backs up /etc/nginx and /etc/systemd/system to a timestamped tar.gz file, writes a SHA256 checksum, and keeps only the last 10 backups."
262```
263
264This is the sweet spot for me. I know enough bash to review the result. I know enough Linux to catch dangerous assumptions. What I want is acceleration: a draft that gets the boring structure in place so I can focus on the intent.
265
266## Installation With Ollama
267
268The upstream project is here:
269
270[ther1d/shell_gpt on GitHub](https://github.com/ther1d/shell_gpt)
271
272The basic install from the README is:
273
274```bash
275python3 -m pip install --upgrade shell-gpt
276```
277
278By default, ShellGPT uses OpenAI's API. To use Ollama, install ShellGPT with LiteLLM support:
279
280```bash
281python3 -m pip install --upgrade "shell-gpt[litellm]"
282```
283
284If Ollama is not already installed, the Linux installer is:
285
286```bash
287curl -fsSL https://ollama.com/install.sh | sh
288```
289
290If you are using the official ShellGPT Ollama guide as a quick test, it uses:
291
292```bash
293ollama pull gemma4:e4b
294```
295
296In my case, I already had a larger Gemma 4 26B quantized model imported into Ollama from earlier testing. The important thing is the model name that appears in `ollama list` (**IMPORTANT**: don't forget to prefix this with ollama/ - see below). Use that exact name in the ShellGPT configuration.
297
298Open the config file:
299
300```bash
301nano ~/.config/shell_gpt/.sgptrc
302```
303
304Set the Ollama-related values:
305
306```ini
307DEFAULT_MODEL=ollama/gemma4-26b:latest
308OPENAI_USE_FUNCTIONS=false
309USE_LITELLM=true
310API_BASE_URL=http://localhost:11434
311OPENAI_API_KEY=0
312```
313
314Replace `gemma4-26b:latest` with the exact model name from `ollama list`. If your model is called `gemma4:e4b`, use:
315
316```ini
317DEFAULT_MODEL=ollama/gemma4:e4b
318```
319
320Then test it:
321
322```bash
323sgpt "Hello Ollama. Reply in one short sentence."
324```
325
326If that works, try shell mode:
327
328```bash
329sgpt -s "print the current directory, git branch, and latest commit"
330```
331
332## A Few Practical Notes
333
334ShellGPT's own documentation notes that local models may not behave exactly like the default hosted OpenAI path. That matches my experience. Local models are good enough to be useful, but they still need supervision.
335
336A few habits make the workflow safer:
337
338- Use `--shell` when you want a command, because the interactive execute, describe, and abort flow is useful.
339- Ask for a description before running anything destructive.
340- Avoid piping `--no-interaction` directly into `bash`.
341- Treat generated scripts as drafts.
342- Keep Ollama bound to localhost unless you have a deliberate reason to expose it.
343- Use the exact model name from `ollama list`.
344
345The last point sounds mundane, but it matters. With Ollama, the name is the contract. If the model is registered as `gemma4-26b:latest`, that is what ShellGPT and LiteLLM need to see.
346
347## The Takeaway
348
349My first impression is that ShellGPT is not most interesting as "chat in a terminal."
350
351That is fine, but familiar.
352
353It is more interesting as a shell-native bridge to a local model. I can pipe logs into it, ask it to interpret real command output, generate one-off commands, and draft bash scripts in the place where those scripts are going to run.
354
355That makes local AI feel less like a separate destination and more like part of the operating environment.
356
357For a local Gemma 4 model running through Ollama on the RTX PRO 4000 Blackwell, that is exactly the kind of workflow I wanted to test. The model does not need to be perfect. It needs to be nearby, private, fast enough, and useful in the flow of work.
358
359Today, ShellGPT cleared that bar and will be part of my toolkit.
360
361## Links
362
363- [ther1d/shell_gpt on GitHub](https://github.com/ther1d/shell_gpt)
364- [ShellGPT Ollama wiki page](https://github.com/TheR1D/shell_gpt/wiki/Ollama)
365- [Ollama](https://ollama.com/)
366- [My earlier post: Running Modern Edge LLMs on an RTX PRO 4000 Blackwell](/post/running-edge-llms-rtx-pro-4000-blackwell)
367