Package Exports
- @chmgh0st/grok-cli
- @chmgh0st/grok-cli/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@chmgh0st/grok-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Grok CLI
A command-line interface for interacting with Grok AI, featuring markdown-based knowledge storage and custom commands.
Features
- ๐ค Interactive chat with Grok AI
- ๐ Markdown-based knowledge base system
- ๐ Search and organize code snippets
- ๐ Full codebase indexing and searching
- ๐พ Persistent storage of indexed files in
.grok-memory
- ๐ Automatic context from your project files
- ๐ Conversation history with context awareness
- ๐ก Real-time file watching with auto-update
- โก Custom slash commands
- ๐จ Colorful terminal interface
- ๐ AI-powered code generation and refactoring
- ๐งช Automatic test generation
- ๐ง Git integration with formatted output
- ๐ Advanced debugging assistance with error analysis
- ๐ Performance profiling and optimization suggestions
- ๐ฆจ Code smell detection and quality analysis
Installation
npm install
npm run build
npm link
Quick Start
Run the setup wizard to configure everything at once:
grok setup
This will:
- Configure your Grok API key
- Create the knowledge base directory
- Add example knowledge entries
Configuration
To update just the API configuration:
grok config
Or create a .env
file:
cp .env.example .env
# Edit .env with your API key
Usage
Interactive Chat Mode
grok chat
Single Question
grok ask "How do I implement a binary search?"
Commands
In chat mode, use these commands:
Knowledge Base Commands
/help
- Show available commands/search <query>
- Search knowledge base/tag <tag>
- Find entries by tag/category <category>
- Find entries by category/list
- List all knowledge entries
Codebase Commands
/index [pattern]
- Index project files (default: all files, auto-starts watching)/codesearch <query>
- Search for code in indexed files/structure
- Show project file structure/files [language]
- List files by programming language/memory
- Show what's stored in Grok's memory/pwd
- Show current working directory/watch
- Start watching for file changes/unwatch
- Stop watching for file changes
Code Generation Commands
/create <file> <description>
- Create new file with AI-generated code/generate <type> <description>
- Generate code (function/class/component/test)/test-gen <file>
- Generate tests for a file/refactor <file> <instruction>
- Refactor code with AI assistance
Git Commands
/git status
- Show git status with color formatting/git diff [file]
- Show changes with syntax highlighting/git log [count]
- View commit history/git stash [save/pop/list]
- Manage stashes/commit "message" [files]
- Commit changes/branch [name]
- Create or list branches
Debugging Commands
/debug-error <error>
- Analyze error messages and get fix suggestions/debug-stack <trace>
- Analyze stack traces to find root causes/profile <file>
- Get performance optimization suggestions/smells [file]
- Detect code smells and quality issues
General Commands
/clear
- Clear terminal/exit
- Exit chat
Code Generation Examples
Create a new component
/create src/components/Button.tsx "A reusable button component with primary and secondary variants"
Generate a function
/generate function "A debounce utility function that delays execution"
Generate tests for existing code
/test-gen src/utils/helpers.ts
Refactor code
/refactor src/api/client.ts "Add retry logic with exponential backoff"
Git Integration Examples
Check repository status
/git status
Commit changes
/commit "feat: add user authentication" src/auth/*.ts
Create a new branch
/branch feature/new-feature
Debugging Examples
Analyze an error
/debug-error "TypeError: Cannot read property 'name' of undefined at UserProfile.render (app.js:42:15)"
Analyze a stack trace
/debug-stack "Error: Connection timeout
at Socket.onTimeout (net.js:451:8)
at Socket.emit (events.js:315:20)
at Socket._onTimeout (net.js:478:8)
at listOnTimeout (internal/timers.js:549:17)"
Profile performance
/profile src/utils/dataProcessor.ts
Detect code smells
/smells # Analyze entire codebase
/smells src/components/Dashboard.tsx # Analyze specific file
Knowledge Base
Store code snippets and documentation in markdown files in the .grok-memory/
directory:
---
title: Your Code Snippet
tags: [tag1, tag2]
category: Category Name
---
# Content here
Your code and explanations...
Security Considerations
API Key Security
- Never commit your API key: Always use environment variables or the config command
- The API key is stored locally in
~/.grok-cli/config.json
- Use
.env
files for development (already in.gitignore
)
Data Privacy
- All indexed code is stored locally in
.grok-memory/
- No code is sent to external services unless you explicitly ask questions about it
- The
.grok-memory/
directory is excluded from git by default
Ignore Patterns
- Sensitive files are automatically excluded from indexing
- You can add custom ignore patterns during setup or in your config
- The indexer respects
.gitignore
patterns
Development
npm run dev # Run in development mode
npm run build # Build for production
npm run lint # Run linter
npm run typecheck # Type checking