Skip to content

A CLI tool for managing prompt templates and executing them with locally installed AI CLIs (Claude, Gemini, Codex). Automatically detects available providers and expands shell commands in templates - no API keys required.

License

Notifications You must be signed in to change notification settings

trknhr/ai-utils

Repository files navigation

aiu

AI Utils (aiu)

A developer-friendly CLI tool that manages reusable prompt templates and executes them using locally installed AI CLIs (Claude Code, Gemini CLI, Codex CLI, GitHub Copilot CLI). It automatically detects available AI providers, expands shell commands within templates, and eliminates the need for API keys.

Features

  • Template Management: Store reusable prompt templates with Markdown + YAML frontmatter
  • Dynamic Command Expansion: Embed shell commands in templates using {{$ command }} syntax
  • Template Arguments: Pass arguments to templates (e.g., aiu pr-review feature-branch main)
  • Built-in Templates: PR description, PR review, and commit message templates included in binary
  • Multi-Provider Support: Automatically detects and uses Claude, Gemini, Codex, or Copilot CLIs
  • No API Keys Required: Leverages your existing CLI installations

Installation (macOS / Linux)

Homebrew

brew tap trknhr/homebrew-tap
brew install aiu

# Upgrade
brew upgrade aiu

install.sh

Install the latest release via:

curl -sSfL https://raw.githubusercontent.com/trknhr/ai-utils/main/install.sh | sh

This will:

  • Detect your OS and CPU architecture
  • Download the correct binary
  • Install it to /usr/local/bin/aiu

Quick Start

1. Install a supported AI CLI

You need at least one of these installed:

2. Run a prompt

# Generate PR description
aiu pr-desc

# Review a PR branch (compare feature/xxx with origin/main)
aiu pr-review feature/xxx

# Review with custom base branch
aiu pr-review feature/xxx develop

# Generate commit message from staged changes
git add .
aiu commit-msg

# Use codex explicitly
aiu pr-desc -P codex

# Override model (wins over config)
aiu pr-desc -P copilot --model gpt-5

3. Enable auto commit messages (optional)

# Enable AI-powered commit messages globally
aiu enable-auto-commit

# Now just use git commit normally - AI generates the message!
git add .
git commit

# Skip AI for a specific commit
AI_IGNORE=1 git commit

# Disable auto commit
aiu disable-auto-commit

How It Works

┌─────────────┐    1. Read Template    ┌──────────────────┐
│ Prompt File │◄──────────────────────│   aiu CLI        │
│  (*.md)     │                        │                  │
└─────────────┘                        │  - Parse YAML    │
                                       │  - Expand {{$}}  │
┌─────────────┐    2. Execute Commands │  - Detect AI CLI │
│ Shell       │◄──────────────────────│                  │
│ (git, etc)  │                        └────────┬─────────┘
└─────────────┘                                 │
                                                │ 3. Send Prompt
                 ┌──────────────────────────────▼─────┐
                 │ AI Provider (Claude/Gemini/Codex/Copilot) │
                 └────────────────────────────────────┘
  1. Template Loading: Reads Markdown files with YAML frontmatter
  2. Command Expansion: Executes {{$ command }} placeholders and injects output
  3. Provider Detection: Automatically selects available AI CLI (Claude → Gemini → Codex → Copilot)
  4. Execution: Sends expanded prompt to the provider and displays response

Template System

Template Format

Templates are Markdown files with optional YAML frontmatter:

---
name: pr-desc
description: Generate PR description from staged changes
requires:
  - git
---

Generate a clear and concise PR description based on the following git diff.

