Feature Request: Context Control for Subagents #2704

Open
opened 2026-02-16 17:36:54 -05:00 by yindo · 2 comments
Owner

Originally created by @gunnarnordqvist on GitHub (Nov 8, 2025).

Feature Request: Context Control for Subagents

Problem

Subagents currently receive full repository context even for focused tasks, which:

  • Increases token usage for small models (e.g., llama3.2:1b)
  • Degrades performance for specialised, narrow-scope tasks
  • Makes it difficult to optimise local models for specific use cases
  • Wastes resources when only a minimal prompt is needed

Use Case

When using lightweight local models (1B-7B parameters) as subagents for focused tasks like:

  • doc-reader: Extract key points from a single documentation file
  • codegen: Generate a small code snippet
  • log-analyser: Analyse a specific log file
  • editor: Refine a single paragraph

These tasks require only the prompt and perhaps a single file reference, yet the subagent receives the entire repository context including:

  • Full project structure
  • Git history
  • All configuration files
  • Build scripts
  • Documentation files

This is particularly problematic for resource-constrained local models where context window size directly impacts inference speed and quality.

Proposed Solution

Add a context configuration option in agent definitions to control what contextual information is passed to subagents:

{
  "agent": {
    "doc-reader": {
      "mode": "subagent",
      "model": "ollama/llama3.2:1b",
      "context": {
        "repo": false,           // Disable full repository context
        "files": "prompt-only",  // Only include files mentioned in the prompt
        "maxTokens": 2000,       // Maximum context tokens to pass
        "git": false,            // Exclude git history
        "config": false          // Exclude configuration files
      }
    }
  }
}

Configuration Options

  • repo (boolean, default: true): Include full repository structure
  • files (string, default: "all"): Control which files to include
    • "all": All repository files
    • "prompt-only": Only files explicitly mentioned in the prompt
    • "none": No file context
  • maxTokens (number, optional): Hard limit on context tokens
  • git (boolean, default: true): Include git history and metadata
  • config (boolean, default: true): Include configuration files

Alternative: Markdown Configuration

---
description: Reads documentation and summarises key insights
mode: subagent
model: ollama/llama3.2:1b
temperature: 0.1
context:
  repo: false
  files: prompt-only
  maxTokens: 2000
---

Extract key points, APIs, and caveats from documentation.
Provide a short summary and a Q&A with likely follow-ups.

Benefits

  1. Performance: Faster inference for small local models
  2. Cost: Reduced token usage for API-based models
  3. Quality: Less noise, more focused responses
  4. Flexibility: Different subagents can have different context requirements
  5. Resource optimisation: Better support for constrained environments

Real-World Example

Current configuration (16 subagents using llama3.2:1b):

{
  "doc-reader": {
    "mode": "subagent",
    "model": "ollama/llama3.2:1b",
    "prompt": "Extract key points, APIs, and caveats from documentation.\nProvide a short summary and a Q&A with likely follow-ups.",
    "tools": {
      "write": false,
      "edit": false,
      "bash": false
    }
  }
}

When invoked with:

@doc-reader summarise the authentication section in README.md

Current behaviour: Receives entire repository context (potentially 50,000+ tokens)
Desired behaviour: Receives only the prompt + README.md content (~2,000 tokens)

This would make local small models significantly more practical for production use.

Compatibility

This would be a backwards-compatible addition:

  • Default behaviour remains unchanged (full context)
  • Existing agents continue to work without modification
  • New context option is entirely optional

Related Work

Similar context control exists in other AI systems:

  • LangChain's context_window parameter
  • LlamaIndex's chunk_size configuration
  • Anthropic's explicit context management in Claude

Would this feature align with OpenCode's roadmap? Happy to provide additional details or contribute to implementation if helpful.

