Skip to content

Commit 9848453

Browse files
idoubiclaude
andcommitted
Change default workspace to ~/.weclaw/workspace
Instead of using the current working directory (which is unpredictable in daemon mode), default to ~/.weclaw/workspace for all agents. Directory is auto-created on first use. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5f45d5b commit 9848453

5 files changed

Lines changed: 21 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Example:
192192
}
193193
```
194194

195-
Set `cwd` to specify the agent's working directory (workspace). If omitted, defaults to the current working directory.
195+
Set `cwd` to specify the agent's working directory (workspace). If omitted, defaults to `~/.weclaw/workspace`.
196196

197197
> **Warning:** These flags disable safety checks. Only enable them if you understand the risks. ACP agents handle permissions automatically and don't need these flags.
198198

README_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ curl -X POST http://127.0.0.1:18011/api/send \
194194
}
195195
```
196196

197-
通过 `cwd` 指定 Agent 的工作目录(workspace)。不设置则默认使用当前工作目录
197+
通过 `cwd` 指定 Agent 的工作目录(workspace)。不设置则默认为 `~/.weclaw/workspace`
198198

199199
> **注意:** 这些参数会跳过安全检查,请了解风险后再启用。ACP 模式的 Agent 会自动处理权限,无需配置。
200200

agent/acp_agent.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"log"
10-
"os"
1110
"os/exec"
1211
"strings"
1312
"sync"
@@ -143,11 +142,7 @@ func NewACPAgent(cfg ACPAgentConfig) *ACPAgent {
143142
cfg.Command = "claude-agent-acp"
144143
}
145144
if cfg.Cwd == "" {
146-
if wd, err := os.Getwd(); err == nil {
147-
cfg.Cwd = wd
148-
} else {
149-
cfg.Cwd = os.TempDir()
150-
}
145+
cfg.Cwd = defaultWorkspace()
151146
}
152147
return &ACPAgent{
153148
command: cfg.Command,

agent/agent.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package agent
33
import (
44
"context"
55
"fmt"
6+
"os"
7+
"path/filepath"
68
)
79

810
// AgentInfo holds metadata about an agent for logging/debugging.
@@ -23,6 +25,17 @@ func (i AgentInfo) String() string {
2325
return s
2426
}
2527

28+
// defaultWorkspace returns ~/.weclaw/workspace as the default working directory.
29+
func defaultWorkspace() string {
30+
home, err := os.UserHomeDir()
31+
if err != nil {
32+
return os.TempDir()
33+
}
34+
dir := filepath.Join(home, ".weclaw", "workspace")
35+
os.MkdirAll(dir, 0o755)
36+
return dir
37+
}
38+
2639
// Agent is the interface for AI chat agents.
2740
type Agent interface {
2841
// Chat sends a message to the agent and returns the response.

agent/cli_agent.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ type CLIAgentConfig struct {
3535

3636
// NewCLIAgent creates a new CLI agent.
3737
func NewCLIAgent(cfg CLIAgentConfig) *CLIAgent {
38+
cwd := cfg.Cwd
39+
if cwd == "" {
40+
cwd = defaultWorkspace()
41+
}
3842
return &CLIAgent{
3943
name: cfg.Name,
4044
command: cfg.Command,
4145
args: cfg.Args,
42-
cwd: cfg.Cwd,
46+
cwd: cwd,
4347
model: cfg.Model,
4448
systemPrompt: cfg.SystemPrompt,
4549
sessions: make(map[string]string),

0 commit comments

Comments
 (0)