Showing posts with label terminal. Show all posts
Showing posts with label terminal. Show all posts

Ask AI from Anywhere: No GUI, No Heavy Clients, No Friction

Ever wished you could ask AI from anywhere without needing an interface? Imagine just typing ? and your question in any terminal the moment it pops into your head, and getting the answer right away! In this post, I explain how I wrote a tiny shell script that turns this idea into reality, transforming the terminal into a universal AI client. You can query Reka, OpenAI, or a local Ollama model from any editor, tab, or pipeline—no GUI, no heavy clients, no friction.

Small, lightweight, and surprisingly powerful: once you make it part of your workflow, it becomes indispensable.

💡 All the code scripts are available at: https://github.com/reka-ai/terminal-tools


The Core Idea

There is almost always a terminal within reach—embedded in your editor, sitting in a spare tab, or already where you live while building, debugging, and piping data around. So why break your flow to open a separate chat UI? I wanted to just type a single character (?) plus my question and get an answer right there. No window hopping. No heavy client.

How It Works

The trick is delightfully small: send a single JSON POST request to whichever AI provider you feel like (Reka, OpenAI, Ollama locally, etc.):

# Example: Reka
curl https://api.reka.ai/v1/chat
     -H "X-Api-Key: <API_KEY>" 
     -d {
          "messages": [
            {
              "role": "user",
              "content": "What is the origin of thanksgiving?"
            }
          ],
          "model": "reka-core",
          "stream": false
        }
# Example: Ollama local
curl http://127.0.0.1:11434/api/chat 
-d {  
      "model": "llama3",   
      "messages": [
        {
          "role": "user", 
          "content": "What is the origin of thanksgiving?"
        }], 
      "stream": false
    }

Once we get the response, we extract the answer field from it. A thin shell wrapper turns that into a universal “ask” verb for your terminal. Add a short alias (?) and you have the most minimalist AI client imaginable.

Let's go into the details

Let me walk you through the core script step-by-step using reka-chat.sh, so you can customize it the way you like. Maybe this is a good moment to mention that Reka has a free tier that's more than enough for this. Go grab your key—after all, it's free!

The script (reka-chat.sh) does four things:

  1. Captures your question
  2. Loads an API key from ~/.config/reka/api_key
  3. Sends a JSON payload to the chat endpoint with curl.
  4. Extracts the answer using jq for clean plain text.

1. Capture Your Question

This part of the script is a pure laziness hack. I wanted to save keystrokes by not requiring quotes when passing a question as an argument. So ? What is 32C in F works just as well as ? "What is 32C in F".

if [ $# -eq 0 ]; then
    if [ ! -t 0 ]; then
        QUERY="$(cat)"
    else
        exit 1
    fi
else
    QUERY="$*"
fi

2. Load Your API Key

If you're running Ollama locally you don't need any key, but for all other AI providers you do. I store mine in a locked-down file at ~/.config/reka/api_key, then read and trim trailing whitespace like this:

API_KEY_FILE="$HOME/.config/reka/api_key"
API_KEY=$(cat "$API_KEY_FILE" | tr -d '[:space:]')

3. Send The JSON Payload

Building the JSON payload is the heart of the script, including the API_ENDPOINT, API_KEY, and obviously our QUERY. Here’s how I do it for Reka:

RESPONSE=$(curl -s -X POST "$API_ENDPOINT" \
     -H "X-Api-Key: $API_KEY" \
     -H "Content-Type: application/json" \
     -d "{
  \"messages\": [
    {
      \"role\": \"user\",
      \"content\": $(echo "$QUERY" | jq -R -s .)
    }
  ],
  \"model\": \"reka-core\",
  \"stream\": false
}")

4. Extract The Answer

Finally, we parse the JSON response with jq to pull out just the answer text. If jq isn't installed we display the raw response, but a formatted answer is much nicer. If you are customizing for another provider, you may need to adjust the JSON path here. You can add echo "$RESPONSE" >> data_sample.json to the script to log raw responses for tinkering.

With Reka, the response look like this:

{
    "id": "cb7c371b-3a7b-48d2-829d-70ffacf565c6",
    "model": "reka-core",
    "usage": {
        "input_tokens": 16,
        "output_tokens": 460,
        "reasoning_tokens": 0
    },
    "responses": [
        {
            "finish_reason": "stop",
            "message": {
                "role": "assistant",
                "content": " The origin of Thanksgiving ..."
            }
        }
    ]
}
The value we are looking for and want to display is the `content` field inside `responses[0].message`. Using `jq`, we do:
echo "$RESPONSE" | jq -r '.responses[0].message.content // .error // "Error: Unexpected response format"'

Putting It All Together

Now that we have the script, make it executable with chmod +x reka-chat.sh, and let's add an alias to your shell config to make it super easy to use. Add one line to your .zshrc or .bashrc that looks like this:

