Skip to content

Latest commit

 

History

History
440 lines (335 loc) · 11.5 KB

File metadata and controls

440 lines (335 loc) · 11.5 KB

oho - OpenCode CLI

Make OpenCode a command-line tool that can be invoked and supervised by other AI

GitHub Stars License

oho is the command-line client tool for OpenCode Server, providing complete access to the OpenCode Server API.

Project Positioning

Unique Value

oho is the only command-line client implemented entirely in Bash within the OpenCode Ecosystem.

"oho is callable from Bash" represents powerful extensibility and compatibility — this is the project's unique positioning.

Design Goals

Make OpenCode more accessible for invocation and supervision by other AI:

  • 🤖 Natively callable by any AI Agent
  • 🔄 Integrated into automated workflows
  • 📦 Run in CI/CD pipelines
  • 🔗 Seamlessly combined with other shell tools

Unique Linux Capabilities

In Linux environments, oho can provide capabilities that OpenCode CLI doesn't currently support:

Feature Description
📁 Create Session in Specified Directory Start AI programming sessions in any directory
💬 Continue Sending Messages Based on Session Resume previous session context
🗑️ Destroy Session Complete lifecycle management for sessions
🔄 Session Fork and Revert Easy switching for experimental development

Interface Preview

oho CLI

Features

  • ✅ Complete API mapping and封装
  • ✅ HTTP Basic Auth authentication support
  • ✅ JSON/Text dual output mode
  • ✅ Configuration file and environment variable support
  • ✅ All session management operations
  • ✅ Message sending and management
  • ✅ File and symbol lookup
  • ✅ TUI interface control
  • ✅ MCP/LSP/Formatter status management
  • 📊 API Completion Status - View implementation coverage

Installation

Quick Install (Recommended)

# Download and run the installer
curl -sSL https://raw.githubusercontent.com/tornado404/opencode_cli/master/oho/install.sh | bash

# Or with wget
wget -qO- https://raw.githubusercontent.com/tornado404/opencode_cli/master/oho/install.sh | bash

Build from Source

Build from Source

# Clone the repository
git clone https://github.com/tornado404/opencode_cli.git
cd opencode_cli/oho

# Build
make build

# Or build Linux version
make build-linux

Dependencies

  • Go 1.21+
  • Cobra CLI framework
  • Standard library net/http

Quick Start

1. Configure Server Connection

# Using environment variables
export OPENCODE_SERVER_HOST=127.0.0.1
export OPENCODE_SERVER_PORT=4096
export OPENCODE_SERVER_PASSWORD=your-password

# Or use command-line flags
oho --host 127.0.0.1 --port 4096 --password your-password session list

2. Basic Usage

# Check server health
oho global health

# List all sessions
oho session list

# Create a new session
oho session create

# Create session in specified directory
oho session create --path /your/project

# Send a message
oho message add -s <session-id> "Hello, please help me analyze this project"

# Continue existing session
oho message add -s <session-id> "Continue the previous task"

# View message list
oho message list -s <session-id>

# Destroy session
oho session delete <session-id>

# Get configuration
oho config get

# List providers
oho provider list

Comparison with Other Ecosystem Projects

Feature oho Other Ecosystem Projects
Implementation Language Bash TypeScript/Python/Go
AI Callable ✅ Native support Requires additional adaptation
Cross-platform Linux/Mac/Windows Runtime dependent
Integration Difficulty ⭐⭐⭐⭐⭐ Extremely Low ⭐⭐⭐ Medium

Reference: Other Projects in OpenCode Ecosystem

Command Reference

Global Commands

oho global health          # Check server health status
oho global event           # Listen to global event stream (SSE)

Project Management

oho project list           # List all projects
oho project current        # Get current project
oho path                   # Get current path
oho vcs                    # Get VCS information
oho instance dispose       # Dispose current instance

Session Management

oho session list                      # List all sessions
oho session create                    # Create new session
oho session create --path /path        # Create session in specified directory
oho session status                    # Get all session statuses
oho session get <id>                  # Get session details
oho session delete <id>               # Delete session
oho session update <id> --title "New Title"  # Update session
oho session children <id>             # Get child sessions
oho session todo <id>                 # Get todo items
oho session fork <id>                 # Fork session
oho session abort <id>                # Abort session
oho session share <id>                # Share session
oho session unshare <id>              # Unshare session
oho session diff <id>                 # Get file diff
oho session summarize <id>            # Summarize session
oho session revert <id> --message <msg-id>  # Revert message
oho session unrevert <id>             # Undo revert
oho session permissions <id> <perm-id> --response allow  # Respond to permission

Message Management

oho message list -s <session>         # List messages
oho message add -s <session> "content"   # Send message
oho message get -s <session> <msg-id> # Get message details
oho message prompt-async -s <session> "content"  # Send async
oho message command -s <session> /help  # Execute command
oho message shell -s <session> --agent default "ls -la"  # Run shell

