Skip to main content

Ask openai on your terminal

Project description

Agent CLI Tool

PyPI version License: MIT

A powerful command-line tool for interacting with AI models (OpenAI, DeepSeek, Claude) directly from your terminal. Features a plugin-based architecture, multiple UI modes, and extensible hook system.

Features

  • Three UI Modes:
    • stdout - Plain text with ANSI colors
    • rich - Live markdown rendering with syntax highlighting
    • tui - Full interactive terminal UI with session management
  • AI Modes:
    • default - General purpose conversations
    • shell - Generate shell commands only
    • code - Generate code only
  • Plugin System - Hook-based architecture for extending functionality
  • Built-in Plugins:
    • @file("path") - Inject file content into prompts
    • @fetch("url") - Fetch and inject web content
    • Shell command execution confirmation
  • Multi-modal Input - Command-line args, pipe, or interactive TTY
  • Session Management (TUI mode) - History browsing and persistence

Installation

Using pip

pip install agent-cli-tool

Using uv

uv tool install agent-cli-tool

From source

git clone https://github.com/Awoodwhale/agent-cli-tool.git
cd agent-cli-tool
uv pip install -e .

Configuration

Create a configuration file at ~/.config/agent-cli-tool/.env:

# Required
API_KEY=your_api_key
BASE_URL=https://api.openai.com/v1
DEFAULT_MODEL=deepseek-chat

# Optional
UI_MODE=stdout              # stdout | rich | tui
DEFAULT_LANGUAGE=python3    # Default language for code mode
RICH_STYLE=github-dark      # Pygments style for rich mode
STREAM=true                 # Enable streaming
TIMEOUT=60                  # Request timeout in seconds

# Custom prompts
DEFAULT_PROMPT=You are a helpful assistant
SHELL_PROMPT=Provide only shell commands...
CODE_PROMPT=Provide only code...

# UI customization (for stdout/rich modes)
USER_EMOJI=๐Ÿ‘ค
AI_EMOJI=๐Ÿค–
THINK_START_EMOJI=๐Ÿค” [Thinking]
THINK_END_EMOJI=๐Ÿ’ก [Done]

Usage

Basic Query

agent-cli-tool "Explain quantum computing"

UI Modes

# Plain text output (default)
agent-cli-tool "What is AI?"

# Markdown rendering
agent-cli-tool --ui-mode rich "Explain machine learning"

# Interactive TUI with session management
agent-cli-tool --ui-mode tui

AI Modes

# Shell mode - generates shell commands only
agent-cli-tool --shell "list all python processes"

# Code mode - generates code only
agent-cli-tool --code "fibonacci function in python"

Conversation Mode

# Multi-turn conversation
agent-cli-tool --conversation
# or
agent-cli-tool -c

Model Selection

agent-cli-tool -m GPT-5 "Explain quantum computing"     # GPT-5
agent-cli-tool -m deepseek-r1 "Solve this math problem" # DeepSeek Reasoner
agent-cli-tool -m "claude sonnet 4.5" "Write a poem"    # claude sonnet 4.5

Output to File

agent-cli-tool --code "web scraper in python" --output scraper.py

Using Plugins

# Inject file content
agent-cli-tool 'Review this code: @file("src/main.py")'

# Fetch web content
agent-cli-tool 'Summarize: @fetch("https://example.com/article")'

Pipe Input

echo "explain this error" | agent-cli-tool
cat error.log | agent-cli-tool "what went wrong?"

Command Line Options

usage: agent-cli-tool [-h] [-m MODEL] [-a] [-iu] [-ia] [-it] [-c] [-sh] [-co] [-o OUTPUT] [-u {stdout,rich,tui}] [prompt]

positional arguments:
  prompt                 User input prompt

options:
  -h, --help             Show help message
  -m, --model MODEL      AI model to use
  -a, --ahead            Place arg prompt before pipe prompt (default: true)
  -iu, --ignore_user     Don't display user input
  -ia, --ignore_ai       Don't display AI model info
  -it, --ignore_think    Don't display AI thinking/reasoning content
  -c, --conversation     Enable multi-turn conversation mode
  -sh, --shell           Shell mode - output shell commands only
  -co, --code            Code mode - output code only
  -o, --output OUTPUT    Write output to file
  -u, --ui-mode {stdout,rich,tui}
                         UI rendering mode

