You’re deep in focus, trying to solve a problem. You need to parse some logs, and that means diving into the command line. You know what you want to do, but you can’t quite remember the exact flags for jq
or the right way to chain sort
and uniq
. So you do what we all do: you break your focus, open a new browser tab, and start searching.
These micro-interruptions are more costly than we realize. They shatter concentration, waste time, and add a layer of friction to what should be a straightforward task.
What if you could stay in your terminal, ask for what you need in plain English, and get the correct command instantly? That’s the idea behind $hAI
, a shell-native AI assistant for macOS that integrates directly into your workflow.
Let's walk through a real-world scenario: analyzing web server logs to figure out how much traffic is coming from bots.
The Mission: How Many Bots Visit My Website?
For this demo, we'll use a real access log file from wikimedia.org
in JSONL format. (You can download the exact file used in this tutorial here to follow along.) Our first goal is simple: find out how many log entries were generated by bots.
First, let's see what we're working with. A quick ls
shows us the file.
ls *.jsonl
wikimedia_20250804T193623Z.jsonl
Next, we'll peek at the first line to understand the structure of the data using head
.
head -1 *.jsonl
The output is a single, dense JSON line, but we can see a key field that looks promising: "bot":true
.
{"$schema":"/mediawiki/recentchange/1.0.0","meta":{...},"id":2958778979,"type":"categorize",...,"user":"DPLA bot","bot":true,...}
Great. Now we can start counting. A simple pipeline using cat
and wc -l
will give us the total number of lines in the file.
cat *.jsonl | wc -l
2055
So, we have 2,055 total entries.
The "Gotcha": When jq
Does Too Much
To count only the bot entries, we'll use jq
to filter for lines where .bot == true
and then pipe that to wc -l
. This should work.
jq 'select(.bot == true)' *.jsonl | wc -l
38468
Wait. That can’t be right. How can we have over 38,000 bot entries when there are only 2,055 total lines?
This is a classic command-line "gotcha." Let's investigate by looking at the output of our jq
command without the wc -l
.
jq 'select(.bot == true)' *.jsonl | head -5
{
"$schema": "/mediawiki/recentchange/1.0.0",
"meta": {
"uri": "https://commons.wikimedia.org/wiki/Category:Digital_Public_Library_of_America_files_missing_creator",
"request_id": "590763a0-2419-4395-8881-e1c4113b4a28",
Aha! By default, jq
pretty-prints the JSON output, turning each single-line entry into a multi-line, formatted object. The wc -l
command is counting these formatted lines, not the original log entries, which completely skews our result.
This is the exact moment where focus breaks. Now we have to go search for the right jq
flag to disable pretty-printing.
The Fix: Asking $hAI
for Help
Instead of leaving the terminal, let's just ask $hAI
to fix the command for us. We'll type our request in plain English, right where we are.
fix the jq wc command so that it doesn't expand json into multi lines
Then, we press Cmd+Return
. $hAI
analyzes our request and the previous command, and provides the solution.
jq -c 'select(.bot == true)' *.jsonl | wc -l
The -c
flag is for "compact output," which is exactly what we need. Now, we can use Cmd+Up Arrow
to recall the suggestion, and run it.
jq -c 'select(.bot == true)' *.jsonl | wc -l
1196
That looks much more reasonable. Out of 2,055 total entries, 1,196 were from bots. Problem solved, and we never had to leave the command line.
Going Deeper: From Fixing to Assisting
$hAI
is more than just a debugging tool. Now that we have the correct count, let's perform a more complex analysis. We want to find the top 5 most active bots and their hit counts.
Constructing this command chain manually can be tricky. You need to filter, extract the user field, sort, count unique entries, and then sort again numerically.
Or, you can just ask:
find the top 5 bots with their counts
Press Cmd+Return
, and $hAI
generates the entire pipeline.
jq -c 'select(.bot == true) | .user' *.jsonl | sort | uniq -c | sort -rn | head -5
Let's run it. As before, we'll use Cmd+Up Arrow
to recall the command.
jq -c 'select(.bot == true) | .user' *.jsonl | sort | uniq -c | sort -rn | head -5
256 "Dolabbot"
231 "Gzen92Bot"
150 "DPLA bot"
119 "GeographBot"
113 "SchlurcherBot"
Perfect. In seconds, we have a clear, accurate answer to our high-level question, generated from a command that would have taken time and trial-and-error to write manually.
Watch the Full Demo
You can see this entire workflow in action in the video below.
Analyzing Access Log Files With a Little Help From $hAI
Your Terminal, Smarter
This is just one example of how a shell-native AI assistant can remove friction and keep you in the flow. By learning your commands, helping fix errors, and automating complex tasks, $hAI
makes your terminal a more powerful and intuitive environment.
If you're ready to stop context-switching and start executing, you can get started with $hAI
in just a few minutes.
- Sign up at shai.sh
-
Install the shell plugin:
curl -fsSL https://github.com/shai-shell/shAI/releases/latest/download/install.sh -o /tmp/install.sh && bash /tmp/install.sh
-
Log in from your terminal:
shai login
Give it a try and see how much time you can save when you bring AI directly to your shell.
Top comments (0)