Configuration Management

oho config get                      # Get configuration
oho config set --theme dark         # Update configuration
oho config providers                # List providers and default models

Provider Management

oho provider list                   # List all providers
oho provider auth                   # Get authentication methods
oho provider oauth authorize <id>   # OAuth authorize
oho provider oauth callback <id>    # Handle callback

File Operations

oho file list [path]                # List files
oho file content <path>             # Read file content
oho file status                     # Get file status

Find Features

oho find text "pattern"             # Search text
oho find file "query"               # Find files
oho find symbol "query"             # Find symbols

Other Commands

oho agent list                      # List agents
oho command list                    # List commands
oho tool ids                        # List tool IDs
oho tool list --provider xxx --model xxx  # List tools
oho lsp status                      # LSP status
oho formatter status                # Formatter status
oho mcp list                        # List MCP servers
oho mcp add <name> --config '{}'    # Add MCP server
oho tui open-help                   # Open help
oho tui show-toast --message "message"  # Show toast
oho auth set <provider> --credentials key=value  # Set authentication

Output Format

Use -j or --json flags for JSON output:

oho session list -j
oho config get --json

Configuration File

Configuration file is located at ~/.config/oho/config.json:

{
  "host": "127.0.0.1",
  "port": 4096,
  "username": "opencode",
  "password": "",
  "json": false
}

Environment Variables

Variable Description Default
OPENCODE_SERVER_HOST Server host 127.0.0.1
OPENCODE_SERVER_PORT Server port 4096
OPENCODE_SERVER_USERNAME Username opencode
OPENCODE_SERVER_PASSWORD Password empty

Development

# Run
go run ./cmd/oho --help

# Test
go test ./...

# Format
go fmt ./...

# Clean
make clean

Project Structure

oho/
├── cmd/
│   └── oho/
│       ├── main.go           # Entry file
│       ├── root.go           # Root command
│       ├── cmd/              # Subcommands
│       │   ├── global/
│       │   ├── project/
│       │   ├── session/
│       │   ├── message/
│       │   ├── configcmd/
│       │   ├── provider/
│       │   ├── file/
│       │   ├── find/
│       │   ├── tool/
│       │   ├── agent/
│       │   ├── command/
│       │   ├── lsp/
│       │   ├── formatter/
│       │   ├── mcp/
│       │   ├── tui/
│       │   └── auth/
│       └── internal/
│           ├── client/       # HTTP client
│           ├── config/       # Configuration management
│           ├── types/        # Type definitions
│           └── util/         # Utility functions
├── Makefile

MCP Server

oho can be used as an MCP (Model Context Protocol) server, allowing external MCP clients (like Claude Desktop, Cursor, etc.) to call OpenCode API through MCP protocol.

Start MCP Server

# Start the MCP server (stdio mode)
oho mcpserver

The MCP server uses stdio transport, which is the standard mode for local MCP clients.

Available MCP Tools

The following tools are available via MCP:

Tool Description
session_list List all sessions
session_create Create a new session
session_get Get session details
session_delete Delete a session
session_status Get all session statuses
message_list List messages in a session
message_add Send a message to a session
config_get Get OpenCode configuration
project_list List all projects
project_current Get current project
provider_list List AI providers
file_list List files in a directory
file_content Read file content
find_text Search text in project
find_file Find files by name
global_health Check server health

MCP Client Configuration

Claude Desktop (macOS/Windows)

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "oho": {
      "command": "oho",
      "args": ["mcpserver"],
      "env": {
        "OPENCODE_SERVER_HOST": "127.0.0.1",
        "OPENCODE_SERVER_PORT": "4096",
        "OPENCODE_SERVER_PASSWORD": "your-password"
      }
    }
  }
}

Cursor

Add to Cursor settings (JSON mode):

{
  "mcpServers": {
    "oho": {
      "command": "oho",
      "args": ["mcpserver"],
      "env": {
        "OPENCODE_SERVER_HOST": "127.0.0.1",
        "OPENCODE_SERVER_PORT": "4096",
        "OPENCODE_SERVER_PASSWORD": "your-password"
      }
    }
  }
}

VS Code (with Copilot Free)

VS Code doesn't have native MCP support. Use the MCP VS Code extension:

{
  "mcpServers": {
    "oho": {
      "command": "oho",
      "args": ["mcpserver"]
    }
  }
}

License

└── README.md


## License

GPL v3 License - See project root [LICENSE](../LICENSE)

## References

- [OpenCode Official Documentation](https://opencode.ai/docs/)
- [OpenCode Ecosystem](https://opencode.ai/docs/ecosystem/)
- [OpenCode GitHub](https://github.com/anomalyco/opencode)

## Contributing

Issues and Pull Requests are welcome!