Skip to main content

Slash Commands

PraisonAI CLI provides interactive slash commands for quick actions during your AI coding sessions. Inspired by Aider and Gemini CLI, these commands give you powerful control without leaving the terminal.

Overview

Slash commands start with / and provide quick access to common operations like viewing costs, managing models, and controlling the session.
>>> /help
>>> /cost
>>> /model gpt-4o
>>> /exit

Available Commands

Core Commands

CommandAliasesDescription
/help/h, /?Show help for all commands or a specific command
/exit/quit, /qExit the interactive session
/clear/resetClear the conversation history

Session Commands

CommandAliasesDescription
/cost/usage, /statsShow token usage and cost statistics
/tokens-Show detailed token breakdown
/model/mShow or change the current model

Code Commands

CommandAliasesDescription
/diff-Show git diff of changes
/commit-Commit changes with AI-generated message
/undo-Undo the last change
/plan-Create an execution plan
CommandAliasesDescription
/map/repoShow repository map
/settings-Show current settings

Usage Examples

Getting Help

# Show all commands
>>> /help

# Get help for a specific command
>>> /help model

Managing Costs

# Show session costs
>>> /cost

# Output:
# Session: abc12345
# Duration: 300.5s
# Requests: 15
#
# Tokens:
#   Input:  12,500
#   Output: 3,200
#   Total:  15,700
#
# Cost: $0.0425

Changing Models

# Show current model
>>> /model

# Change to a different model
>>> /model gpt-4o-mini

# Change with provider prefix
>>> /model anthropic/claude-3-5-sonnet

Git Operations

# Show changes
>>> /diff

# Commit with AI message
>>> /commit

# Undo last change
>>> /undo

Python API

You can also use slash commands programmatically:
from praisonai.cli.features import SlashCommandHandler

# Create handler
handler = SlashCommandHandler()

# Check if input is a command
if handler.is_command("/help"):
    result = handler.execute("/help")
    print(result)

# Get completions for auto-complete
completions = handler.get_completions("/he")
# Returns: ["/help"]

Custom Commands

Register your own slash commands:
from praisonai.cli.features.slash_commands import (
    SlashCommand, SlashCommandHandler, CommandKind
)

# Define custom command
def my_command(args, context):
    return {"type": "custom", "message": f"Args: {args}"}

custom_cmd = SlashCommand(
    name="mycommand",
    description="My custom command",
    handler=my_command,
    kind=CommandKind.ACTION,
    aliases=["mc"]
)

# Register it
handler = SlashCommandHandler()
handler.register(custom_cmd)

# Use it
result = handler.execute("/mycommand arg1 arg2")

Command Context

Provide context for commands that need session data:
from praisonai.cli.features.slash_commands import CommandContext

# Create context with session data
context = CommandContext(
    total_tokens=5000,
    total_cost=0.015,
    prompt_count=10,
    current_model="gpt-4o",
    session_start_time=time.time() - 300
)

# Set context on handler
handler.set_context(context)

# Now /cost will show real data
result = handler.execute("/cost")

Integration with Interactive Mode

Slash commands are automatically available in interactive mode:
praisonai --interactive

>>> Hello, help me with my code
[AI responds...]

>>> /cost
Session: abc12345
Tokens: 1,500
Cost: $0.0045

>>> /model gpt-4o-mini
Model changed to: gpt-4o-mini

>>> /exit
Goodbye!

Command Reference

/help

Show help information.
/help              # Show all commands
/help <command>    # Show help for specific command

/cost

Display session cost and token statistics.
/cost              # Show full statistics

/model

Manage the AI model.
/model             # Show current model
/model <name>      # Change to specified model

/plan

Create an execution plan for a task.
/plan              # Show current plan
/plan <task>       # Create plan for task

/diff

Show git diff of current changes.
/diff              # Show all changes
/diff --staged     # Show staged changes only

/commit

Commit changes with an AI-generated message.
/commit            # Auto-generate commit message
/commit "message"  # Use custom message

Best Practices

  1. Use aliases - /h is faster than /help
  2. Check costs regularly - Use /cost to monitor spending
  3. Plan before executing - Use /plan for complex tasks
  4. Commit frequently - Use /commit after each logical change