OpenCode: 20 power-user tips
The TUI, custom commands, permissions and headless runs, checked against its docs.
This round was different: I didn't study a release. I studied a rewrite still in progress, on the default branch, before it ships.
The codebase
The open-source coding agent: a terminal UI, a desktop and web app, a headless server and an SDK, working with providers through its own model database. All eight lessons came from v2, the new core being built on dev next to v1, studied at commit 3884062. The org used to be sst, the team behind the SST framework; it's now anomalyco.
The eight lessons
- Admit first, run later: the
session_inputinbox, steer and queue. - Never rewrite the system prompt: Context Epochs and mid-conversation updates.
- Record once, replay forever: the
http-recorderpackage. - Bound what the model sees: the tool-output store, 2,000 lines or 50 KB.
- One API, even in-process: the embedded SDK's in-memory
fetch. - Rebuild on the main branch:
specs/v2and the schema changelog. - Configured is not allowed: policy in one
findLast. - Compact before you overflow:
session/compaction.ts.
The lessons describe v2. The tips below are for OpenCode as it ships today, checked against its docs. The leader key is Ctrl+X by default.
20 power-user tips
In the TUI
- Plan before you build. Tab switches between the Build and Plan agents. Plan asks before every file edit and shell command, so it's a safe place to explore.
- Pull in files. Type
@for a fuzzy file search; the file's content is added to the conversation. - Run a command inline. Start a message with
!, like!ls -la, and the output joins the conversation as a tool result. - Undo includes your files.
/undo(Ctrl+X U) removes the last message and reverts the file changes it made;/redobrings them back. Your project needs to be a git repo. - Learn the leader key. Ctrl+X then N new session, L sessions, M models, C compact, T themes.
- Write long prompts in your editor.
/editor(Ctrl+X E) opens$EDITOR./export(Ctrl+X X) saves the conversation as Markdown. - Change effort, not just visibility. Ctrl+T cycles model variants (reasoning effort).
/thinkingonly shows or hides the thinking blocks. - Call a subagent by name.
@general help me search for this function. Use Leader+↓ to jump into the child session it creates. - Let it write its own rules.
/initwalks you through creating or updatingAGENTS.md. - Share a session.
/sharecreates a link;/unshareremoves it.
Make it yours
- Custom commands are Markdown.
.opencode/commands/test.mdbecomes/test. Use$ARGUMENTS, or$1,$2for positional arguments. - Feed live output into a command. Inside a command file,
!`git log --oneline -10`runs and inserts the output into the prompt. - Tune permissions per tool. In
opencode.json:"permission": { "*": "ask", "bash": "allow", "edit": "deny" }. - Auto mode, with brakes.
opencode --autoapproves anything not explicitly denied. Yourdenyrules still apply.
Outside the TUI
- One-shot runs.
opencode run "Explain how closures work". Add--format jsonfor raw JSON events. - Skip the cold start. Run
opencode serveonce, thenopencode run --attach http://localhost:4096 "…"so MCP servers don't boot on every run. - Attach from anywhere.
opencode attach http://host:4096connects the TUI to a server running somewhere else. - Review a PR in one command.
opencode pr 123checks out the PR branch and starts OpenCode on it. - Summon it on GitHub.
opencode github installsets up the app and workflow; then comment/opencodeor/ocon an issue or PR and it runs in your Actions runner. - Know what it costs.
opencode stats --days 7 --modelsshows token usage and cost, with a per-model breakdown.
What's next
Three codebases, three coding agents, three very different ideas of how to build one: compare them on the lessons page. The next codebase lands on X first: follow @tarekkh1997, or subscribe via RSS.