LaercioSantana/opencode-leaner

An opencode plugin that reduces the context sent to the model — shorter tool descriptions and lean agent definitions (some of them are more like experiments)

TypeScript

2

14 commits

updated Sep 30, 2026

See the code

See what people are saying

SourceMessageScoreDate

While I was investigating why my opencode context was large I created the opencoder-leaner to try prune the context (minimal prune in the tools, agent pi-like, bash only) (r/LocalLLaMA)

I was a little obsessed about the size of my context, mainly because I use a local LLM with little context). So I started looking in the opencode codebase to understand how the context was builded. After learn a lot, I'm really impressed how context of opencode can be customized. Before, I thought…

2

Oct 5, 2026

README

opencode-leaner

opencode-leaner

An opencode plugin that reduces the context sent to the model — shorter tool descriptions and lean agent definitions (some of them are more like experiments).

Features

Trimmed tool descriptions

Opencode's builtin tool descriptions are verbose. The plugin hooks tool.definition and replaces/trim the descriptions of tools with short, minimal versions (see src/tools/*.txt)

The rules applied "the tools should have the essential to execute the tool, other instructions should be pruned from tools".

Examples:

  • "Use gh for GitHub tasks, including PRs, issues, checks, and releases; return the PR URL when done." from bash/shell tool - it should not be in the shell/bash tool description, it is too specific and out of the scope of the tool description or usage.

  • "ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required." from write tool - if need this, it should be a agents.md or custom agent prompt instruction.

  • "Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked." from write tool - if need this, it should be a agents.md or custom agent prompt instruction. This sentence overlap if other tools and system prompt too.

Tool parameters, output format, truncation caps, and permission prompts are untouched — only the description text changes.

Lean agents

The plugin hooks config and injects five agent definitions (defined in src/agents as markdown with YAML frontmatter):

AgentDescriptionToolsTokens at start [1]Notes
bashCoding assistant only with bash (similar to the mini-swe-agent)bash~1,300A experiment to let opencode agent similar to the mini-swe-agent. It only has the bash tool so the agent must read, write, find files and do all other actions from bash.
blankCoding assistant without tools and without promptnone~220Since this agent does not have any tool, it works more like a chat
minimalCoding assistant with minimal prompt but with toolsall core tools~7000Use if you want all tools like grep, subagents and skills, but dont want a 1k tokens agent prompt
codingCoding assistant with a pruned, verbose-minimized promptall core tools~8100It is the Build agent that is built in opencode, but pruned
pi-likeCoding assistant similar to pi in built tools and promptbash, edit, glob, grep, read, write, skill~5500Has a minimal set of tools, no subagents and one line agent prompt

[1] Tokens at start was calculated in a empty folder, with not project or personal AGENTS.md, and but with various skills (about ~2600 tokens in skill descriptions). Base Build agent in the same enviroment uses ~10,300 tokens.

If an agent with the same id already exists in your config, the plugin's definition is deep-merged over it (your config wins on conflict).

Set OPENCODE_LEANER_AGENT_PREFIX surpass the conflicts name, e.g. OPENCODE_LEANER_AGENT_PREFIX=lean inject lean-bash instead of bash.

Install

Npm package

Register the plugin in your opencode config (e.g. opencode.json):

{
  "plugin": ["opencode-leaner"]
}

Manual

git clone <repo-url> opencode-leaner
cd opencode-leaner
bun install

Register the plugin in your opencode config (e.g. opencode.json), pointing at the plugin entrypoint:

{
  "plugin": ["file:///absolute/path/to/opencode-leaner/index.ts"]
}

Development

# Typecheck
bunx tsc

# Run the log proxy
bun run log-proxy

There is no test suite yet; validate by loading the plugin in opencode and inspecting the debug context dump or the proxy log.

Debug context

With OPENCODE_LEANER_DEBUG_CONTEXT=1, the plugin appends the outgoing messages, system prompt, chat params, and headers for every request to a file (default: /tmp/opencode-context-debug.txt), so you can inspect offline what was actually sent to the model.

Log proxy

scripts/log-proxy.mjs is a small Bun HTTP proxy for OpenAI-compatible endpoints. It forwards requests to an upstream server and logs the (pretty-printed) request body — and optionally the response — to a file. Useful for measuring context size at the wire level.

Configuration

All options are environment variables read by the plugin (and the log proxy):

VariableDefaultDescription
OPENCODE_LEANER_AGENT_PREFIX(empty)Prefix added to injected agent ids, e.g. lean-bash
OPENCODE_LEANER_DEBUG_CONTEXT(off)Set to 1 to dump outgoing context to a file
OPENCODE_LEANER_DEBUG_CONTEXT_PATH/tmp/opencode-context-debug.txtOutput file for the debug context dump
OPENCODE_LEANER_PROXY_PORT18077Port for the log proxy
OPENCODE_LEANER_PROXY_UPSTREAMhttp://192.168.2.56:8077/v1Upstream base URL the proxy forwards to
OPENCODE_LEANER_PROXY_LOG_FILE/tmp/opencode-proxy-requests.txtLog file for the proxy
OPENCODE_LEANER_PROXY_LOG_RESPONSE(off)Set to 1 to also log response bodies

License

MIT

