feat(chat): per-chat permission modes for Claude, Codex and OpenCode

This commit is contained in:
2026-10-24 18:16:10 +01:00
parent ef575898f2
commit 6d430948a6
29 changed files with 1512 additions and 3 deletions
+11 -1
View File
@@ -44,6 +44,10 @@ type process struct {
exitErr error
done chan struct{}
stderrDone chan struct{}
// mode is the permission mode this process runs in, guarded by the
// session's mu: set at spawn and after a confirmed set_permission_mode.
mode string
}
type controlReply struct {
@@ -80,6 +84,12 @@ func (s *session) spawn(ctx context.Context) (*process, error) {
if s.model != "" {
args = append(args, "--model", s.model)
}
s.mu.Lock()
mode := s.mode
s.mu.Unlock()
if mode != "" && mode != defaultMode {
args = append(args, "--permission-mode", mode)
}
cmd := exec.CommandContext(s.chat.ctx, s.chat.binary, args...)
cmd.Dir = s.directory
cmd.Env = s.chat.auth.resolve(s.chat.ctx, s.chat.binary, withServiceToken(os.Environ()))
@@ -99,7 +109,7 @@ func (s *session) spawn(ctx context.Context) (*process, error) {
if err := cmd.Start(); err != nil {
return nil, fmt.Errorf("start Claude Code: %w", err)
}
p := &process{session: s, cmd: cmd, stdin: stdin, pending: map[string]chan controlReply{}, done: make(chan struct{}), stderrDone: make(chan struct{})}
p := &process{session: s, cmd: cmd, stdin: stdin, pending: map[string]chan controlReply{}, done: make(chan struct{}), stderrDone: make(chan struct{}), mode: mode}
go p.readStderr(stderr)
go p.readStdout(stdout)
go p.wait()