Skip to content
Merged
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
4 changes: 4 additions & 0 deletions docs/src/content/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ These settings configure the proxy process. Claude Code client settings such as
"port": 18765,
"aliasProvider": "codex",
"autoReviewModel": "gpt-5.6-terra",
"autoReviewEffort": "medium",
"codex": {
"originator": "claude-code-proxy",
"userAgent": "claude-code-proxy/0.1.24",
Expand Down Expand Up @@ -68,6 +69,7 @@ All keys are optional. An unreadable file, malformed JSON, or incompatible field
| `CCP_CONFIG_DIR` | none | Platform config directory | Replaces the configuration and file-backed auth root. |
| `CCP_ALIAS_PROVIDER` | `aliasProvider` | `codex` | Routes recognized Anthropic-style aliases through `codex` or `kimi`. |
| `CCP_AUTO_REVIEW_MODEL` | `autoReviewModel` | `gpt-6-luna` for Codex | Routes Claude Code's non-streaming, tool-free Bash security-review classifier through a registered model. |
| `CCP_AUTO_REVIEW_EFFORT` | `autoReviewEffort` | — | Sets the Auto Mode classifier's reasoning effort to `low`, `medium`, `high`, `xhigh`, or `max`. |
| `CCP_LOG_STDERR` | `log.stderr` | `false` | Mirrors logs to stderr when present in the environment, regardless of its value. |
| `CCP_LOG_VERBOSE` | `log.verbose` | `false` | Preserves full string fields in structured logs when present, regardless of its value. |
| `CCP_TRAFFIC_LOG` | none | `false` | Enables full request captures for `1`, `true`, or `yes`. |
Expand All @@ -77,6 +79,8 @@ All keys are optional. An unreadable file, malformed JSON, or incompatible field

Auto-review routing resolves the classifier's requested model first, not the main conversation's model. Recognized Claude aliases follow Codex/Kimi session affinity or `aliasProvider`; Grok and other providers do not establish alias affinity. Codex auto-review classifier requests use `gpt-6-luna` by default. Requests routed through other providers retain their requested model. `CCP_AUTO_REVIEW_MODEL` or `autoReviewModel` selects an explicit registered model for all detected classifier requests without changing the session's provider affinity. Normal messages, streaming requests, tool-using requests, and token counting retain their requested model.

Classifier effort is independent of model selection. A valid `CCP_AUTO_REVIEW_EFFORT` takes precedence over `autoReviewEffort` in the config file. Either overrides the classifier's `output_config.effort` and, on Codex, the global `CCP_CODEX_EFFORT` or `codex.effort`. Empty or invalid values are ignored. If neither setting is valid, normal effort selection applies. Supported levels depend on the provider and model; Cursor, for example, selects effort through its model variant.

## Outbound proxies

Outbound HTTP requests and Codex WebSocket setup inherit standard proxy environment variables when each provider client is created:
Expand Down
2 changes: 2 additions & 0 deletions src/anthropic/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub struct MessagesRequest {
pub stream: bool,
#[serde(skip)]
pub bypass_provider_model_override: bool,
#[serde(skip)]
pub bypass_provider_effort_override: bool,
#[serde(flatten)]
pub extra: serde_json::Map<String, serde_json::Value>,
}
Expand Down
58 changes: 58 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct FileConfig {
pub alias_provider: Option<String>,
#[serde(rename = "autoReviewModel")]
pub auto_review_model: Option<String>,
#[serde(rename = "autoReviewEffort")]
pub auto_review_effort: Option<serde_json::Value>,
pub log: Option<FileLog>,
pub kimi: Option<KimiConfig>,
pub codex: Option<CodexConfig>,
Expand Down Expand Up @@ -325,6 +327,12 @@ pub fn config_override_summary_lines(cfg: &LoadedConfig) -> Vec<String> {
{
out.push("CCP_AUTO_REVIEW_MODEL (env)".to_string());
}
if env
.get("CCP_AUTO_REVIEW_EFFORT")
.is_some_and(|raw| valid_auto_review_effort(raw))
{
out.push("CCP_AUTO_REVIEW_EFFORT (env)".to_string());
}
if let Some(file_cfg) = file {
if let Some(bind_address) = file_cfg.bind_address {
out.push(format!("bindAddress: {bind_address}"));
Expand All @@ -341,6 +349,14 @@ pub fn config_override_summary_lines(cfg: &LoadedConfig) -> Vec<String> {
{
out.push("autoReviewModel (config)".to_string());
}
if file_cfg
.auto_review_effort
.as_ref()
.and_then(serde_json::Value::as_str)
.is_some_and(valid_auto_review_effort)
{
out.push("autoReviewEffort (config)".to_string());
}
if let Some(log) = file_cfg.log {
if let Some(v) = log.verbose {
out.push(format!("log.verbose: {v}"));
Expand Down Expand Up @@ -900,6 +916,23 @@ pub fn auto_review_model() -> Option<String> {
.filter(|model| !model.is_empty())
}

pub fn auto_review_effort() -> Option<String> {
std::env::var("CCP_AUTO_REVIEW_EFFORT")
.ok()
.filter(|raw| valid_auto_review_effort(raw))
.or_else(|| {
let value = read_file_config(&paths::config_dir())?.auto_review_effort?;
value
.as_str()
.filter(|raw| valid_auto_review_effort(raw))
.map(str::to_owned)
})
}

fn valid_auto_review_effort(effort: &str) -> bool {
matches!(effort, "low" | "medium" | "high" | "xhigh" | "max")
}

// ---------------------------------------------------------------------------
// Codex transport config
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1084,6 +1117,7 @@ mod tests {
EnvGuard::unset("CCP_CODEX_TRANSCRIPTIONS_API"),
EnvGuard::unset("CCP_CODEX_HEADER_TIMEOUT_MS"),
EnvGuard::unset("CCP_AUTO_REVIEW_MODEL"),
EnvGuard::unset("CCP_AUTO_REVIEW_EFFORT"),
EnvGuard::unset("CCP_GROK_CLIENT_VERSION"),
];
guards.push(EnvGuard::set("CCP_CONFIG_DIR", config.path()));
Expand Down Expand Up @@ -1550,6 +1584,30 @@ mod tests {
}
}

#[test]
fn auto_review_effort_reads_top_level_config_and_env_takes_precedence() {
let _guard = ENV_LOCK.lock().unwrap();
let config = tempfile::TempDir::new().unwrap();
let _env = isolated_env(&config);
let path = config.path().join("config.json");
assert_eq!(auto_review_effort(), None);

std::fs::write(&path, r#"{"autoReviewEffort":"medium"}"#).unwrap();
assert_eq!(auto_review_effort().as_deref(), Some("medium"));
for (raw, expected) in [("high", "high"), ("", "medium"), ("off", "medium")] {
let _effort_env = EnvGuard::set("CCP_AUTO_REVIEW_EFFORT", raw);
assert_eq!(auto_review_effort().as_deref(), Some(expected));
}

std::fs::write(
&path,
r#"{"autoReviewEffort":42,"autoReviewModel":"grok-4.5"}"#,
)
.unwrap();
assert_eq!(auto_review_effort(), None);
assert_eq!(auto_review_model().as_deref(), Some("grok-4.5"));
}

#[test]
fn codex_server_compaction_defaults_and_overrides() {
let _guard = ENV_LOCK.lock().unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/openai_compat/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub fn parse_request(
messages,
stream: true,
bypass_provider_model_override: false,
bypass_provider_effort_override: false,
extra,
},
requested_model,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/codex/translate/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ fn translate_request_inner(

let effort = read_effort(req)?;
let codex_effort = to_codex_effort(effort);
let mut resolved_effort = if apply_codex_config {
let mut resolved_effort = if apply_codex_config && !req.bypass_provider_effort_override {
resolve_effort(codex_effort)?
} else {
codex_effort
Expand Down
78 changes: 77 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ fn apply_auto_review_model(
Some(route)
}

fn apply_auto_review_effort(
body: &mut crate::anthropic::schema::MessagesRequest,
count_tokens: bool,
configured_effort: impl FnOnce() -> Option<String>,
) {
if count_tokens || !is_claude_auto_review_request(body) {
return;
}
let Some(effort) = configured_effort() else {
return;
};
let output_config = body.extra.entry("output_config").or_insert(Value::Null);
if output_config.is_null() {
*output_config = Value::Object(Map::new());
}
if let Some(output_config) = output_config.as_object_mut() {
output_config.insert("effort".to_string(), Value::String(effort));
body.bypass_provider_effort_override = true;
}
}

pub struct ServerConfig {
pub bind_address: String,
pub port: u16,
Expand Down Expand Up @@ -1718,6 +1739,7 @@ async fn dispatch_request(
};

body.bypass_provider_model_override = auto_review_route.is_some() && provider.name() == "codex";
apply_auto_review_effort(&mut body, count_tokens, crate::config::auto_review_effort);

if let Some(route) = auto_review_route.as_ref() {
log.info(
Expand Down Expand Up @@ -2318,7 +2340,10 @@ mod request_id_header_tests {

#[cfg(test)]
mod auto_review_tests {
use super::{apply_auto_review_model, headers_to_record, is_claude_auto_review_request};
use super::{
CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, apply_auto_review_effort, apply_auto_review_model,
headers_to_record, is_claude_auto_review_request,
};
use crate::anthropic::schema::MessagesRequest;
use crate::request_identity::{CLAUDE_AGENT_HEADER, CLAUDE_PARENT_AGENT_HEADER};
use http::{HeaderMap, HeaderValue};
Expand Down Expand Up @@ -2365,6 +2390,57 @@ mod auto_review_tests {
)));
}

#[test]
fn classifier_effort_preserves_output_format_without_a_model_override() {
let mut body = request(CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, false, json!([]));
body.model = Some("grok-4.5".to_string());
assert!(apply_auto_review_model(&mut body, false, None, "grok").is_none());
let format = json!({"type": "json_schema", "schema": {"type": "object"}});
body.extra.insert(
"output_config".to_string(),
json!({"effort": "low", "format": format}),
);
apply_auto_review_effort(&mut body, false, || Some("high".to_string()));
assert_eq!(body.model.as_deref(), Some("grok-4.5"));
assert_eq!(
body.extra["output_config"],
json!({"effort": "high", "format": format})
);
assert!(body.bypass_provider_effort_override);
}

#[test]
fn classifier_effort_does_not_change_other_requests_or_unconfigured_reviews() {
for (mut body, count_tokens) in [
(request("An ordinary request", false, json!([])), false),
(
request(CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, true, json!([])),
false,
),
(
request(
CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX,
false,
json!([{"name": "Bash"}]),
),
false,
),
(
request(CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, false, json!([])),
true,
),
] {
apply_auto_review_effort(&mut body, count_tokens, || panic!("not a review message"));
assert!(!body.extra.contains_key("output_config"));
assert!(!body.bypass_provider_effort_override);
}

let mut body = request(CLAUDE_AUTO_REVIEW_SYSTEM_PREFIX, false, json!([]));
apply_auto_review_effort(&mut body, false, || None);
assert!(!body.extra.contains_key("output_config"));
assert!(!body.bypass_provider_effort_override);
}

#[test]
fn codex_classifier_defaults_to_luna() {
let mut classifier = request(
Expand Down
23 changes: 23 additions & 0 deletions tests/codex_agent_continuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fn configure_environment(config_dir: &Path, upstream_url: &str) -> Vec<EnvGuard>
"all_proxy",
"REQUEST_METHOD",
"CCP_AUTO_REVIEW_MODEL",
"CCP_AUTO_REVIEW_EFFORT",
"CCP_CODEX_MODEL",
"CCP_CODEX_SERVICE_TIER",
"CCP_CODEX_EFFORT",
Expand Down Expand Up @@ -1441,6 +1442,17 @@ async fn malformed_identity_sandwich_is_stateless_and_preserves_main() {
async fn auto_review_with_agent_headers_is_stateless() {
let _environment_lock = env_lock();
let mut harness = TestHarness::start().await;
std::fs::write(
harness._config_dir.path().join("config.json"),
r#"{"autoReviewEffort":"medium","codex":{"effort":"high"}}"#,
)
.unwrap();
let schema = json!({
"type": "object",
"properties": {"allow": {"type": "boolean"}},
"required": ["allow"],
"additionalProperties": false
});
let case = unique("auto-review");
let session = tagged(&case, "session");
let headers = IdentityHeaders::agent(&session, &tagged(&case, "agent-a"), None);
Expand Down Expand Up @@ -1471,6 +1483,10 @@ async fn auto_review_with_agent_headers_is_stateless() {
"text": review_system
}],
"messages": [{"role": "user", "content": review}],
"output_config": {
"effort": "low",
"format": {"type": "json_schema", "name": "decision", "schema": schema}
},
"tools": []
}),
headers.clone(),
Expand Down Expand Up @@ -1502,6 +1518,13 @@ async fn auto_review_with_agent_headers_is_stateless() {
&[("developer", review_system), ("user", &review)],
);
assert_eq!(classifier.body["model"], "gpt-6-luna");
assert_eq!(classifier.body["reasoning"]["effort"], "medium");
assert_eq!(
classifier.body["text"]["format"],
json!({"type": "json_schema", "name": "decision", "schema": schema, "strict": true})
);
assert_eq!(first.body["reasoning"]["effort"], "high");
assert_eq!(second.body["reasoning"]["effort"], "high");
assert_eq!(first.socket_ordinal, 1);
assert_eq!(classifier.socket_ordinal, 2);
assert_delta_input(&second, &a_response, first.socket_ordinal, &a2);
Expand Down