alias \\?=\"$REKA_CHAT_SCRIPT\"

Because ? is a special character in the shell, we escape it with a backslash. After adding this line, reload your shell configuration with source ~/.zshrc or source ~/.bashrc, and you are all set!

The Result

Now you can ask questions directly from your terminal. Wanna know what is origin of Thanksgiving, ask it like this:

? What is the origin of Thanksgiving

And if you want to keep the quotes, please you do you!

Extra: Web research

I couldn't stop there! Reka also supports web research, which means it can fetch and read web pages to provide more informed answers. Following the same pattern described previously, I wrote a similar script called reka-research.sh that sends a request to Reka's research endpoint. This obviously takes a bit more time to answer, as it's making different web queries and processing them, but the results are often worth the wait—and they are up to date! I used the alias ?? for this one.

On the GitHub repository, you can find both scripts (reka-chat.sh and reka-research.sh) along with a script to create the aliases automatically. Feel free to customize them to fit your workflow and preferred AI provider. Enjoy the newfound superpower of instant AI access right from your terminal!

What's Next?

With this setup, the possibilities are endless. Reka supports questions related to audio and video, which could be interesting to explore next. The project is open source, so feel free to contribute or suggest improvements. You can also join the Reka community on Discord to share your experiences and learn from others.


Resources




Reading Notes #664

Welcome to another edition of my weekly reading notes! This week's collection brings together some fascinating developments across the tech landscape. From the intricacies of building cross-platform .NET tools to impressive AI breakthroughs like Warp's stellar performance on SWE-bench, there's plenty to explore. I've also discovered some thought-provoking content about leadership, product management, and the art of meaningful communication. Whether you're interested in the latest AI tools, looking for career insights, or simply want to stay current with industry trends, this week's selection has something valuable for every developer and tech professional.



Programming

  • Using and authoring .NET tools (Andrew Lock) - Interesting post that shares the behind-the-scenes when you're building a tool for multiple targets and the challenge that it represents. Those also share the new ways of .NET 10

AI

Podcasts

Miscellaneous

Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week.

If you have interesting content, share it!

~frank

Reading Notes #662

From Docker's security practices to the latest in GPT-5 discussions, there's quite a mix of topics to dive into. I particularly enjoyed the thought-provoking piece about junior developers in the age of LLMs - it's a conversation we should all be having.


As always, grab your favorite beverage, and let's explore what caught my attention this week!

DevOps

AI

Podcasts

Miscellaneous


Sharing my Reading Notes is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week.

If you have interesting content, share it!

~frank

Reading Notes #604

It's reading notes time! It is a habit I started a long time ago, where I share a list of all the articles, blog posts, and books that catch my interest during the week. 


You also read something you liked? Share it!

 

Cloud

Programming

DevOps

Miscellaneous

  • Introducing Plans on Microsoft Learn (Kaberi Bell) - Would it be to be a data engineer, AI specialist, app builder there's a plan for you and that's a very cool new feature on learn have a look this blog post explain all of it

  • How Do You Measure Developer Experience? (Jennifer Riggins) - An interesting article about what and how measure performance. I didn't know so many system and details concepts were that detailed.

  • Windows Terminal Preview 1.21 Release (Christopher Nguyen) - Tons of new features again and I love| seeing all those community contributions.

~Frank

Reading Notes #593

It is time to share new reading notes. It is a habit I started a long time ago where I share a list of all the articles, blog posts, and books that catch my interest during the week.

If you think you may have interesting content, share it!

Cloud

Programming

Miscellaneous

~Frank

Reading Notes #575

Happy Thanksgiving to all Canadian🍁! 

It is time to share new reading notes. It is a habit I started a long time ago where I share a list of all the articles, blog posts, and books that catch my interest during the week.

If you think you may have interesting content, share it!

Suggestion of the week

Programming

Open Source

Podcasts

~Frank

Reading Notes #557


It is time to share new reading notes. It is a habit I started a long time ago where I share a list of all the articles, blog posts, and books that catch my interest during the week. 

If you have interesting content, share it!

Open Source

  • Introducing Dart | Windows (Tim Sneath) - This a nice post that makes us dive into a world close to the machine. An interesting open-source project indeed.

Programming

LowCode

Podcasts

Miscellaneous

~Frank

Reading Notes #540

Good Monday!

Already time to share new reading notes. It is a habit I started a long time ago where I share a list of all the articles, blog posts, podcast episodes, and books that catch my interest during the week.

You think you may have interesting content, share it!

Cloud

Programming

Databases

Miscellaneous

Reading Notes #533


Good Monday!
It's time to share my reading notes. Those are a curated list of all the articles and blog posts, that caught my interest during the week and that I found interesting. It's a mix of the actuality and what I consumed.