TUI Mode

The TUI mode provides a full interactive terminal interface:

Keyboard Shortcuts

Key Action
Ctrl+D Send input
Ctrl+L Clear input
Ctrl+E Toggle history panel
Ctrl+T New session
Ctrl+B Toggle markdown/raw rendering
Ctrl+G Edit config
Ctrl+C Stop streaming (double-press to exit)
Delete Delete selected history/session
ESC Close modal dialogs

Features

  • Session management with automatic title generation
  • History browsing and search
  • Config editing modal
  • Persistent chat history stored in ~/.config/agent-cli-tool/history/

Development

Project Structure

src/agent_cli_tool/
โ”œโ”€โ”€ __init__.py          # Entry point
โ”œโ”€โ”€ agents/
โ”‚   โ”œโ”€โ”€ agent.py         # Central orchestration
โ”‚   โ””โ”€โ”€ ai.py            # OpenAI client wrapper
โ”œโ”€โ”€ cli/
โ”‚   โ””โ”€โ”€ cli.py           # Argument parser
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ config.py        # Configuration management
โ”œโ”€โ”€ plugins/
โ”‚   โ”œโ”€โ”€ __init__.py      # Plugin loader
โ”‚   โ”œโ”€โ”€ fetch.py         # Web content fetcher
โ”‚   โ”œโ”€โ”€ file.py          # File content injector
โ”‚   โ””โ”€โ”€ shell.py         # Shell confirmation plugin
โ””โ”€โ”€ ui/
    โ”œโ”€โ”€ base.py          # Base renderer
    โ”œโ”€โ”€ stdout.py        # Plain text renderer
    โ”œโ”€โ”€ rich.py          # Markdown renderer
    โ””โ”€โ”€ tui.py           # Interactive TUI renderer

Architecture

main() โ†’ Agent โ†’ Renderer (stdout/rich/tui) โ†’ Output
         โ†“
    CLI Args & Config
         โ†“
    Plugin System (before/after hooks)
         โ†“
    BaseAI โ†’ OpenAI API

Creating Plugins

Create a Python file in src/agent_cli_tool/plugins/:

# my_plugin.py
def before_ai_ask_hook(user_input: str, mode: str) -> str:
    """Process user input before sending to AI"""
    # Modify user_input as needed
    return user_input

def after_ai_ask_hook(ai_reply: str, mode: str) -> str:
    """Process AI response after receiving"""
    # Modify ai_reply as needed
    return ai_reply

Plugins are auto-discovered and loaded at runtime.

Dependencies

  • openai>=1.75.0 - OpenAI API client
  • python-dotenv>=1.1.0 - Configuration management
  • requests>=2.32.3 - HTTP requests
  • rich>=14.0.0 - Terminal rendering
  • textual>=6.11.0 - TUI framework
  • wcwidth>=0.2.14 - Unicode width handling

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_cli_tool-0.2.2.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_cli_tool-0.2.2-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

Details for the file agent_cli_tool-0.2.2.tar.gz.

File metadata

  • Download URL: agent_cli_tool-0.2.2.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for agent_cli_tool-0.2.2.tar.gz
Algorithm Hash digest
SHA256 1804383933f68f163079c715a674449aa8e3582311d3010bf2baa7f81750208b
MD5 c693b7b0ad8ea2373f33b3c25cde8372
BLAKE2b-256 c106c9bfe7e8493f1021819e66ebe0b929b070657aa72f6ba45764b0fdb205b0

See more details on using hashes here.

File details

Details for the file agent_cli_tool-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: agent_cli_tool-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for agent_cli_tool-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ec256249f52af83ffc9cce660d109cce953a0e25a96d27857d54c6b20c880852
MD5 6ea0e4fb389e48260491855d2634f5af
BLAKE2b-256 495dcdf398cdced47c032f332e23bf871339b3c8782e73d65d2bb3d003c67f36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page