Skip to main content

Overview

OpenCode is the default AI assistant in Gentleman.Dots, featuring a custom Gentleman agent configuration. It’s installed automatically with the setup script and includes a custom theme, modern CLI tools integration, and MCP support.
OpenCode is enabled by default in ~/.config/nvim/lua/plugins/disabled.lua. All other AI plugins are disabled to avoid conflicts.

Installation

OpenCode is automatically installed by the Gentleman.Dots setup script:
# Installed automatically during setup
curl -fsSL https://opencode.ai/install | bash
The configuration is located at:
~/.config/opencode/opencode.json

Neovim Configuration

The OpenCode Neovim plugin is configured in ~/.config/nvim/lua/plugins/opencode.lua:

Keybindings

Primary Commands

KeyModeDescription
<leader>aaNormalToggle OpenCode sidebar
<leader>asNormal, VisualSubmit selected code to OpenCode
<leader>aiNormal, VisualAsk OpenCode a question
<leader>aINormal, VisualAsk with current buffer context (@this:)
<leader>abNormal, VisualAsk about current file (@file)
<leader>apNormal, VisualSend custom prompt with context
KeyPromptDescription
<leader>apeexplainExplain selected code
<leader>apffixFix issues in selected code
<leader>apddiagnoseDiagnose problems
<leader>aprreviewReview code for best practices
<leader>apttestGenerate unit tests
<leader>apooptimizeOptimize performance

Window Configuration

vim.g.opencode_opts = {
  provider = {
    snacks = {
      win = {
        position = "left",  -- Sidebar on left side
      },
    },
  },
}
The autoread option is automatically enabled to detect external file changes from OpenCode operations.

OpenCode Configuration File

The main configuration is stored in ~/.config/opencode/opencode.json:
{
  "$schema": "https://opencode.ai/config.json",
  "theme": "gentleman",
  "autoupdate": true,
  "mcp": {
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "enabled": true
    }
  },
  "agent": {
    "gentleman": {
      "mode": "primary",
      "description": "Reviews code for best practices and potential issues as the Gentleman",
      "prompt": "You are a Senior Architect with 15+ years of experience...",
      "tools": {
        "write": true,
        "edit": true
      }
    }
  }
}

Configuration Options

OptionDescriptionDefault
themeOpenCode UI themegentleman
autoupdateAutomatically update OpenCode CLItrue
mcpModel Context Protocol integrationsSee below
agentCustom agent configurationsSee below
modelDefault LLM modelOpenCode default

MCP Integration

Model Context Protocol (MCP) enhances OpenCode’s ability to fetch up-to-date documentation:
{
  "mcp": {
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "enabled": true
    }
  }
}

Context7 MCP

Provides real-time access to documentation, allowing the Gentleman agent to verify claims with current information.

Gentleman Theme

The custom Gentleman theme features:
  • Dark background for comfortable long coding sessions
  • Kanagawa-inspired colors matching the Neovim theme
  • Clean typography optimized for code readability
  • Consistent visual language with the rest of the configuration
The theme is automatically applied when you run OpenCode. No additional configuration needed.

Model Configuration

You can specify a default model or per-agent model:
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-20250514",
  "agent": {
    "gentleman": {
      ...
    }
  }
}
ProviderModel IDBest For
Anthropicanthropic/claude-sonnet-4-20250514General development, reasoning
Anthropicanthropic/claude-haiku-4-20250514Fast responses, simple tasks
OpenAIopenai/gpt-4oGeneral development
OpenAIopenai/gpt-4o-miniQuick tasks, cost-effective
Googlegoogle/gemini-2.0-flashFast inference
Googlegoogle/gemini-2.5-pro-preview-06-05Advanced reasoning
The Gentleman agent works best with Claude Sonnet 4 or GPT-4o for nuanced, collaborative interactions.

Using OpenCode

1

Launch OpenCode

Open your terminal and run:
opencode
2

Activate the Gentleman Agent

Type /agent and press Enter, then select gentleman from the list.
3

Start Coding

The Gentleman agent is now active. It will:
  • Challenge your assumptions
  • Propose alternatives with tradeoffs
  • Verify claims before agreeing
  • Use modern CLI tools (bat, rg, fd, sd, eza)

Neovim Integration Workflow

1

Open OpenCode Sidebar

Press <leader>aa in Normal mode to toggle the OpenCode sidebar.
2

Select Code

Visually select code you want to discuss or modify.
3

Send to OpenCode

Use <leader>as to submit the selection, or use built-in prompts:
  • <leader>ape - Explain
  • <leader>apf - Fix
  • <leader>apr - Review
  • <leader>apt - Generate tests
4

Iterate

The Gentleman agent will respond in the sidebar. Continue the conversation or apply changes.

Advanced Usage

Context Management

" Press <leader>aI in Normal or Visual mode
" Automatically includes @this: for current buffer context

Working with Modern CLI Tools

The Gentleman agent prefers modern tools. When asking questions, it will use:
# Instead of cat
bat file.ts

# Instead of grep
rg 'pattern' --type ts

# Instead of find
fd '*.tsx' src/

# Instead of sed
sd 'old' 'new' file.ts

# Instead of ls
eza -la
If a tool is missing, the agent will attempt to install it via Homebrew. Ensure Homebrew is properly configured.

Troubleshooting

The OpenCode CLI may not be installed or not in PATH:
# Install OpenCode
curl -fsSL https://opencode.ai/install | bash

# Verify installation
which opencode

# Add to PATH if needed (add to shell config)
export PATH="$HOME/.opencode/bin:$PATH"
The agent configuration may be missing:
# Check if config exists
cat ~/.config/opencode/opencode.json

# If missing, copy from Gentleman.Dots
cp GentlemanOpenCode/opencode.json ~/.config/opencode/
Install missing tools:
brew install bat ripgrep fd sd eza

# Verify installations
bat --version
rg --version
fd --version
sd --version
eza --version

Next Steps

Gentleman Agent

Learn about the agent’s philosophy, personality, and interaction style

Switch AI Plugins

Enable a different AI assistant like Avante or CopilotChat

AI Overview

Explore all available AI integration options

Build docs developers (and LLMs) love