Skip to content

transportrefer/better-opencode-btw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 better-opencode-btw

The /btw command opencode deserves β€” ask side questions with rich context, zero pollution.

You're 12 tool calls deep into a complex refactor. You suddenly need to remember why a function exists, or what a config flag does, or whether you already handled an edge case. You could ask the main agent β€” but that bloats its context window, derails its focus, and costs tokens on a tangent.

That's what /btw is for.

/btw what does the `useAuth` hook actually return?
/btw remind me, why did we choose SQLite over Postgres again?
/btw how do I undo the last commit without losing changes?
/btw what's the difference between the plan and build agents?

The answer appears inline as a subtask result. Your main agent keeps working exactly where it left off β€” no context pollution, no derailment, no wasted tokens.


✨ Why this is better

🧠 better-opencode-btw πŸ“¦ dalekirkwood/opencode-btw
Context depth 4 layers: session metadata + 15 smart-truncated messages + compaction summaries + todo state + AGENTS.md Last 10 messages, blind 500-char truncation
Tool part parsing Correct SDK shape (part.type === "tool" + .state.input) Broken β€” uses "tool-invocation" which doesn't exist in the SDK
Synthetic handling Selectively includes compaction/summary synthetics Skips all synthetics β€” loses deep session context
Agent Dedicated read-only subagent, hidden from autocomplete Reuses general agent β€” can write files, shows in autocomplete
Model Specific model on agent definition β€” no surprise fallbacks Inherits parent model β€” silent fallback if provider is down
Install One-line curl | bash Manual copy only

πŸš€ Install

One-line install

curl -fsSL https://raw.githubusercontent.com/transportrefer/better-opencode-btw/main/install.sh | bash

Manual install

git clone https://github.com/transportrefer/better-opencode-btw.git /tmp/better-opencode-btw
cp /tmp/better-opencode-btw/commands/btw.md ~/.config/opencode/commands/
cp /tmp/better-opencode-btw/agents/btw.md ~/.config/opencode/agents/
cp /tmp/better-opencode-btw/plugins/btw.ts ~/.config/opencode/plugins/
cd ~/.config/opencode && npm install @opencode-ai/plugin

Restart opencode. Done.


πŸ”§ How it works

Three pieces work together:

File What it does
πŸ“‹ commands/btw.md Registers /btw as a custom command that runs as an isolated subtask
πŸ€– agents/btw.md Defines a read-only subagent (Qwen 3.6 Plus via OpenRouter)
πŸ”Œ plugins/btw.ts Hooks command.execute.before to inject rich context before the subtask runs

When you type /btw <question>, the plugin automatically gathers:

  1. πŸ“Œ Session metadata β€” title, project context
  2. πŸ’¬ Last 15 messages β€” last 5 full text, older ones smart-truncated at 300 chars
  3. πŸ“ Compaction summaries β€” synthetic continuation/summary text from session history
  4. βœ… Todo/task state β€” what's currently in-progress or pending
  5. πŸ“– AGENTS.md β€” project-specific instructions (up to 1000 chars)

All injected as a synthetic context block into the child subtask β€” never your main session. The parent agent's context window stays completely clean.

πŸ”’ Context isolation guarantee

subtask: true creates a separate child session. The parent only sees a brief result summary. Your main agent picks up exactly where it left off, as if the /btw never happened.


βš™οΈ Configuration

Change the model

Edit ~/.config/opencode/agents/btw.md:

model: openrouter/qwen/qwen3.6-plus    # default β€” fast and cheap
model: anthropic/claude-sonnet-4-20250514  # if you want quality
model: opencode/gpt-5.1-codex           # via opencode Zen

Run opencode models to see everything available.

Tune context injection

Edit ~/.config/opencode/plugins/btw.ts:

Constant Default What it controls
RECENT_LIMIT 15 How many recent messages to inject
FULL_TEXT_MESSAGES 5 How many of the newest get full (untruncated) text
OLDER_TRUNCATE 300 Character limit for older messages
AGENTS_MD_CAP 1000 Character limit for AGENTS.md injection

πŸ—‘οΈ Uninstall

rm ~/.config/opencode/commands/btw.md
rm ~/.config/opencode/agents/btw.md
rm ~/.config/opencode/plugins/btw.ts

Restart opencode.


πŸ“‹ Requirements

  • opencode v1.3.13+
  • An OpenRouter account (or change the model to one you have access to)
  • @opencode-ai/plugin (installed automatically by the install script)

πŸ“„ License

MIT

About

🧠 The /btw command for opencode β€” ask side questions with rich context injection, without polluting your main agent

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors