on 333ea6e 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

OpenAI Models

Model IDNameContext Window
gpt-4.1GPT 4.11,047,576 tokens
gpt-4.1-miniGPT 4.1 Mini200,000 tokens
gpt-4.1-nanoGPT 4.1 Nano1,047,576 tokens
gpt-4.5-previewGPT 4.5 Preview128,000 tokens
gpt-4oGPT-4o128,000 tokens
gpt-4o-miniGPT-4o Mini128,000 tokens
o1O1200,000 tokens
o1-proO1 Pro200,000 tokens
o1-miniO1 Mini128,000 tokens
o3O3200,000 tokens
o3-miniO3 Mini200,000 tokens
o4-miniO4 Mini128,000 tokens

Anthropic Models

Model IDNameContext Window
claude-3.5-sonnetClaude 3.5 Sonnet200,000 tokens
claude-3-haikuClaude 3 Haiku200,000 tokens
claude-3.7-sonnetClaude 3.7 Sonnet200,000 tokens
claude-3.5-haikuClaude 3.5 Haiku200,000 tokens
claude-3-opusClaude 3 Opus200,000 tokens

Other Models

Model IDProviderNameContext Window
gemini-2.5GoogleGemini 2.5 Pro-
gemini-2.0-flashGoogleGemini 2.0 Flash-
qwen-qwqGroqQwen Qwq-
bedrock.claude-3.7-sonnetAWS BedrockClaude 3.7 Sonnet-

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
Ctrl+LView logs
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)
EscBlur editor and focus messages

Logs Page Shortcuts

ShortcutAction
BackspaceReturn 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 rich code intelligence features across multiple programming languages.

LSP Features

Supported LSP Features

FeatureDescription
DiagnosticsError checking and linting
CompletionsCode suggestions and autocompletion
HoverDocumentation on hover
DefinitionGo to definition
ReferencesFind all references
Document SymbolsNavigate symbols in current file
Workspace SymbolsSearch symbols across workspace
FormattingCode formatting
Code ActionsQuick fixes and refactorings

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:

Development

Prerequisites

Building from Source

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

# Build the diff script first
go run cmd/diff/main.go

# Build
go build -o opencode

# Run
./opencode

Acknowledgments

OpenCode builds upon the work of several open source projects and developers:

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.