A command-line interface tool powered by the Grok API, providing an AI assistant directly in your terminal.
- 🤖 Interactive chat mode with Grok AI
- 💬 Single-question mode for quick queries
- 🎨 Beautiful terminal UI with colors
- 📝 Conversation history support
- ⚡ Fast and lightweight
- 🛠️ Function calling support - Grok can execute shell commands when needed
- 🖥️ Cross-platform command execution (Windows/Linux/macOS)
# Clone the repository
git clone <repository-url>
cd grokcli
# Install dependencies
npm install
# Build the project
npm run build
# Link the CLI globally (optional)
npm linknpm install -g grokcliGrok CLI loads configuration from a global config directory:
macOS / Linux:
~/.grokcli/.env
Windows (PowerShell):
$env:USERPROFILE\.grokcli\.env
This global config location allows grokcli to run from any directory without needing a local .env file.
-
Get your Grok API key from X.AI
-
Create the global config directory and file:
macOS / Linux:
mkdir -p ~/.grokcli
nano ~/.grokcli/.envWindows (PowerShell):
mkdir $env:USERPROFILE\.grokcli
notepad $env:USERPROFILE\.grokcli\.env- Add your API keys to the
.envfile:
GROK_API_KEY=your_api_key_here
SERPAPI_KEY=your_serpapi_key_hereAlternative: You can also create a .env file in the project directory as a fallback, but the global config is recommended for convenience.
Start an interactive conversation with Grok:
grokcli
# or
grokcli chatType your questions and get responses in real-time. Type exit or quit to end the session.
Inside the interactive mode, you can use these commands:
/help- Show available commands/clear- Clear conversation history/exit- Exit the application/version- Show version information/model [name|list]- View or switch the active model/search <query>- Search the web using SerpAPI/exec <command>- Execute shell command directly
Ask a single question:
grokcli "What is the meaning of life?"Grok CLI now supports function calling! When you ask Grok to perform system-related tasks, it can automatically execute shell commands:
> List all files in the current directory
# Grok will automatically execute the appropriate command:
# - Windows: dir
# - Linux/macOS: ls -laThe AI automatically detects your operating system and uses the correct commands. You can ask Grok to:
- Check system information
- List files and directories
- View file contents
- Run development commands (npm, git, etc.)
- And much more!
Note: Shell commands are executed with the same permissions as your terminal session. Be cautious when allowing command execution.
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build the project
npm run build
# Run the built version
npm startgrokcli/
├── src/
│ ├── index.ts # Main CLI entry point
│ └── grok-client.ts # Grok API client
├── dist/ # Compiled JavaScript
├── .env # Environment variables (create this)
├── .gitignore
├── package.json
├── tsconfig.json
├── LICENSE
└── README.md
The tool uses the Grok API from X.AI. Make sure you have access to the API and a valid API key.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Powered by Grok API
- Inspired by other AI CLI tools like Gemini and Claude Code
If you encounter any issues or have questions, please open an issue on GitHub.