From 08cfc6a8338f8ce46e3480aa08345d9ac90949d1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 24 Sep 2026 21:54:17 +0200 Subject: [PATCH 1/2] Let the project's settings pick loop-claude's models --- bin/loop-claude | 14 ++++++++------ bin/test_loop_claude.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bin/loop-claude b/bin/loop-claude index 6aa21a50..5ec9c31a 100755 --- a/bin/loop-claude +++ b/bin/loop-claude @@ -16,8 +16,8 @@ typing anything. Before a handoff every worktree is marked trusted in ~/.claude. Each project has one session, "A ~/code/ auto-mode" (the absolute path outside ~/code), resumed while present and deleted when the chunk finishes. Its transcript is archived under $AUTO_MODE_TRANSCRIPTS (default ~/.claude/auto-mode-transcripts//) whenever the human is asked -and when the chunk finishes. JUDGE_MODEL and WORKER_MODEL override the models (default -claude-opus-5-5). A change to this file takes effect at the next round boundary. +and when the chunk finishes. JUDGE_MODEL and WORKER_MODEL override the model the project's +Claude Code settings pick. A change to this file takes effect at the next round boundary. """ import glob import json @@ -29,11 +29,9 @@ import time import uuid ARCHIVE = os.path.expanduser(os.environ.get("AUTO_MODE_TRANSCRIPTS", "~/.claude/auto-mode-transcripts")) -JUDGE_MODEL = os.environ.get("JUDGE_MODEL", "claude-opus-5-5") ROUND = "LOOP_CLAUDE_ROUND" SESSION_NAMESPACE = uuid.UUID("64fb586b-d926-4bb3-a44c-c903e86d3eec") SOURCE = open(__file__, encoding="utf-8").read() -WORKER_MODEL = os.environ.get("WORKER_MODEL", "claude-opus-5-5") JUDGE_RULES = ( "Decide whether the human must now be interrupted. ask=true when any of these appear:\n" @@ -212,6 +210,10 @@ def trust(paths): print("trusted for the handoff: " + ", ".join(granted), file=sys.stderr) +def model(variable): + return ["--model", os.environ[variable]] if os.environ.get(variable) else [] + + def worker_args(task, name, session_id, resuming): if resuming: start = ["-p", "Continue the task; the previous run stopped before it was finished.", "--resume", str(session_id)] @@ -222,7 +224,7 @@ def worker_args(task, name, session_id, resuming): "--output-format", "stream-json", "--permission-mode", "bypassPermissions", "--verbose", - "--model", WORKER_MODEL, + *model("WORKER_MODEL"), ] @@ -261,7 +263,7 @@ def judge(task, premises, transcript): args = [ "-p", "--json-schema", json.dumps(JUDGE_SCHEMA), - "--model", JUDGE_MODEL, + *model("JUDGE_MODEL"), "--no-session-persistence", "--output-format", "json", "--permission-mode", "bypassPermissions", diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 53acfc58..88d4ec5e 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -66,6 +66,16 @@ class WorkerArgs(unittest.TestCase): self.assertNotIn("--name", args) self.assertNotIn("paint the fence", args[1]) + def test_the_project_settings_pick_the_model_unless_the_environment_names_one(self): + os.environ.pop("WORKER_MODEL", None) + self.assertNotIn("--model", loop.worker_args("t", "n", SESSION_ID, resuming=False)) + os.environ["WORKER_MODEL"] = "claude-fable-5-1" + try: + args = loop.worker_args("t", "n", SESSION_ID, resuming=False) + finally: + del os.environ["WORKER_MODEL"] + self.assertEqual(args[args.index("--model") + 1], "claude-fable-5-1") + class JudgePrompt(unittest.TestCase): def test_hands_the_judge_the_tail_of_a_long_transcript(self): -- 2.52.0 From de8c3d955ea1fd5b41334b188304ea55e7045949 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 24 Sep 2026 21:55:45 +0200 Subject: [PATCH 2/2] Restore the environment after the model test --- bin/test_loop_claude.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 88d4ec5e..5d13e0b3 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -6,6 +6,7 @@ import pathlib import stat import tempfile import unittest +import unittest.mock import uuid SESSION_ID = str(getattr(uuid, "uuid7", uuid.uuid4)()) @@ -67,13 +68,11 @@ class WorkerArgs(unittest.TestCase): self.assertNotIn("paint the fence", args[1]) def test_the_project_settings_pick_the_model_unless_the_environment_names_one(self): - os.environ.pop("WORKER_MODEL", None) - self.assertNotIn("--model", loop.worker_args("t", "n", SESSION_ID, resuming=False)) - os.environ["WORKER_MODEL"] = "claude-fable-5-1" - try: + with unittest.mock.patch.dict(os.environ): + os.environ.pop("WORKER_MODEL", None) + self.assertNotIn("--model", loop.worker_args("t", "n", SESSION_ID, resuming=False)) + with unittest.mock.patch.dict(os.environ, {"WORKER_MODEL": "claude-fable-5-1"}): args = loop.worker_args("t", "n", SESSION_ID, resuming=False) - finally: - del os.environ["WORKER_MODEL"] self.assertEqual(args[args.index("--model") + 1], "claude-fable-5-1") -- 2.52.0