Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 97 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ask - AI CLI tool
# ask - Claude Code CLI wrapper

A lightweight bash script for querying AI models via the OpenRouter API, optimized for direct, executable output.
A lightweight bash script for querying Claude AI via the Claude Code CLI, optimized for direct, executable output with file editing capabilities.

## Quick start

Expand All @@ -12,16 +12,15 @@ cd ask
chmod +x ask
sudo cp ask /usr/local/bin/


# Make sure you have you OpenRouter API key
export OPENROUTER_API_KEY="your-api-key-here"
# Install Claude Code CLI first
# Visit: https://claude.com/claude-code

# Test it
> ask remove lines in file1 that appear in file2
ask "Write a hello world in Python"

grep -vFf file2 file1 > file3 && mv file3 file1
print("Hello, World!")

[inception/mercury-coder via Inception - 0.66s - 20.9 tok/s]
[sonnet - 1.23s - 0 tool calls - 12 tokens - $0.0001]
```

We also provide a handy install script.
Expand All @@ -31,36 +30,24 @@ We also provide a handy install script.
### Basic usage

```bash
ask ffmpeg command to convert mp4 to gif
ask "ffmpeg command to convert mp4 to gif"
```

### Model selection

```bash
# Default model (Mercury Coder - optimized for code)
ask find files larger than 20mb
# Default model (Claude Sonnet)
ask "find files larger than 20mb"

# Shorthand flags for quick model switching
ask -c "prompt" # Mercury Coder (default, best for code)
ask -g "prompt" # Gemini 2.5 Flash (fast, general purpose)
ask -s "prompt" # Claude Sonnet 4 (complex reasoning)
ask -k "prompt" # Kimi K2 (long context)
ask -q "prompt" # Qwen 235B (large model)

# Custom model by full name
ask -m "openai/gpt-4o" "Explain this concept"
```
ask -s "prompt" # Claude Sonnet (default, balanced)
ask -o "prompt" # Claude Opus (most capable, complex reasoning)
ask -h "prompt" # Claude Haiku (fastest, simple tasks)

### Provider routing

Specify provider order for fallback support:

```bash
ask --provider "cerebras,together" "Generate code"
# Custom model by name
ask -m haiku "What is 2+2?"
```

This will try Cerebras first, then fall back to Together if needed.

### System prompts

```bash
Expand All @@ -71,36 +58,60 @@ ask --system "You are a pirate" "Tell me about sailing"
ask -r "What is 2+2?"
```

### Streaming mode
### File editing

Get responses as they're generated:
File editing is **enabled by default** in the current working directory:

```bash
ask --stream "Tell me a long story"
# Claude can read and edit files automatically
ask "Read README.md and update it with current features"
ask "Fix the bug in server.js"

# Disable file editing if you only want analysis
ask --no-edits "Just analyze server.js, don't modify it"
```

### Running commands

Claude can run bash commands to gather context:

```bash
# Claude will run git commands for you
ask "Look at git diff and write a commit message"
ask "Run git status and summarize changes"

# Show statistics to see tool usage
ask --stats "Run git status and summarize changes"
```

### Pipe input

```bash
# Pipe as prompt
echo "Fix this code: print('hello world)" | ask
cat script.py | ask "Review this code"

# Pipe as context with --context flag
git diff | ask --context "Write a commit message for this diff"
cat error.log | ask --context "Explain what caused this error"
```

## Options

| Option | Description |
|--------|-------------|
| `-c` | Use Mercury Coder (default) |
| `-g` | Use Google Gemini 2.5 Flash |
| `-s` | Use Claude Sonnet 4 |
| `-k` | Use Moonshotai Kimi K2 |
| `-q` | Use Qwen3 235B |
| `-m MODEL` | Use custom model |
| `-r` | Disable system prompt |
| `--stream` | Enable streaming output |
| `--system` | Set custom system prompt |
| `--provider` | Set provider order (comma-separated) |
| `-h, --help` | Show help message |
| `-s` | Use Claude Sonnet (default) |
| `-o` | Use Claude Opus |
| `-h` | Use Claude Haiku |
| `-m MODEL` | Use custom Claude model |
| `-r` | Disable system prompt (raw model behavior) |
| `--system TEXT` | Set custom system prompt |
| `--context` | Pipe stdin as context, combine with prompt argument |
| `--no-edits` | Disable file editing (enabled by default) |
| `--permission-mode MODE` | Set permission mode (e.g., acceptEdits) |
| `--allowed-tools TOOLS` | Comma-separated list of allowed tools |
| `--stats` | Show statistics (time, tool calls, tokens, cost) |
| `--debug` | Show system context, prompts, and command (stderr) |
| `--help` | Show help message |

## Common use cases

Expand All @@ -123,6 +134,29 @@ ask "Python function to calculate factorial"
cat script.py | ask "Find potential bugs in this code"
```

### File editing and code modification
```bash
# Claude can read and modify files directly
ask "Read server.js and add error handling to the API routes"
ask "Fix the typo in README.md line 42"
ask "Refactor utils.py to use type hints"

# Disable editing for read-only analysis
ask --no-edits "Analyze the performance of this algorithm in sort.js"
```

### Git workflow
```bash
# Claude can run git commands and analyze changes
ask "Look at git diff and write a commit message"
ask "Run git status and tell me what needs attention"
ask "Review the last 3 commits and summarize changes"

# See what Claude is doing with --stats
ask --stats "Run git log --oneline -5 and summarize the recent changes"
# Output: [sonnet - 2.15s - 1 tool calls - 89 tokens - $0.0023]
```

### Quick answers
```bash
# Calculations
Expand All @@ -142,19 +176,34 @@ ask "List all Python files" | ask "Generate a script to check syntax of these fi
# Use with other tools
docker ps -a | ask "Which containers are using the most memory?"

# Debug mode to see what's happening
ask --debug "Why is my build failing?"
```

## Requirements

### Dependencies
- `bash` - Shell interpreter
- `curl` - HTTP requests to OpenRouter API
- `jq` - JSON parsing for API responses
- `bc` - Performance metrics calculation

### API access
- OpenRouter API key (get one at [openrouter.ai](https://openrouter.ai))
- Set as environment variable: `OPENROUTER_API_KEY`
- Claude Code CLI - The underlying AI engine

### Installation
1. Install Claude Code CLI from [claude.com/claude-code](https://claude.com/claude-code)
2. Clone this repository
3. Make the script executable: `chmod +x ask`
4. Copy to your PATH: `sudo cp ask /usr/local/bin/`

## Features

- **Direct executable output** - Optimized for command generation and piping
- **File editing** - Claude can read and modify files in your working directory
- **Command execution** - Claude can run bash commands to gather context
- **Smart system context** - Automatically detects OS, tools, git repos, and project type
- **Model selection** - Choose between Sonnet, Opus, or Haiku
- **Statistics** - Track tool usage, tokens, and costs with `--stats`
- **Debug mode** - See exactly what prompts are being sent
- **Caching** - System context is cached for 24 hours for performance

## License

Expand Down
Loading