on e1b2ce4 help sign in

Glamourous agentic coding for all ๐Ÿ’˜

git clone ssh://git.iko.soy/crush

โŒฌ OpenCode

โš ๏ธ Early Development Notice: This project is in early development and is not yet ready for production use. Features may change, break, or be incomplete. Use at your own risk.

A powerful terminal-based AI assistant for developers, providing intelligent coding assistance directly in your terminal.

Overview

OpenCode is a Go-based CLI application that brings AI assistance to your terminal. It provides a TUI (Terminal User Interface) for interacting with various AI models to help with coding tasks, debugging, and more.

Features

Installation

# Coming soon
go install github.com/kujtimiihoxha/opencode@latest

Configuration

OpenCode looks for configuration in the following locations:

Environment Variables

You can configure OpenCode using environment variables:

Environment VariablePurpose
ANTHROPIC_API_KEYFor Claude models
OPENAI_API_KEYFor OpenAI models
GEMINI_API_KEYFor Google Gemini models
GROQ_API_KEYFor Groq models
AWS_ACCESS_KEY_IDFor AWS Bedrock (Claude)
AWS_SECRET_ACCESS_KEYFor AWS Bedrock (Claude)
AWS_REGIONFor AWS Bedrock (Claude)

Configuration File Structure

{
  "data": {
    "directory": ".opencode"
  },
  "providers": {
    "openai": {
      "apiKey": "your-api-key",
      "disabled": false
    },
    "anthropic": {
      "apiKey": "your-api-key",
      "disabled": false
    }
  },
  "agents": {
    "coder": {
      "model": "claude-3.7-sonnet",
      "maxTokens": 5000
    },
    "task": {
      "model": "claude-3.7-sonnet",
      "maxTokens": 5000
    },
    "title": {
      "model": "claude-3.7-sonnet",
      "maxTokens": 80
    }
  },
  "mcpServers": {
    "example": {
      "type": "stdio",
      "command": "path/to/mcp-server",
      "env": [],
      "args": []
    }
  },
  "lsp": {
    "go": {
      "disabled": false,
      "command": "gopls"
    }
  },
  "debug": false,
  "debugLSP": false
}

Supported AI Models

OpenCode supports a variety of AI models from different providers:

OpenAI

Anthropic

Google

AWS Bedrock

Usage

# Start OpenCode
opencode

# Start with debug logging
opencode -d

# Start with a specific working directory
opencode -c /path/to/project

Command-line Flags

FlagShortDescription
--help-hDisplay help information
--debug-dEnable debug mode
--cwd-cSet current working directory

Keyboard Shortcuts

Global Shortcuts

ShortcutAction
Ctrl+CQuit application
Ctrl+?Toggle help dialog
?Toggle help dialog (when not in editing mode)
Ctrl+LView logs
Ctrl+ASwitch session
Ctrl+KCommand dialog
EscClose current overlay/dialog or return to previous mode

Chat Page Shortcuts

ShortcutAction
Ctrl+NCreate new session
Ctrl+XCancel current operation/generation
iFocus editor (when not in writing mode)
EscExit writing mode and focus messages

Editor Shortcuts

ShortcutAction
Ctrl+SSend message (when editor is focused)
Enter or Ctrl+SSend message (when editor is not focused)
Ctrl+EOpen external editor
EscBlur editor and focus messages

Session Dialog Shortcuts

ShortcutAction
โ†‘ or kPrevious session
โ†“ or jNext session
EnterSelect session
EscClose dialog

Permission Dialog Shortcuts

ShortcutAction
โ† or leftSwitch options left
โ†’ or right or tabSwitch options right
Enter or spaceConfirm selection
aAllow permission
AAllow permission for session
dDeny permission

Logs Page Shortcuts

ShortcutAction
Backspace or qReturn to chat page

AI Assistant Tools

OpenCode's AI assistant has access to various tools to help with coding tasks:

File and Code Tools

ToolDescriptionParameters
globFind files by patternpattern (required), path (optional)
grepSearch file contentspattern (required), path (optional), include (optional), literal_text (optional)
lsList directory contentspath (optional), ignore (optional array of patterns)
viewView file contentsfile_path (required), offset (optional), limit (optional)
writeWrite to filesfile_path (required), content (required)
editEdit filesVarious parameters for file editing
patchApply patches to filesfile_path (required), diff (required)
diagnosticsGet diagnostics informationfile_path (optional)

Other Tools

ToolDescriptionParameters
bashExecute shell commandscommand (required), timeout (optional)
fetchFetch data from URLsurl (required), format (required), timeout (optional)
sourcegraphSearch code across public repositoriesquery (required), count (optional), context_window (optional), timeout (optional)
agentRun sub-tasks with the AI agentprompt (required)

Architecture

OpenCode is built with a modular architecture:

MCP (Model Context Protocol)

OpenCode implements the Model Context Protocol (MCP) to extend its capabilities through external tools. MCP provides a standardized way for the AI assistant to interact with external services and tools.

MCP Features

Configuring MCP Servers

MCP servers are defined in the configuration file under the mcpServers section:

{
  "mcpServers": {
    "example": {
      "type": "stdio",
      "command": "path/to/mcp-server",
      "env": [],
      "args": []
    },
    "web-example": {
      "type": "sse",
      "url": "https://example.com/mcp",
      "headers": {
        "Authorization": "Bearer token"
      }
    }
  }
}

MCP Tool Usage

Once configured, MCP tools are automatically available to the AI assistant alongside built-in tools. They follow the same permission model as other tools, requiring user approval before execution.

LSP (Language Server Protocol)

OpenCode integrates with Language Server Protocol to provide code intelligence features across multiple programming languages.

LSP Features

Configuring LSP

Language servers are configured in the configuration file under the lsp section:

{
  "lsp": {
    "go": {
      "disabled": false,
      "command": "gopls"
    },
    "typescript": {
      "disabled": false,
      "command": "typescript-language-server",
      "args": ["--stdio"]
    }
  }
}

LSP Integration with AI

The AI assistant can access LSP features through the diagnostics tool, allowing it to:

While the LSP client implementation supports the full LSP protocol (including completions, hover, definition, etc.), currently only diagnostics are exposed to the AI assistant.

Development

Prerequisites

Building from Source

# Clone the repository
git clone https://github.com/kujtimiihoxha/opencode.git
cd opencode

# Build
go build -o opencode

# Run
./opencode

Acknowledgments

OpenCode gratefully acknowledges the contributions and support from these key individuals:

Special thanks to the broader open source community whose tools and libraries have made this project possible.

License

OpenCode is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and follow the existing code style.