Settings up headroom ai with opencode A developer published a guide for integrating headroom-ai with OpenCode for context compression and proxy routing, including fixes for absolute path resolution and dynamic chunk binding. The guide warns that OpenCode's Bun module resolver does not expand the ~ symbol, requiring full absolute paths in configuration. A refined, battle-tested guide to successfully integrating headroom-ai with opencode for context compression and proxy routing, incorporating fixes for absolute path resolution and dynamic chunk binding. Ensure you have headroom installed locally and note its absolute path: which headroom Example output: /Users/username/.local/bin/headroom Navigate to your OpenCode configuration directory and install headroom-ai and the required plugin package: cd ~/.config/opencode npm install headroom-ai npm install @opencode-ai/plugin@latest Since pre-compiled chunks must match the build hash, clone the repository and build the plugin from source: rm -rf /tmp/headroom-build && mkdir -p /tmp/headroom-build cd /tmp/headroom-build git clone --filter=blob:none --sparse --depth=1 https://github.com/headroomlabs-ai/headroom.git . git sparse-checkout set plugins/opencode cd plugins/opencode npm install npm run build Create the target directory structure and move the built distribution files: PLUGIN=~/.config/opencode/plugins/headroom-opencode SRC=/tmp/headroom-build/plugins/opencode rm -rf "$PLUGIN" && mkdir -p "$PLUGIN/hook-shim" cp "$SRC/package.json" "$PLUGIN/" cp -R "$SRC/dist" "$PLUGIN/dist" cp "$SRC/hook-shim/handler.js" "$PLUGIN/hook-shim/" Create or verify a package.json in both the plugin root and the hook-shim folder to enforce ESM "type": "module" : Plugin root package.json cat "$PLUGIN/package.json" <<'EOF' { "private": true, "type": "module" } EOF Hook-shim package.json cat "$PLUGIN/hook-shim/package.json" <<'EOF' { "private": true, "type": "module" } EOF Crucial: Hardcoding a generic chunk name will break child-process interception. Use this snippet to automatically detect your build's specific hashed chunk name and write it into handler.js : CHUNK=$ ls "$PLUGIN/dist/chunk-" .js | head -1 | xargs basename cat "$PLUGIN/hook-shim/handler.js" <