LaercioSantana/opencode-leaner

An opencode plugin that reduces the context sent to the model — shorter tool descriptions and lean agent definitions (some of them are more like experiments)

TypeScript

2

14 commits

updated Sep 30, 2026

See the code

See what people are saying

SourceMessageScoreDate

While I was investigating why my opencode context was large I created the opencoder-leaner to try prune the context (minimal prune in the tools, agent pi-like, bash only) (r/LocalLLaMA)

I was a little obsessed about the size of my context, mainly because I use a local LLM with little context). So I started looking in the opencode codebase to understand how the context was builded. After learn a lot, I'm really impressed how context of opencode can be customized. Before, I thought…

2

Oct 5, 2026

README

opencode-leaner

opencode-leaner

An opencode plugin that reduces the context sent to the model — shorter tool descriptions and lean agent definitions (some of them are more like experiments).

Features

Trimmed tool descriptions

Opencode's builtin tool descriptions are verbose. The plugin hooks tool.definition and replaces/trim the descriptions of tools with short, minimal versions (see src/tools/*.txt)

The rules applied "the tools should have the essential to execute the tool, other instructions should be pruned from tools".

Examples:

  • "Use gh for GitHub tasks, including PRs, issues, checks, and releases; return the PR URL when done." from bash/shell tool - it should not be in the shell/bash tool description, it is too specific and out of the scope of the tool description or usage.

  • "ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required." from write tool - if need this, it should be a agents.md or custom agent prompt instruction.

  • "Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked." from write tool - if need this, it should be a agents.md or custom agent prompt instruction. This sentence overlap if other tools and system prompt too.

Tool parameters, output format, truncation caps, and permission prompts are untouched — only the description text changes.

Lean agents

The plugin hooks config and injects five agent definitions (defined in src/agents as markdown with YAML frontmatter):

AgentDescriptionToolsTokens at start [1]Notes
bashCoding assistant only with bash (similar to the mini-swe-agent)bash~1,300A experiment to let opencode agent similar to the mini-swe-agent. It only has the bash tool so the agent must read, write, find files and do all other actions from bash.
blankCoding assistant without tools and without promptnone~220Since this agent does not have any tool, it works more like a chat
minimalCoding assistant with minimal prompt but with toolsall core tools~7000Use if you want all tools like grep, subagents and skills, but dont want a 1k tokens agent prompt
codingCoding assistant with a pruned, verbose-minimized promptall core tools~8100It is the Build agent that is built in opencode, but pruned
pi-likeCoding assistant similar to pi in built tools and promptbash, edit, glob, grep, read, write, skill~5500Has a minimal set of tools, no subagents and one line agent prompt

[1] Tokens at start was calculated in a empty folder, with not project or personal AGENTS.md, and but with various skills (about ~2600 tokens in skill descriptions). Base Build agent in the same enviroment uses ~10,300 tokens.

If an agent with the same id already exists in your config, the plugin's definition is deep-merged over it (your config wins on conflict).

Set OPENCODE_LEANER_AGENT_PREFIX surpass the conflicts name, e.g. OPENCODE_LEANER_AGENT_PREFIX=lean inject lean-bash instead of bash.

Install

Npm package

Register the plugin in your opencode config (e.g. opencode.json):

{
  "plugin": ["opencode-leaner"]
}

Manual

git clone <repo-url> opencode-leaner
cd opencode-leaner
bun install

Register the plugin in your opencode config (e.g. opencode.json), pointing at the plugin entrypoint:

{
  "plugin": ["file:///absolute/path/to/opencode-leaner/index.ts"]
}

Development

# Typecheck
bunx tsc

# Run the log proxy
bun run log-proxy

There is no test suite yet; validate by loading the plugin in opencode and inspecting the debug context dump or the proxy log.

Debug context

With OPENCODE_LEANER_DEBUG_CONTEXT=1, the plugin appends the outgoing messages, system prompt, chat params, and headers for every request to a file (default: /tmp/opencode-context-debug.txt), so you can inspect offline what was actually sent to the model.

Log proxy

scripts/log-proxy.mjs is a small Bun HTTP proxy for OpenAI-compatible endpoints. It forwards requests to an upstream server and logs the (pretty-printed) request body — and optionally the response — to a file. Useful for measuring context size at the wire level.

Configuration

All options are environment variables read by the plugin (and the log proxy):

VariableDefaultDescription
OPENCODE_LEANER_AGENT_PREFIX(empty)Prefix added to injected agent ids, e.g. lean-bash
OPENCODE_LEANER_DEBUG_CONTEXT(off)Set to 1 to dump outgoing context to a file
OPENCODE_LEANER_DEBUG_CONTEXT_PATH/tmp/opencode-context-debug.txtOutput file for the debug context dump
OPENCODE_LEANER_PROXY_PORT18077Port for the log proxy
OPENCODE_LEANER_PROXY_UPSTREAMhttp://192.168.2.56:8077/v1Upstream base URL the proxy forwards to
OPENCODE_LEANER_PROXY_LOG_FILE/tmp/opencode-proxy-requests.txtLog file for the proxy
OPENCODE_LEANER_PROXY_LOG_RESPONSE(off)Set to 1 to also log response bodies

License

MIT