Chunked Processing
Files over 2,000 lines are automatically processed using a map-reduce pattern: split into overlapping chunks, each analyzed independently in parallel, then results synthesized into a single coherent response.
Parameters
| Parameter | Default | Description |
CHUNK_THRESHOLD | 2,000 lines | Files above this trigger chunking |
CHUNK_SIZE | 800 lines | Lines per chunk |
CHUNK_OVERLAP | 20 lines | Overlap between adjacent chunks for context continuity |
MAX_PARALLEL_CHUNKS | 6 | Maximum concurrent chunk processing (semaphore limit) |
MAX_TOTAL_CHUNKS | 20 | Safety cap on total chunks per file |
Boundary snapping
Chunks don't cut at arbitrary line numbers. The splitter looks for natural code boundaries near the target cut point:
- Blank lines
- Function/class/method definitions (
def, class, function, func, fn, pub fn, impl, module, package)
- Closing braces (
})
- Comment lines (
//, #, /*, */)
This is language-agnostic — it works for Python, JavaScript, Go, Rust, Java, C/C++, and more.
Pipeline
- Split — file is divided into overlapping chunks with boundary snapping
- Map — each chunk is sent to OpenCode independently (stateless, no session flag) with a focused prompt containing chunk metadata (index, line range, total chunks)
- Reduce — all chunk analyses are sent to a synthesis prompt that merges them into one coherent response
Error handling
If some chunks fail, the synthesis still proceeds with available results. Failed chunks are marked in the synthesis prompt. If all chunks fail, raw error messages are returned. If synthesis fails, individual chunk analyses are concatenated as fallback.
Supported tools
Chunked processing is triggered by both opencode_discuss (when files are attached) and opencode_review (when file paths point to large files).