If you think you may have interesting content, share it!

Cloud

Programming

Miscellaneous

~Enjoy!


Reading Notes #528


Good Monday, 
Already time to share new reading notes. Here is a list of all the articles, and blog posts that catch my interest during the week. 

If you think you may have interesting content, share it!

Cloud

Podcast

Miscellaneous

~frank


Reading Notes #508


It's... Tuesday! 
Yes I know one day later, but it's still time to share my reading notes. Those are a curated list of all the articles, blog posts, podcast episodes, and books that catch my interest during the week and that I found interesting. It's a mix of the actuality and what I consumed. 

If you think you may have interesting content, share it!

Cloud

Programming

Podcast

Miscellaneous


~frank


Reading Notes #487

It's... Tuesday! Yes I know one day later, but it's still time to share my reading notes. 

Those are a curated list of all the articles, blog posts, podcast episodes, and books that catch my interest during the week and that I found interesting. It's a mix of the actuality and what I consumed. 

You think you may have interesting content, share it!

Suggestion of the week

Cloud

Programming

Podcasts

  • Egil Hansen on Blazor Testing with bUnit - Episode 169 (Azure DevOps Podcast) - It's the second time I hear good things about bUnit. This is an open-source library for testing Blazor components that can be paired with many popular test frameworks. I need to try it.

  • Podcast Tags: Are They Still Relevant? (Feed Your Brand) - It all makes sense. I am not 100% sure about YouTube however because all captions are indexed... I think. But if you create content listen to this.

  • Family with Ari Emanuel (A Bit of Optimism) - The best way to learn and grow is to try and fail ( aka fall). A great episode very interesting.



☁️ Frank

Reading Notes #482


Another Monday, a new reading notes; a list of all the articles, blog posts, and books that catch my interest during the week and that I found interesting. It's a mix of the actuality and what I consumed.

You think you may have interesting content, share it!

Cloud

Programming

Podcast


~frank


Reading Notes #468

Every Monday, I share my "reading notes". Those are a curated list of all the articles, blog posts, podcast episodes, and books that catch my interest during the week and that I found interesting. It's a mix of the actuality and what I consumed.

You think you may have interesting content, share it!


Cloud

Programming

Miscellaneous


~Frank


Reading Notes #460

DevRel 2021 pass

Cloud


Programming


Podcast

  • #188 – Fame, Focus, and Billions of Pageviews with Evan Britton of Famous Birthdays (Indie Hackers) - A nice story where people focus on the users, worked super hard (and continue to do it), and had amazing success.

  • How to Stop Being Complacent (Influencer Entrepreneurs with Jenny Melrose) - A nice episode to "kick our butt" and get back on track. Yes, 2020 indeed brought tons of new challenges at all and every level. However. we must try to make this year better.

  • Who Owns Open-Source Software? (Coding Blocks) - Great discussion. Most of us, at some point, have to ask ourselves those questions (at least I know I did). It was very interesting listening to this episode and follow their thoughts.

  • 631 - How to Explain a Gap in Your Résumé (Modern Mentor) - I have gaps in my resumé and I always been very comfortable about it. When I saw the title of this episode I thought maybe I should be concerned... Happy to know I was right!


Miscellaneous


Books


Beyond the Trees: A Journey Alone Across Canada's Arctic

Author: Adam Shoalts

Nice adventure. I wish I could see all those images, animals, and horizon. I had a good time reading this odyssey. And for the record, as a canoeist/ kayaker I was impressed by the upriver challenge.












~Frank

Reading Notes #456


The suggestion of the week

Cloud

Programming

Podcasts

Miscellaneous


~Frank

Reading Notes #447


Cloud

Programming

Miscellaneous

Books


Talk Triggers: The Complete Guide to Creating Customers with Word of Mouth
 

Author: Jay Baer

A good book filled with good stories. I personally like it when they deconstruct like this winner journey or factor that makes those ideas, plans, actions different. The idea of a talk trigger is good and it was nice that the creation, lifetime, and death of a talk trigger was also cover in the book.



~Frank

Reading Notes #445


Every Monday, I share my "reading notes". Those are a curated list of all the articles, blog posts, podcast episodes, and books that catch my interest during the week and that I found interesting. It's a mix of the actuality and what I consumed.

You think you may have interesting content, share it!

Cloud

Programming

Podcasts

Miscellaneous


~ Have a nice week!

Reading Notes #436

The suggestion of the week

Cloud


Programming


Podcasts


Miscellaneous


Reading Notes #433

Every Monday, I share my "reading notes". Those are a curated list of all the articles, blog posts, podcast episodes, and books that catch my interest during the week and that I found interesting. It's a mix of the actuality and what I consumed. 

You think you may have interesting content, share it!

Cloud


Programming


Podcast


Miscellaneous