From 29c1bde5f14083104f3f2625b8cf6c93902376f1 Mon Sep 17 00:00:00 2001 From: Daurkhan Zhussipov Date: Fri, 5 Dec 2025 13:42:54 +0500 Subject: [PATCH] fix: ensure cache directory is created and fix xdgCache path on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix xdgCache bug on macOS where it returns /home/ instead of /Users/ - Ensure cache directory is created on startup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- packages/opencode/src/global/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/global/index.ts b/packages/opencode/src/global/index.ts index 04a9093a5..a24bdd304 100644 --- a/packages/opencode/src/global/index.ts +++ b/packages/opencode/src/global/index.ts @@ -6,7 +6,15 @@ import os from "os" const app = "opencode" const data = path.join(xdgData!, app) -const cache = path.join(xdgCache!, app) +// Fix xdgCache bug on macOS where it returns /home/ instead of /Users/ +const cacheBase = (() => { + const isMacOS = os.platform() === "darwin" + if (isMacOS && xdgCache && xdgCache.startsWith("/home/")) { + return xdgCache.replace(/^\/home\/[^\/]+/, os.homedir()) + } + return xdgCache || path.join(os.homedir(), ".cache") +})() +const cache = path.join(cacheBase, app) const config = path.join(xdgConfig!, app) const state = path.join(xdgState!, app) @@ -28,6 +36,7 @@ await Promise.all([ fs.mkdir(Global.Path.state, { recursive: true }), fs.mkdir(Global.Path.log, { recursive: true }), fs.mkdir(Global.Path.bin, { recursive: true }), + fs.mkdir(Global.Path.cache, { recursive: true }), ]) const CACHE_VERSION = "13"