Skip to content

Commit 89e4892

Browse files
committed
Specify a workdir for opencode
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent c5440c4 commit 89e4892

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ An MCP server for controlling opencode AI sessions asynchronously. Start session
11871187
- `OPENCODE_AGENT` - Agent to use for sessions
11881188
- `OPENCODE_SHARE` - Share sessions: `true` or `false` (default: `false`)
11891189
- `OPENCODE_VARIANT` - Model variant for provider-specific reasoning effort
1190+
- `OPENCODE_WORKDIR` - Directory where opencode starts (default: `/root`)
11901191

11911192
**Start Session Example:**
11921193
```json

opencode/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ type Session struct {
2929

3030
// SessionManager manages all opencode sessions
3131
type SessionManager struct {
32-
sessions map[string]*Session
33-
mutex sync.RWMutex
34-
sessionDir string
35-
maxSessions int
32+
sessions map[string]*Session
33+
mutex sync.RWMutex
34+
sessionDir, workDir string
35+
maxSessions int
3636
}
3737

3838
// Global session manager
@@ -60,6 +60,7 @@ func main() {
6060
// Initialize session manager
6161
sessionDir := getEnv("OPENCODE_SESSION_DIR", "/tmp/opencode-sessions")
6262
maxSessions := getEnvInt("OPENCODE_MAX_SESSIONS", 10)
63+
workDir := getEnv("OPENCODE_WORK_DIR", "/root")
6364

6465
// Ensure session directory exists
6566
if err := os.MkdirAll(sessionDir, 0755); err != nil {
@@ -69,6 +70,7 @@ func main() {
6970
globalSessionManager = &SessionManager{
7071
sessions: make(map[string]*Session),
7172
sessionDir: sessionDir,
73+
workDir: workDir,
7274
maxSessions: maxSessions,
7375
}
7476

opencode/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (sm *SessionManager) CreateSession(message, title, sessionID string, files
9696
processmanager.WithName(opencodeBinary),
9797
processmanager.WithArgs(args...),
9898
processmanager.WithStateDir(sessionDir),
99-
processmanager.WithWorkDir(sessionDir),
99+
processmanager.WithWorkDir(sm.workDir),
100100
processmanager.WithEnvironment(os.Environ()...),
101101
)
102102

0 commit comments

Comments
 (0)