Skip to main content

Your favorite AI buddy right in your terminal

Project description

ShellSage

Overview

ShellSage works by understanding your terminal context and leveraging powerful language models (Claude or GPT) to provide intelligent assistance for:

  • Shell commands and scripting
  • System administration tasks
  • Git operations
  • File management
  • Process handling
  • Real-time problem solving

What sets ShellSage apart is its ability to:

  • Read your terminal context through tmux integration
  • Provide responses based on your current terminal state
  • Accept piped input for direct analysis
  • Target specific tmux panes for focused assistance

Whether you’re a seasoned sysadmin or just getting started with the command line, ShellSage acts as your intelligent terminal companion, ready to help with both simple commands and complex operations.

Installation

Install ShellSage directly from PyPI using pip:

pip install shell_sage

Prerequisites

  1. API Key Setup

    # For Claude (default)
    export ANTHROPIC_API_KEY=sk...
    
    # For OpenAI (optional)
    export OPENAI_API_KEY=sk...
    
  2. tmux Configuration

    We recommend using this optimized tmux configuration for the best ShellSage experience. Create or edit your ~/.tmux.conf:

    # Enable mouse support
    set -g mouse on
    
    # Show pane ID and time in status bar
    set -g status-right '#{pane_id} | %H:%M '
    
    # Keep terminal content visible (needed for neovim)
    set-option -g alternate-screen off
    
    # Enable vi mode for better copy/paste
    set-window-option -g mode-keys vi
    
    # Improved search and copy bindings
    bind-key / copy-mode\; send-key ?
    bind-key -T copy-mode-vi y \
      send-key -X start-of-line\; \
      send-key -X begin-selection\; \
      send-key -X end-of-line\; \
      send-key -X cursor-left\; \
      send-key -X copy-selection-and-cancel\; \
      paste-buffer
    

    Reload tmux config:

    tmux source ~/.tmux.conf
    

This configuration enables mouse support, displays pane IDs (crucial for targeting specific panes), maintains terminal content visibility, and adds vim-style keybindings for efficient navigation and text selection.

Getting Started

Basic Usage

ShellSage is designed to run within a tmux session. Here are the core commands:

# Basic usage
ssage hi ShellSage

# Pipe content to ShellSage
cat error.log | ssage explain this error

# Target a specific tmux pane
ssage --pid %3 what is happening in this pane?

# Automatically fill in the command to run
ssage --c how can I list all files including the hidden ones?

The --pid flag is particularly useful when you want to analyze content from a different pane. The pane ID is visible in your tmux status bar (configured earlier).

Using Alternative Model Providers

ShellSage supports using different LLM providers through base URL configuration. This allows you to use local models or alternative API endpoints:

# Use a local Ollama endpoint
ssage --provider openai --model llama3.2 --base_url http://localhost:11434/v1 --api_key ollama what is rsync?

# Use together.ai
ssage --provider openai --model mistralai/Mistral-7B-Instruct-v0.3 --base_url https://api.together.xyz/v1 help me with sed # make sure you've set your together API key in your shell_sage conf

This is particularly useful for:

  • Running models locally for privacy/offline use
  • Using alternative hosting providers
  • Testing different model implementations
  • Accessing specialized model deployments

You can also set these configurations permanently in your ShellSage config file (~/.config/shell_sage/shell_sage.conf). See next section for details.

Configuration

ShellSage can be customized through its configuration file located at ~/.config/shell_sage/shell_sage.conf. Here’s a complete configuration example:

[DEFAULT]
# Choose your AI model provider
provider = anthropic     # or 'openai'
model = claude-3-sonnet # or 'gpt-4o-mini' for OpenAI
base_url = # leave empty to use default openai endpoint
api_key = # leave empty to default to using your OPENAI_API_KEY env var

# Terminal history settings
history_lines = -1      # -1 for all history

# Code display preferences
code_theme = monokai    # syntax highlighting theme
code_lexer = python     # default code lexer

You can find all of the code theme and code lexer options here: https://pygments.org/styles/

Command Line Overrides

Any configuration option can be overridden via command line arguments:

# Use OpenAI instead of Claude for a single query
ssage --provider openai --model gpt-4o-mini "explain this error"

# Adjust history lines for a specific query
ssage --history-lines 50 "what commands did I just run?"

Tips & Best Practices

Effective Usage Patterns

  1. Contextual Queries

    • Keep your tmux pane IDs visible in the status bar
    • Use --pid when referencing other panes
    • Let ShellSage see your recent command history for better context
  2. Piping Best Practices

    # Pipe logs directly
    tail -f log.txt | ssage "watch for errors"
    
    # Combine commands
    git diff | ssage "review these changes"
    

Getting Help

# View all available options
ssage --help

# Submit issues or feature requests
# https://github.com/AnswerDotAI/shell_sage/issues

Contributing

ShellSage is built using nbdev. For detailed contribution guidelines, please see our CONTRIBUTING.md file.

We welcome contributions of all kinds:

  • Bug reports
  • Feature requests
  • Documentation improvements
  • Code contributions

Please visit our GitHub repository to get started.

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

shell_sage-0.0.6.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

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

shell_sage-0.0.6-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file shell_sage-0.0.6.tar.gz.

File metadata

  • Download URL: shell_sage-0.0.6.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for shell_sage-0.0.6.tar.gz
Algorithm Hash digest
SHA256 4c51820299a76bd3fbf0c1ac4434e43b32a8ee1c7f400fcae631d4b5b0c56135
MD5 5be7431f4d66e50d7ce1ec4a74833814
BLAKE2b-256 6fa4da07ebadb85c16e02faa5a176f9936912663a3d2cedc1e8d3508f4331f20

See more details on using hashes here.

File details

Details for the file shell_sage-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: shell_sage-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for shell_sage-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ac95f0c6604fa09535d92c88fa39e241b3c8200f75962a5a026ab79b84b45693
MD5 b56895020a7dbab3872b04a1e6ba77d1
BLAKE2b-256 fad40084f76943cbd5d89fceeed78870675c30c075e8d1b8993c8a9e3d1c7c7d

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