## Changes
\```
{{$ git diff --cached }}
\```

## Recent Commit History
\```
{{$ git log --oneline -5 }}
\```

Output format:
- Title: One-line summary
- Overview: Purpose and context
- Details: List of main changes

Command Syntax

Syntax Description Example
{{$ command }} Execute shell command and insert output {{$ git diff }}
$ARG1, $ARG2... Template arguments (passed from CLI) {{$ echo $ARG1 }}
$ARGS All arguments joined by space {{$ echo $ARGS }}

Template Location

Built-in templates are embedded in the binary. Custom templates can be stored in:

  • <workspace>/.aiu/prompts/ (overrides global; searched first)
  • ~/.aiu/prompts/ (global)
  • Additional directories via config.yaml (prompt_dirs)

Configuration

Configuration files (merged in this order; workspace overrides global):

  • ~/.aiu/config.yaml
  • <workspace>/.aiu/config.yaml
# Prompt directories (searched in order)
prompt_dirs:
  - <workspace>/.aiu/prompts
  - ~/.aiu/prompts
  - ~/.local/share/ai-utils/prompts

# Provider priority (tries in order)
provider_priority:
  - claude
  - gemini
  - codex
  - copilot

# Provider-specific settings
providers:
  claude:
    command: claude
    args: ["-p", "--output-format", "text"]
    timeout: 120s
  gemini:
    command: gemini
    args: []
    timeout: 120s
  codex:
    command: codex
    args: []
    model: ""
    timeout: 120s
  copilot:
    command: copilot
    args: ["-s"]
    model: ""
    timeout: 120s

# Defaults
defaults:
  timeout: 60s
  verbose: false

Usage Examples

Generate PR Description

# From current branch vs origin/main
aiu pr-desc

PR Code Review

# Review current branch vs origin/main
aiu pr-review

# Review specific branch vs origin/main
aiu pr-review feature/new-api

# Review with custom base branch
aiu pr-review feature/new-api develop

Generate Commit Message

# Stage changes first
git add .

# Generate commit message from staged changes
aiu commit-msg

# Or use auto-commit hook
aiu enable-auto-commit
git commit  # AI generates message automatically

Dry Run (Preview)

# Show expanded prompt without sending to AI
aiu pr-review --dry-run

Specify Provider

# Use specific provider
aiu pr-desc --provider gemini

Parallel Providers

# Run all available providers in parallel, then choose the best output
aiu pr-desc --multiple
# or: aiu pr-desc -m

Direct Prompt (Skip Template)

# Send prompt text directly (no template expansion)
aiu run -p "Write a PR description for this change"

Development

Build from Source

# Clone repository
git clone https://github.com/trknhr/ai-utils.git
cd ai-utils

# Build
make build

# Install locally
make install

# Run tests
make test

Project Structure

ai-utils/
├── cmd/aiu/              # CLI entry point
├── internal/
│   ├── cli/              # Command implementations
│   ├── config/           # Configuration management
│   ├── provider/         # AI provider implementations
│   └── template/         # Template parser & executor
│       └── prompts/      # Built-in templates (embedded)
├── build/                # Build output (gitignored)
├── go.mod
├── Makefile
└── README.md

Requirements

  • Go 1.21+
  • At least one supported AI CLI installed

Built-in Templates

Template Description Usage
pr-desc Generate PR description from git diff aiu pr-desc
pr-review Comprehensive code review checklist aiu pr-review [target] [base]
commit-msg Generate commit message from staged changes aiu commit-msg

pr-review Output

The PR review template generates a detailed review covering:

  • Code Quality (readability, DRY, complexity)
  • Security (input validation, credentials, vulnerabilities)
  • Test Coverage (unit tests, edge cases)
  • Performance (N+1, memory, optimization)
  • Maintainability (docs, error handling, logging)
  • Architecture & Design (separation of concerns, dependencies)

Roadmap

  • Phase 1: Basic template system + Claude provider
  • Phase 2: Built-in templates, template arguments, auto-commit hook
  • Phase 3: Gemini & Codex providers, aiu list command
  • Phase 4: Interactive mode, colored output, better error messages
  • Phase 5: Plugin system, custom providers

Feedback & Contributions

PRs and issues welcome → github.com/trknhr/ai-utils

License

Apache 2.0 License — © 2025 Teruo Kunihiro

About

A CLI tool for managing prompt templates and executing them with locally installed AI CLIs (Claude, Gemini, Codex). Automatically detects available providers and expands shell commands in templates - no API keys required.

Resources

License

Stars

Watchers

Forks

Packages

No packages published