Originally created by @gunnarnordqvist on GitHub (Nov 8, 2025). # Feature Request: Context Control for Subagents ## Problem Subagents currently receive full repository context even for focused tasks, which: - Increases token usage for small models (e.g., llama3.2:1b) - Degrades performance for specialised, narrow-scope tasks - Makes it difficult to optimise local models for specific use cases - Wastes resources when only a minimal prompt is needed ## Use Case When using lightweight local models (1B-7B parameters) as subagents for focused tasks like: - **doc-reader**: Extract key points from a single documentation file - **codegen**: Generate a small code snippet - **log-analyser**: Analyse a specific log file - **editor**: Refine a single paragraph These tasks require only the prompt and perhaps a single file reference, yet the subagent receives the entire repository context including: - Full project structure - Git history - All configuration files - Build scripts - Documentation files This is particularly problematic for resource-constrained local models where context window size directly impacts inference speed and quality. ## Proposed Solution Add a `context` configuration option in agent definitions to control what contextual information is passed to subagents: ```json { "agent": { "doc-reader": { "mode": "subagent", "model": "ollama/llama3.2:1b", "context": { "repo": false, // Disable full repository context "files": "prompt-only", // Only include files mentioned in the prompt "maxTokens": 2000, // Maximum context tokens to pass "git": false, // Exclude git history "config": false // Exclude configuration files } } } } ``` ### Configuration Options - `repo` (boolean, default: `true`): Include full repository structure - `files` (string, default: `"all"`): Control which files to include - `"all"`: All repository files - `"prompt-only"`: Only files explicitly mentioned in the prompt - `"none"`: No file context - `maxTokens` (number, optional): Hard limit on context tokens - `git` (boolean, default: `true`): Include git history and metadata - `config` (boolean, default: `true`): Include configuration files ### Alternative: Markdown Configuration ```markdown --- description: Reads documentation and summarises key insights mode: subagent model: ollama/llama3.2:1b temperature: 0.1 context: repo: false files: prompt-only maxTokens: 2000 --- Extract key points, APIs, and caveats from documentation. Provide a short summary and a Q&A with likely follow-ups. ``` ## Benefits 1. **Performance**: Faster inference for small local models 2. **Cost**: Reduced token usage for API-based models 3. **Quality**: Less noise, more focused responses 4. **Flexibility**: Different subagents can have different context requirements 5. **Resource optimisation**: Better support for constrained environments ## Real-World Example Current configuration (16 subagents using llama3.2:1b): ```json { "doc-reader": { "mode": "subagent", "model": "ollama/llama3.2:1b", "prompt": "Extract key points, APIs, and caveats from documentation.\nProvide a short summary and a Q&A with likely follow-ups.", "tools": { "write": false, "edit": false, "bash": false } } } ``` When invoked with: ``` @doc-reader summarise the authentication section in README.md ``` **Current behaviour**: Receives entire repository context (potentially 50,000+ tokens) **Desired behaviour**: Receives only the prompt + README.md content (~2,000 tokens) This would make local small models significantly more practical for production use. ## Compatibility This would be a backwards-compatible addition: - Default behaviour remains unchanged (full context) - Existing agents continue to work without modification - New `context` option is entirely optional ## Related Work Similar context control exists in other AI systems: - LangChain's `context_window` parameter - LlamaIndex's `chunk_size` configuration - Anthropic's explicit context management in Claude Would this feature align with OpenCode's roadmap? Happy to provide additional details or contribute to implementation if helpful.
yindo added the discussion label 2026-02-16 17:36:54 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Nov 8, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #2588: Feature request for subagents to inherit context - addresses similar context control concerns but from the opposite direction
  • #3153: Auto compaction for subagents when they exceed context limits - addresses context management for subagents
  • #2666: Detailed telemetry for token counts and input composition - related to token usage optimization which is a core concern here

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Nov 8, 2025): This issue might be a duplicate of existing issues. Please check: - #2588: Feature request for subagents to inherit context - addresses similar context control concerns but from the opposite direction - #3153: Auto compaction for subagents when they exceed context limits - addresses context management for subagents - #2666: Detailed telemetry for token counts and input composition - related to token usage optimization which is a core concern here Feel free to ignore if none of these address your specific case.
Author
Owner

@gunnarnordqvist commented on GitHub (Nov 8, 2025):

Update: Temporary Workaround Implemented

While waiting for native context control in OpenCode, I've implemented a transparent HTTP proxy that solves this issue for small local models.

Repository: https://github.com/gunnarnordqvist/opencode-context-filter

How It Works

  • Sits between OpenCode and Ollama (port 11435 → 11434)
  • Automatically filters context for configured small models (llama3.2:1b, qwen2.5:1.5b)
  • Removes <project>, <env>, AGENTS.md, and custom instructions
  • Zero modifications to OpenCode required

Performance Results

  • Token reduction: 45,000 → 200 tokens (99%)
  • Inference speed: 8s → 1s (8× faster)
  • Time savings: ~112 seconds per cycle (16 subagents)
  • Overhead: <50ms additional latency

Installation

git clone https://github.com/gunnarnordqvist/opencode-context-filter.git
cd opencode-context-filter
./scripts/install.sh
# Update OpenCode baseURL to http://localhost:11435/v1

The proxy launches automatically with OpenCode via a wrapper script. Works with any OpenCode version, pure Python (no dependencies).

This serves as a proof-of-concept demonstrating the value of context control for small models. Would still love to see this implemented natively in OpenCode!

@gunnarnordqvist commented on GitHub (Nov 8, 2025): ## Update: Temporary Workaround Implemented While waiting for native context control in OpenCode, I've implemented a transparent HTTP proxy that solves this issue for small local models. **Repository**: https://github.com/gunnarnordqvist/opencode-context-filter ### How It Works - Sits between OpenCode and Ollama (port 11435 → 11434) - Automatically filters context for configured small models (llama3.2:1b, qwen2.5:1.5b) - Removes `<project>`, `<env>`, `AGENTS.md`, and custom instructions - Zero modifications to OpenCode required ### Performance Results - **Token reduction**: 45,000 → 200 tokens (99%) - **Inference speed**: 8s → 1s (8× faster) - **Time savings**: ~112 seconds per cycle (16 subagents) - **Overhead**: <50ms additional latency ### Installation ```bash git clone https://github.com/gunnarnordqvist/opencode-context-filter.git cd opencode-context-filter ./scripts/install.sh # Update OpenCode baseURL to http://localhost:11435/v1 ``` The proxy launches automatically with OpenCode via a wrapper script. Works with any OpenCode version, pure Python (no dependencies). This serves as a proof-of-concept demonstrating the value of context control for small models. Would still love to see this implemented natively in OpenCode!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2704