Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ All notable changes to SkillOpt are documented here. This project adheres to
instead of treating them as missing, and load integral floats such as
`1776.0` as `1776`, so a correct integer answer is no longer scored wrong
(thanks @Shizoqua).
- An empty `CLAUDE_SETTING_SOURCES` now reaches the Claude CLI as
`--setting-sources ""`, which loads no settings. The `claude_chat` backend
used to drop the flag for an empty value, and the CLI then loaded every
source, so the user's hooks ran and their `CLAUDE.md` loaded in every
rollout, and there was no way to ask for none. The variable is now
documented.

### Security
- Prevent managed-identity credentials from being sent to non-Azure or
Expand Down
1 change: 1 addition & 0 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Model credentials are loaded from environment variables:
| `OPENAI_COMPATIBLE_MODEL` | `openai_compatible` | Shared provider model ID for direct library use; train/eval YAML role models take precedence |
| `CLAUDE_CLI_BIN` | `claude_chat` | Optional path to the `claude` executable; defaults to `claude` |
| `ANTHROPIC_API_KEY` | `claude_chat` | Optional authentication method understood by the Claude CLI, not a direct SkillOpt API client |
| `CLAUDE_SETTING_SOURCES` | `claude_chat` | Settings sources the Claude CLI loads, a comma-separated list of `user`, `project` and `local`; defaults to `user,project`, and an empty value loads none, so no user settings, hooks or `CLAUDE.md` reach rollouts |
| `CURSOR_EXEC_PATH` | `cursor_exec` | Optional path to `cursor-agent`; defaults to `cursor-agent` |
| `CURSOR_EXEC_SANDBOX` | `cursor_exec` | Cursor sandbox mode: `enabled` (default) or `disabled` |
| `CURSOR_API_KEY` | `cursor_exec` | Optional authentication method understood directly by Cursor Agent |
Expand Down
10 changes: 7 additions & 3 deletions skillopt/model/claude_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

CLAUDE_BIN = os.environ.get("CLAUDE_CLI_BIN", "claude")
CLAUDE_PERMISSION_MODE = os.environ.get("CLAUDE_PERMISSION_MODE", "dontAsk")
CLAUDE_SETTING_SOURCES = os.environ.get("CLAUDE_SETTING_SOURCES", "user,project")
# Settings sources the CLI loads (--setting-sources). Unset means user and
# project settings; an empty value means none, so no user settings, hooks or
# CLAUDE.md reach the model.
CLAUDE_SETTING_SOURCES = os.environ.get("CLAUDE_SETTING_SOURCES", "user,project").strip()
CLAUDE_ALLOW_ATTACHMENT_READ = os.environ.get("CLAUDE_ALLOW_ATTACHMENT_READ", "1").strip().lower() not in {"0", "false", "no"}

OPTIMIZER_DEPLOYMENT = os.environ.get("OPTIMIZER_DEPLOYMENT", "claude-sonnet-4-6")
Expand Down Expand Up @@ -254,8 +257,9 @@ def _run_claude_print(*, system: str, prompt: str, model: str, tools: list[dict[
cmd = [CLAUDE_BIN, "-p", "--output-format", "json", "--permission-mode", CLAUDE_PERMISSION_MODE, "--add-dir", temp_dir]
if model:
cmd.extend(["--model", model])
if CLAUDE_SETTING_SOURCES:
cmd.extend(["--setting-sources", CLAUDE_SETTING_SOURCES])
# Always pass the flag: without it the CLI loads every source, so an
# empty value would load the most settings instead of none.
cmd.extend(["--setting-sources", CLAUDE_SETTING_SOURCES])
if system:
# Write the system prompt to a file, not argv: here the skill being
# optimized IS the system prompt, and SkillOpt grows it over training,
Expand Down
62 changes: 62 additions & 0 deletions tests/test_claude_backend_setting_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""CLAUDE_SETTING_SOURCES must be able to ask the Claude CLI for no settings at all."""
from __future__ import annotations

import importlib.util
import json
from types import SimpleNamespace

import pytest

from skillopt.model import claude_backend


def _fresh_backend(monkeypatch, value: str | None):
if value is None:
monkeypatch.delenv("CLAUDE_SETTING_SOURCES", raising=False)
else:
monkeypatch.setenv("CLAUDE_SETTING_SOURCES", value)
spec = importlib.util.spec_from_file_location("_claude_backend_fresh", claude_backend.__file__)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


def _cli_argv(monkeypatch, module) -> list[str]:
captured: dict = {}

def fake_run(cmd, **kwargs):
captured["cmd"] = list(cmd)
payload = {"type": "result", "result": "ok", "usage": {}}
return SimpleNamespace(returncode=0, stdout=json.dumps(payload) + "\n", stderr="")

monkeypatch.setattr(module.subprocess, "run", fake_run)
module._run_claude_print(
system="system",
prompt="prompt",
model="",
tools=None,
tool_choice=None,
return_message=False,
timeout=10,
)
return captured["cmd"]


@pytest.mark.parametrize(
("env_value", "expected"),
[
(None, "user,project"),
# Omitting the flag makes the CLI load every source (user, project and
# local), so an empty value must reach it as an explicit empty list.
("", ""),
(" ", ""),
("user", "user"),
],
)
def test_setting_sources_flag_follows_the_environment(monkeypatch, env_value, expected) -> None:
module = _fresh_backend(monkeypatch, env_value)

cmd = _cli_argv(monkeypatch, module)

assert cmd.count("--setting-sources") == 1
assert cmd[cmd.index("--setting-sources") + 1] == expected