Files
claude-config/bin/agent_cycle/hand_over.py
T
2026-11-18 16:21:35 +01:00

30 lines
1.1 KiB
Python

"""Opens claude on the terminal for the human."""
import dataclasses
from loop_effects.effects import Effects
from failure import Failure
from model_routing.ladder import Rung
@dataclasses.dataclass(frozen=True)
class ClaudeCommand:
"""How claude opens on a terminal: its arguments, its folder and what it adds to the environment."""
args: list[str]
cwd: str
env: dict[str, str]
def claude_args(rung: Rung, args: list[str]) -> list[str]:
return [*rung.flags(), "--permission-mode", "bypassPermissions", *args]
# CLAUDE_CODE_SANDBOXED, which Claude Code doesn't document, skips its trust dialog without writing ~/.claude.json:
# docs/decisions.md → `loop-claude: every claude it opens on a terminal has CLAUDE_CODE_SANDBOXED set`.
def hand_over(command: ClaudeCommand, effects: Effects) -> Failure | None:
"""Runs claude on the terminal as command says, with CLAUDE_CODE_SANDBOXED=1 added to its environment; the failure is why claude could not start."""
try:
effects.claude_on_terminal(command.args, command.cwd, {**command.env, "CLAUDE_CODE_SANDBOXED": "1"})
except OSError as failure:
return Failure(str(failure.strerror))
return None