Build Your Own AI-Powered Command Line Tool with Groq Code CLI

Groq Code CLI

The command line is still one of the most powerful tools in software development. But modern CLIs (Command Line Interfaces) can feel bloated, overly complex, or difficult to customize.

Groq Code CLI takes a different approach.

This lightweight, open-source CLI tool is designed for developers who want full control—without the weight of large frameworks. Whether you’re building internal developer tools, experimenting with AI workflows, or crafting your own interactive CLI environment, Groq Code CLI gives you the foundation.


What Makes Groq Code CLI Different?

Most CLI tools today come with massive feature sets. They’re powerful, but often hard to modify. That makes them unfriendly for developers who want to build their own tools or personalize the workflow.

Groq Code CLI offers:


  • A simple, minimal base

  • All core features of modern CLIs

  • Deep customization ability

  • Instant access to Groq language models

  • Easy extensibility using TypeScript

You don’t have to fight against the tool. You build with it.


Use Cases for Groq Code CLI

Groq Code CLI can be adapted for a wide range of purposes. Some examples include:


  • Creating developer assistants that use AI

  • Building internal CLI tools for your team

  • Writing custom commands to automate tasks

  • Integrating AI model prompts directly into the terminal

  • Learning how CLI applications are structured

You can run it globally across directories or keep it local to your project—your choice.


Installing Groq Code CLI

Groq Code CLI can be installed in two ways depending on your intent: for full development or just to try it out.

Option 1: Local Development Setup (Recommended)

Use this method if you plan to customize the CLI or explore the codebase.

git clone https://github.com/build-with-groq/groq-code-cli.git
cd groq-code-cli
npm install
npm run build
npm link

To enable live updates while coding:

npm run dev

Option 2: Quick Trial (No Install Required)

To run it directly without modifying code:

npx groq-code-cli@latest

This lets you use the latest CLI version instantly.


Starting a Groq Session

After installation, launch Groq CLI by typing:

groq

This opens an interactive AI-powered chat session in your terminal.

On first use, you’ll need to log in. Enter:

/login

You’ll be prompted to input your API key from the Groq Console. Once authenticated, a configuration folder is created in your home directory (.groq/), storing your API key and preferences.

You can also define your key using an environment variable:

export GROQ_API_KEY=your_api_key_here

Built-in Slash Commands

Groq CLI supports intuitive commands starting with /, similar to popular chat applications.

Command Purpose
/help Show list of available commands
/login Log in using your Groq API key
/model Choose which Groq model to use
/clear Clear the current chat context
/reasoning Toggle AI reasoning output visibility

These commands enhance the usability of the CLI and allow quick interaction with the system.


Command Line Options

In addition to slash commands, Groq CLI supports standard command line arguments when launching:

groq [options]

Options:
  -t, --temperature <temp>    Set model creativity (default: 1)
  -s, --system <message>      Provide a custom system prompt
  -d, --debug                 Enable debug logs in debug-agent.log
  -h, --help                  Display help message
  -V, --version               Show version information

You can tailor the AI’s behavior by adjusting these parameters.


How the Project Is Organized

Understanding the file structure is key if you’re planning to extend Groq Code CLI.

Here’s how the main components are laid out:

groq-code-cli/
├── src/
│   ├── commands/           # Slash command definitions
│   ├── core/               # CLI logic and Groq agent interface
│   ├── tools/              # Extensible tools for AI to call
│   ├── ui/                 # Text UI (TUI) components
│   └── utils/              # File operations, settings, markdown
├── docs/                   # Documentation and images
├── package.json            # Project dependencies and metadata
├── tsconfig.json           # TypeScript settings
└── LICENSE                 # Open-source license (MIT)

Main entry points include:


  • src/core/cli.ts — Starts the CLI

  • src/core/agent.ts — Handles communication with Groq models

  • src/ui/hooks/useAgent.ts — Connects the UI to the AI

Customizing the CLI: Adding Tools and Commands

Groq Code CLI is designed to be extended. You can add new AI tools or custom commands to shape the behavior exactly how you want.

Adding a New Tool (Function for AI to Call)

Tools allow the model to trigger custom functions from the CLI.

1. Define a Schema

In src/tools/tool-schemas.ts:

export const YOUR_TOOL_SCHEMA: ToolSchema = {
  type: 'function',
  function: {
    name: 'your_tool_name',
    description: 'What the tool does',
    parameters: {
      type: 'object',
      properties: {
        param1: { type: 'string', description: 'Description of param1' }
      },
      required: ['param1']
    }
  }
};

2. Implement the Function

In src/tools/tools.ts:

export async function yourToolName(param1: string): Promise<ToolResult> {
  // Logic here
  return createToolResponse(true, result, 'Execution successful');
}

3. Register the Tool

Ensure your function and schema are added to:


  • TOOL_REGISTRY

  • ALL_TOOL_SCHEMAS

Now your tool is callable by the Groq model.


Adding a Custom Slash Command

Commands are direct user instructions, defined similarly to tools.

1. Create the Command File

In src/commands/definitions/your-command.ts:

import { CommandDefinition, CommandContext } from '../base.js';

export const yourCommand: CommandDefinition = {
  command: 'yourcommand',
  description: 'Describe the command',
  handler: ({ addMessage }: CommandContext) => {
    addMessage({
      role: 'system',
      content: 'Response message'
    });
  }
};

2. Register the Command

Import and include your command in src/commands/index.ts under availableCommands.

Now it will respond to /yourcommand inputs.


Changing the Startup Command

The CLI is launched using groq by default. To change this (e.g., to mycli):

  1. Open package.json
  2. Edit the "bin" field:
"bin": {
  "mycli": "./dist/core/cli.js"
}
  1. Rebuild and relink:
npm run build
npm link

You can now run your custom CLI with:

mycli

Local Development Workflow

For developers customizing or contributing, these scripts are helpful:

Command Purpose
npm run build Compile TypeScript to the dist/ folder
npm run dev Watch files and rebuild automatically

During development, keep the dev script running in the background to reflect changes instantly.


Frequently Asked Questions

Do I need an internet connection to use Groq CLI?

Yes. Groq CLI communicates with online Groq models using API calls.


Where is my API key stored?

After logging in, your API key is saved in a local folder:
~/.groq/

You can also configure it per project using environment variables.


Can I use Groq CLI with a custom AI model?

While Groq CLI is built for Groq models, developers can adapt src/core/agent.ts to connect to other model APIs. This gives you full flexibility over the backend.


What kind of tools can I build?

Some tool ideas:


  • Source code analyzers

  • Custom web search integrations

  • Conflict resolution helpers

  • Data processing modules

  • Knowledge graph utilities

Anything you can write in TypeScript, you can integrate.


Why Groq Code CLI Matters

Groq Code CLI isn’t a finished product. It’s a starting point.

It gives developers a powerful but minimal foundation to:


  • Explore AI interactions in the terminal

  • Build assistants tailored to their work

  • Control every piece of their CLI environment

  • Extend commands and tools easily

  • Learn by modifying a real, working CLI

Whether you’re learning, prototyping, or building tools for your team, Groq Code CLI lets you move fast and stay in control.


Contribute or Learn More

You can find the full source code and contribute at:

👉 https://github.com/build-with-groq/groq-code-cli

Open issues, submit pull requests, or explore how others are using Groq on X/Twitter.