Skip to content

Interface & Basic Operations

💡 One-sentence Summary: Master @ file references, ! command execution, and / slash commands, and you'll be able to harness OpenCode.

📝 Course Notes

Key knowledge points from this lesson:

Interface & Basic Operations Notes


What You'll Be Able to Do

  • Understand every area of the TUI interface
  • Use @ to reference project files
  • Use ! to execute system commands
  • Use / to call slash commands
  • Remember the most commonly used shortcuts

Your Current Challenge

  • Opened OpenCode, but don't know what each part of the interface does
  • Know you can chat with AI, but don't know how to make it read files
  • Don't know about shortcut operations, can only communicate by typing

When to Use This

  • When you need to: Efficiently use OpenCode for daily tasks
  • And you don't want to: Type long paragraphs to explain context every time

🎒 Before You Start

Make sure you've completed the following:


Core Concepts

TUI Interface Overview

After starting OpenCode, you'll see an interface like this:

┌─────────────────────────────────────────────────┐
│  OpenCode v1.0.0                    Build Mode  │  ← Status Bar/Header
├─────────────────────────────────────────────────┤
│                                                 │
│  AI: Hello! How can I help you?                 │  ← Chat Area
│                                                 │
├─────────────────────────────────────────────────┤
│  > Ask something...                             │  ← Input Area
└─────────────────────────────────────────────────┘
AreaPurpose
Status Bar/HeaderShows version, current mode (Plan/Build), Token usage
SidebarSession list (auto-shows on wide screens, hides on narrow)
Chat AreaAI responses and your message history
Input AreaWhere you type messages (different modes have different prompts)
Interface Display Rules

1. Sidebar Auto Show/Hide

  • Auto-shows session list on wide screens (>120 columns)
  • Auto-hides on narrow screens to save space

2. Input Box Smart Prompts

  • Different modes show different placeholder prompts
  • Normal mode: Ask something...
  • Shell mode: Enter shell command...
  • Comment summary mode: Summarize comments...

Core Operations Trio

SymbolPurposeExample
@Reference file@src/main.ts What does this file do
!Execute command!ls -la to view directory
/Slash command/help to view help

Follow Along

Step 1: Start OpenCode and Enter Your Project

Why
Only by starting in the project directory can AI see your code files.

bash
cd ~/your-project  # Replace with your project path
opencode

Step 2: Let AI Introduce Itself

Why
Verify that basic conversation functionality works.

In the input area, type:

Hello, please briefly introduce yourself

Press Enter to send.

You should see: AI responds with a self-introduction

Step 3: Use @ to Reference Files

Why
This is OpenCode's most powerful feature—letting AI directly read your files.

Type:

@package.json What project does this file describe

💡 Search Completion

After typing @, you'll see an Agent list (like @explore) and folders. Continue typing part of the filename (like @pack), and it will search and show matching files. Use arrow keys to select and press Enter to confirm.

You should see: AI analyzes the package.json content and responds

Step 4: Use ! to Execute Commands

Why
Lets AI see the execution results of commands.

Type:

!ls -la

You should see: The file list of the current directory appears in the chat

You can also ask AI to execute commands:

Help me see what files are in the current directory

AI will automatically call the appropriate tool to execute.

Step 5: Use / to Call Slash Commands

Why
Slash commands are the entry point for OpenCode's built-in features.

Type:

/help

You should see: A list of all available slash commands

Common slash commands overview:

CommandPurpose
/helpView help
/newNew session
/modelsSwitch model
/themesSwitch theme
/exitExit

💡 Command Palette

Press Ctrl+P to open the command palette. Ctrl+X is the Leader prefix and does not open the palette by itself.

Step 6: Learn Common Shortcuts

Why
Shortcuts make you faster.

ShortcutPurpose
TabToggle Plan/Build mode
EscInterrupt the current response or go back one level
Ctrl+CClear the input; can also exit the application
Ctrl+XLeader key (prefix key)
Ctrl+X NNew session

Step 7: Review Changes in the Diff Viewer

Enter /diff—or search for Open diff viewer in the command palette—to open the diff viewer, which is enabled by default. It organizes changes in a file tree and supports:

  • Navigating by file and hunk
  • Switching between a single patch and all patches
  • Switching between unified and split views (narrow terminals display only the unified view)
  • Viewing workspace changes and changes produced by the latest AI turn; when the current branch is not the default branch, you can also view its differences from the main branch

Common keys: ] / [ to move between hunks, n / p to move between files, d to switch sources, v to switch views, m to mark a file as reviewed, ? to open the full help, and Esc / q to close the viewer and return to the previous screen.

Source references: v1.18.22 diff viewer navigation and sources and entry command.

📦 What is a Leader Key

A Leader key is a shortcut combination method. First press Ctrl+X, release, then press another key.

For example: Ctrl+X then N = New session

This allows more shortcut combinations without conflicting with system shortcuts.


Checklist ✅

All items must pass before continuing

  • [ ] Can reference project files with @filename
  • [ ] Can execute system commands with !command
  • [ ] Can see help information with /help
  • [ ] Tab key can toggle Plan/Build mode
  • [ ] /diff opens the diff viewer and lets you switch files or hunks

Common Pitfalls

IssueCauseSolution
No file completion after @Not in project directorycd to project directory and restart
! command permission errorOpenCode blocked dangerous commandConfirm command is safe then press y to allow
Shortcuts not workingTerminal hijacked the keysCheck terminal settings or try another terminal

Lesson Summary

You learned:

  1. Three areas of the TUI interface (status bar, chat area, input area)
  2. Core operations trio (@ reference, ! execute, / command)
  3. Most commonly used shortcuts

Next Lesson Preview

Next lesson we'll learn How to Copy Content.

You'll learn:

  • Why Ctrl+C doesn't copy
  • How to copy with mouse on Win/Mac
  • How to copy AI's long code blocks