Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat: add backend default agent args env vars (#1807)
Prince Pal391a4ecd0957
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.mdindex 1fdf2a4c30..9bb9fe54fd 100644--- a/CLI_AND_DAEMON.md+++ b/CLI_AND_DAEMON.md@@ -181,8 +181,10 @@ Agent-specific overrides:|----------|-------------|| `MULTICA_CLAUDE_PATH` | Custom path to the `claude` binary || `MULTICA_CLAUDE_MODEL` | Override the Claude model used |+| `MULTICA_CLAUDE_ARGS` | Default extra arguments for Claude Code runs || `MULTICA_CODEX_PATH` | Custom path to the `codex` binary || `MULTICA_CODEX_MODEL` | Override the Codex model used |+| `MULTICA_CODEX_ARGS` | Default extra arguments for Codex runs || `MULTICA_OPENCODE_PATH` | Custom path to the `opencode` binary || `MULTICA_OPENCODE_MODEL` | Override the OpenCode model used || `MULTICA_OPENCLAW_PATH` | Custom path to the `openclaw` binary |@@ -200,6 +202,8 @@ Agent-specific overrides:| `MULTICA_KIRO_PATH` | Custom path to the `kiro-cli` binary || `MULTICA_KIRO_MODEL` | Override the Kiro model used |+`MULTICA_CLAUDE_ARGS` and `MULTICA_CODEX_ARGS` are parsed with POSIX shellword quoting, so values such as `--model "gpt-5.1 codex" --sandbox read-only` are split like a shell command line. Agent arguments are applied in this order: hardcoded Multica defaults, daemon-wide env defaults, then per-agent `custom_args` from the task.+### Self-Hosted ServerWhen connecting to a self-hosted Multica instance, the easiest approach is:diff --git a/server/go.mod b/server/go.modindex 70920f7785..9b4d40d168 100644--- a/server/go.mod+++ b/server/go.mod@@ -15,6 +15,7 @@ require (github.com/gorilla/websocket v1.5.3github.com/jackc/pgx/v5 v5.8.0github.com/lmittmann/tint v1.1.3+ github.com/mattn/go-shellwords v1.0.13github.com/oklog/ulid/v2 v2.1.1github.com/prometheus/client_golang v1.23.2github.com/redis/go-redis/v9 v9.18.0diff --git a/server/go.sum b/server/go.sumindex 10247cfdd1..7cda863d39 100644--- a/server/go.sum+++ b/server/go.sum@@ -87,6 +87,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=github.com/lmittmann/tint v1.1.3 h1:Hv4EaHWXQr+GTFnOU4VKf8UvAtZgn0VuKT+G0wFlO3I=github.com/lmittmann/tint v1.1.3/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=+github.com/mattn/go-shellwords v1.0.13 h1:DC0OMEpGjm6LfNFU4ckYcvbQKyp2vE8atyFGXNtDcf4=+github.com/mattn/go-shellwords v1.0.13/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.goindex 626c2874f0..92d66e7958 100644--- a/server/internal/daemon/config.go+++ b/server/internal/daemon/config.go@@ -8,6 +8,8 @@ import ("path/filepath""strings""time"++ "github.com/mattn/go-shellwords")const (@@ -48,6 +50,8 @@ type Config struct {HeartbeatInterval time.DurationAgentTimeout time.DurationCodexSemanticInactivityTimeout time.Duration+ ClaudeArgs []string+ CodexArgs []string}// Overrides allows CLI flags to override environment variables and defaults.@@ -163,6 +167,15 @@ func LoadConfig(overrides Overrides) (Config, error) {return Config{}, fmt.Errorf("no agent CLI found: install claude, codex, copilot, opencode, openclaw, hermes, gemini, pi, cursor-agent, kimi, or kiro-cli and ensure it is on PATH")}+ claudeArgs, err := shellArgsFromEnv("MULTICA_CLAUDE_ARGS")+ if err != nil {+ return Config{}, err+ }+ codexArgs, err := shellArgsFromEnv("MULTICA_CODEX_ARGS")+ if err != nil {+ return Config{}, err+ }+// Host infohost, err := os.Hostname()if err != nil || strings.TrimSpace(host) == "" {@@ -326,6 +339,8 @@ func LoadConfig(overrides Overrides) (Config, error) {HeartbeatInterval: heartbeatInterval,AgentTimeout: agentTimeout,CodexSemanticInactivityTimeout: codexSemanticInactivityTimeout,+ ClaudeArgs: claudeArgs,+ CodexArgs: codexArgs,}, nil}@@ -352,3 +367,15 @@ func NormalizeServerBaseURL(raw string) (string, error) {u.Fragment = ""return strings.TrimRight(u.String(), "/"), nil}++func shellArgsFromEnv(name string) ([]string, error) {+ raw := strings.TrimSpace(os.Getenv(name))+ if raw == "" {+ return nil, nil+ }+ args, err := shellwords.Parse(raw)+ if err != nil {+ return nil, fmt.Errorf("invalid %s: %w", name, err)+ }+ return args, nil+}diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex 515f5a95ec..ba7a14750b 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -1191,6 +1191,7 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, taskLotaskStart := time.Now()var customArgs []string+ extraArgs := defaultArgsForProvider(d.cfg, provider)var mcpConfig json.RawMessageif task.Agent != nil {customArgs = task.Agent.CustomArgs@@ -1218,6 +1219,7 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, taskLoTimeout: d.cfg.AgentTimeout,SemanticInactivityTimeout: d.cfg.CodexSemanticInactivityTimeout,ResumeSessionID: task.PriorSessionID,+ ExtraArgs: extraArgs,CustomArgs: customArgs,McpConfig: mcpConfig,}@@ -1642,3 +1644,16 @@ func isBlockedEnvKey(key string) bool {}return false}++func defaultArgsForProvider(cfg Config, provider string) []string {+ var args []string+ switch provider {+ case "claude":+ args = cfg.ClaudeArgs+ case "codex":+ args = cfg.CodexArgs+ default:+ return nil+ }+ return append([]string(nil), args...)+}diff --git a/server/internal/daemon/daemon_test.go b/server/internal/daemon/daemon_test.goindex 33c26ce092..612cd0da87 100644--- a/server/internal/daemon/daemon_test.go+++ b/server/internal/daemon/daemon_test.go@@ -700,3 +700,39 @@ func TestEnsureRepoReadyConcurrentMissRefreshesOnce(t *testing.T) {t.Fatalf("expected exactly 1 refresh call, got %d", got)}}++func TestShellArgsFromEnv(t *testing.T) {+ t.Setenv("MULTICA_CLAUDE_ARGS", `--max-turns 60 --append-system-prompt "multi word"`)+ got, err := shellArgsFromEnv("MULTICA_CLAUDE_ARGS")+ if err != nil {+ t.Fatalf("shellArgsFromEnv: %v", err)+ }+ want := []string{"--max-turns", "60", "--append-system-prompt", "multi word"}+ if strings.Join(got, "\x00") != strings.Join(want, "\x00") {+ t.Fatalf("got %#v, want %#v", got, want)+ }+}++func TestShellArgsFromEnvEmptyIsNil(t *testing.T) {+ t.Setenv("MULTICA_CODEX_ARGS", " ")+ got, err := shellArgsFromEnv("MULTICA_CODEX_ARGS")+ if err != nil {+ t.Fatalf("shellArgsFromEnv: %v", err)+ }+ if got != nil {+ t.Fatalf("expected nil for empty env, got %#v", got)+ }+}++func TestDefaultArgsForProvider(t *testing.T) {+ cfg := Config{ClaudeArgs: []string{"--max-turns", "60"}, CodexArgs: []string{"--sandbox", "workspace-write"}}+ if got := defaultArgsForProvider(cfg, "claude"); strings.Join(got, " ") != "--max-turns 60" {+ t.Fatalf("unexpected claude args: %#v", got)+ }+ if got := defaultArgsForProvider(cfg, "codex"); strings.Join(got, " ") != "--sandbox workspace-write" {+ t.Fatalf("unexpected codex args: %#v", got)+ }+ if got := defaultArgsForProvider(cfg, "gemini"); got != nil {+ t.Fatalf("expected nil for unsupported provider, got %#v", got)+ }+}diff --git a/server/pkg/agent/agent.go b/server/pkg/agent/agent.goindex 246fe14943..3704a5235f 100644--- a/server/pkg/agent/agent.go+++ b/server/pkg/agent/agent.go@@ -29,7 +29,8 @@ type ExecOptions struct {Timeout time.DurationSemanticInactivityTimeout time.DurationResumeSessionID string // if non-empty, resume a previous agent session- CustomArgs []string // additional CLI arguments appended to the agent command+ ExtraArgs []string // daemon-wide default CLI arguments appended before CustomArgs; currently read by claude and codex backends only+ CustomArgs []string // per-agent CLI arguments appended after ExtraArgsMcpConfig json.RawMessage // if non-nil, MCP server config to pass via --mcp-config}diff --git a/server/pkg/agent/claude.go b/server/pkg/agent/claude.goindex f89c146203..11adfb40b0 100644--- a/server/pkg/agent/claude.go+++ b/server/pkg/agent/claude.go@@ -434,6 +434,7 @@ func buildClaudeArgs(opts ExecOptions, logger *slog.Logger) []string {if opts.ResumeSessionID != "" {args = append(args, "--resume", opts.ResumeSessionID)}+ args = append(args, filterCustomArgs(opts.ExtraArgs, claudeBlockedArgs, logger)...)args = append(args, filterCustomArgs(opts.CustomArgs, claudeBlockedArgs, logger)...)return args}diff --git a/server/pkg/agent/claude_test.go b/server/pkg/agent/claude_test.goindex ef1b9feb77..d740486a8c 100644--- a/server/pkg/agent/claude_test.go+++ b/server/pkg/agent/claude_test.go@@ -602,3 +602,26 @@ func mustMarshal(t *testing.T, v any) json.RawMessage {}return data}++func TestBuildClaudeArgsExtraArgsBeforeCustomArgsAndFiltersBoth(t *testing.T) {+ args := buildClaudeArgs(ExecOptions{+ ExtraArgs: []string{"--output-format", "text", "--max-budget-usd", "1.00"},+ CustomArgs: []string{"--max-budget-usd", "2.00", "--permission-mode", "plan"},+ }, slog.Default())+ joined := strings.Join(args, " ")+ if strings.Contains(joined, "--output-format text") || strings.Contains(joined, "--permission-mode plan") {+ t.Fatalf("blocked args should be filtered from both layers: %v", args)+ }+ extraIdx, customIdx := -1, -1+ for i := 0; i+1 < len(args); i++ {+ if args[i] == "--max-budget-usd" && args[i+1] == "1.00" {+ extraIdx = i+ }+ if args[i] == "--max-budget-usd" && args[i+1] == "2.00" {+ customIdx = i+ }+ }+ if extraIdx == -1 || customIdx == -1 || extraIdx > customIdx {+ t.Fatalf("expected extra args before custom args, got %v", args)+ }+}diff --git a/server/pkg/agent/codex.go b/server/pkg/agent/codex.goindex 55165b101e..13207b6909 100644--- a/server/pkg/agent/codex.go+++ b/server/pkg/agent/codex.go@@ -36,6 +36,13 @@ type codexBackend struct {cfg Config}+func buildCodexArgs(opts ExecOptions, logger *slog.Logger) []string {+ args := []string{"app-server", "--listen", "stdio://"}+ args = append(args, filterCustomArgs(opts.ExtraArgs, codexBlockedArgs, logger)...)+ args = append(args, filterCustomArgs(opts.CustomArgs, codexBlockedArgs, logger)...)+ return args+}+func (b *codexBackend) Execute(ctx context.Context, prompt string, opts ExecOptions) (*Session, error) {execPath := b.cfg.ExecutablePathif execPath == "" {@@ -55,7 +62,7 @@ func (b *codexBackend) Execute(ctx context.Context, prompt string, opts ExecOpti}runCtx, cancel := context.WithTimeout(ctx, timeout)- codexArgs := append([]string{"app-server", "--listen", "stdio://"}, filterCustomArgs(opts.CustomArgs, codexBlockedArgs, b.cfg.Logger)...)+ codexArgs := buildCodexArgs(opts, b.cfg.Logger)cmd := exec.CommandContext(runCtx, execPath, codexArgs...)hideAgentWindow(cmd)b.cfg.Logger.Info("agent command", "exec", execPath, "args", codexArgs)diff --git a/server/pkg/agent/codex_test.go b/server/pkg/agent/codex_test.goindex 9ba6a25516..9592a44db1 100644--- a/server/pkg/agent/codex_test.go+++ b/server/pkg/agent/codex_test.go@@ -1192,3 +1192,26 @@ func TestWithAgentStderrAppendsHint(t *testing.T) {t.Errorf("got %q, want %q", msg, want)}}++func TestBuildCodexArgsExtraArgsBeforeCustomArgsAndFiltersBoth(t *testing.T) {+ args := buildCodexArgs(ExecOptions{+ ExtraArgs: []string{"--listen", "tcp://evil", "--sandbox", "read-only"},+ CustomArgs: []string{"--sandbox", "workspace-write", "--listen=bad"},+ }, slog.Default())+ joined := strings.Join(args, " ")+ if strings.Contains(joined, "tcp://evil") || strings.Contains(joined, "--listen=bad") {+ t.Fatalf("blocked args should be filtered from both layers: %v", args)+ }+ extraIdx, customIdx := -1, -1+ for i := 0; i+1 < len(args); i++ {+ if args[i] == "--sandbox" && args[i+1] == "read-only" {+ extraIdx = i+ }+ if args[i] == "--sandbox" && args[i+1] == "workspace-write" {+ customIdx = i+ }+ }+ if extraIdx == -1 || customIdx == -1 || extraIdx > customIdx {+ t.Fatalf("expected extra args before custom args, got %v", args)+ }+}