YouTip LogoYouTip

Opencode Cli

OpenCode provides a powerful command-line interface (CLI) that not only launches the interactive TUI but also enables automation and scripting through commands.\n\nBy default, the OpenCode CLI launches the TUI, but its true power lies in its programmable invocations.\n\nThe OpenCode CLI is not just a command tool, but a programmable AI development interface.\n\nThe OpenCode CLI can be abstracted into three layers:\n\n* **Interaction Layer**: `tui / web / attach`\n* **Execution Layer**: `run / agent / mcp / github`\n* **Service Layer**: `serve / acp`\n\n> ? Essentially, it is a unified entry point for an **AI Agent + Local Development Environment + Programmable CLI + Server API**.\n\nBelow is the complete table of OpenCode CLI commands:\n\n### Basic Behavior\n\n| Command/Usage | Description | Notes |\n| --- | --- | --- |\n| `opencode` | Launch TUI by default | When no arguments are provided |\n| `opencode run "msg"` | Execute task non-interactively | Automation/Scripting |\n\n### TUI Launch Parameters\n\n| Flag | Shorthand | Description |\n| --- | --- | --- |\n| `--continue` | `-c` | Continue the last session |\n| `--session` | `-s` | Specify session ID |\n| `--fork` | β€” | Fork a session |\n| `--prompt` | β€” | Initial prompt |\n| `--model` | `-m` | Specify model |\n| `--agent` | β€” | Specify agent |\n| `--port` | β€” | Listening port |\n| `--hostname` | β€” | Host address |\n\n### Core CLI Commands\n\n| Command | Description | Key Subcommands |\n| --- | --- | --- |\n| `agent` | Manage agents | create / list |\n| `auth` | Manage authentication | login / list / logout |\n| `attach` | Connect to remote backend | β€” |\n| `github` | GitHub automation | install / run |\n| `mcp` | MCP service management | add / list / auth / debug |\n| `models` | View model list | β€” |\n| `run` | Non-interactive execution | β€” |\n| `serve` | Start API service | β€” |\n| `web` | Web UI service | β€” |\n| `session` | Session management | list |\n| `stats` | Token/Cost statistics | β€” |\n| `export` | Export session | β€” |\n| `import` | Import session | β€” |\n| `acp` | Start ACP protocol service | β€” |\n| `uninstall` | Uninstall | β€” |\n| `upgrade` | Upgrade version | β€” |\n\n### run Command Parameters\n\n| Flag | Shorthand | Description |\n| --- | --- | --- |\n| `--continue` | `-c` | Continue session |\n| `--session` | `-s` | Specify session |\n| `--fork` | β€” | Fork |\n| `--share` | β€” | Share session |\n| `--model` | `-m` | Specify model |\n| `--agent` | β€” | Specify agent |\n| `--file` | `-f` | Attach file |\n| `--format` | β€” | Output format (json) |\n| `--title` | β€” | Session title |\n| `--attach` | β€” | Connect to existing service |\n| `--port` | β€” | Local port |\n\n### Service Command Parameters\n\n#### serve / web / acp\n\n| Flag | Description |\n| --- | --- |\n| `--port` | Listening port |\n| `--hostname` | Host address |\n| `--mdns` | LAN discovery |\n| `--cors` | Allow cross-origin |\n\n### session / stats Parameters\n\n| Command | Flag | Description |\n| --- | --- | --- |\n| session | `--max-count (-n)` | Recent N entries |\n| session | `--format` | table/json |\n| stats | `--days` | Recent N days |\n| stats | `--tools` | Tool statistics |\n| stats | `--models` | Model usage |\n| stats | `--project` | Project filter |\n\n### Global Flags\n\n| Flag | Shorthand | Description |\n| --- | --- | --- |\n| `--help` | `-h` | Help |\n| `--version` | `-v` | Version |\n| `--print-logs` | β€” | Output logs |\n| `--log-level` | β€” | Log level |\n\n### Environment Variables\n\n| Variable | Type | Description |\n| --- | --- | --- |\n| `OPENCODE_AUTO_SHARE` | boolean | Auto share |\n| `OPENCODE_CONFIG` | string | Config path |\n| `OPENCODE_TUI_CONFIG` | string | TUI config |\n| `OPENCODE_DISABLE_AUTOUPDATE` | boolean | Disable updates |\n| `OPENCODE_SERVER_PASSWORD` | string | API authentication |\n| `OPENCODE_MODELS_URL` | string | Model source |\n\n### Experimental Features\n\n| Variable | Type | Description |\n| --- | --- | --- |\n| `OPENCODE_EXPERIMENTAL` | boolean | Enable all experimental features |\n| `OPENCODE_EXPERIMENTAL_LSP_TOOL` | boolean | LSP tool |\n| `OPENCODE_EXPERIMENTAL_PLAN_MODE` | boolean | Plan mode |\n| `OPENCODE_EXPERIMENTAL_FILEWATCHER` | boolean | File watcher |\n\n* * *\n\n## 1. Basic Usage\n\n### 1. Launch TUI (Default Behavior)\n\nopencode\nEquivalent to entering the interactive terminal interface\n\n!(#)\n\n### 2. Specify Project Directory\n\nopencode /path/to/project\nLaunch TUI in the specified directory, for example, launching in the opencode-tutorial-test directory:\n\nopencode opencode-tutorial-test\n!(#)\n\n### 3. Non-interactive Mode (Script Invocation)\n\nopencode run Explain the principle of closures in JavaScript\nReturns the result directly without entering the interface.\n\n* * *\n\n## 2. Core CLI Capabilities\n\nThe core capabilities of the OpenCode CLI can be summarized into three categories:\n\n* **Interactive Mode:** TUI (Default)\n* **Command Execution:** run / serve\n* **System Management:** agent / auth / session, etc.\n\n* * *\n\n## 3. Common Parameters (Flags)\n\n| Parameter | Shorthand | Description |\n| --- | --- | --- |\n| --continue | -c | Continue the last session |\n| --session | -s | Specify session ID |\n| --fork | | Fork from the current session |\n| --model | -m | Specify model (provider/model) |\n| --agent | | Specify agent |\n| --port | | Service port |\n| --hostname | | Listening address |\n\n* * *\n\n## 4. Core Command Details\n\n### 1. run (Most Commonly Used)\n\nUsed for non-interactive execution:\n\nopencode run Analyze the context usage in this Go project\n**Applicable Scenarios:**\n\n* Script automation\n* CI/CD\n* Quick Q&A\n\n### Connect to Background Service (Avoid Cold Start)\n\n# Start the background service with opencode serve # Connect using run with opencode run --attach http://localhost:4096 Explain async/await\n### Common Parameters\n\n| Parameter | Description |\n| --- | --- |\n| --model | Specify model |\n| --file | Attach file |\n| --format | Output format (json / default) |\n| --share | Share session |\n\n## 5. auth (Authentication Management)\n\n### Login\n\nopencode auth login\nConfigure API Key (stored locally)\n\n* * *\n\n### View Logged-in Providers\n\nopencode auth list\n### Logout\n\nopencode auth logout\n\n* * *\n\n## 6. models (Model Management)\n\n### View All Models\n\nopencode models\n### Filter by Provider\n\nopencode models anthropic\n### Refresh Model List\n\nopencode models --refresh\n\n* * *\n\n## 7. agent (Agent System)\n\n### Create Agent\n\nopencode agent create\nCustomizable prompts + tools\n\n### View Agents\n\nopencode agent list\n\n* * *\n\n## 8. session (Session Management)\n\n### View Sessions\n\nopencode session list\n### Limit Quantity\n\nopencode session list -n 10\n\n* * *\n\n## 9. serve (Service Mode)\n\nStart API service:\n\nopencode serve\nProvides HTTP interface (no UI)\n\n**Optional Parameters:**\n\n* --port: Port\n* --hostname: Listening address\n\n* * *\n\n## 10. web (Web UI)\n\nopencode web\nLaunch the version with a web interface\n\n* * *\n\n## 11. mcp (Extended Capabilities)\n\n### Add MCP Service\n\nopencode mcp add\n### View List\n\nopencode mcp list\nMCP is used to extend AI capabilities (such as tool calls)\n\n* * *\n\n## 12. stats (Usage Statistics)\n\nopencode stats\nView Token usage and costs\n\n* * *\n\n## 13. export / import\n\n### Export Session\n\nopencode export\n### Import Session\n\nopencode import session.json\n\n* * *\n\n## 14. Upgrade and Uninstall\n\n### Upgrade\n\nopencode upgrade\n### Uninstall\n\nopencode uninstall\n\n* * *\n\n## 15. Global Parameters\n\n| Parameter | Description |\n| --- | --- |\n| --help | View help |\n| --version | View version |\n| --log-level | Log level |\n\n* * *\n\n## 16.
← Opencode GithubOpencode Vscode β†’