Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(mcp): skip settings.local.json for the output limit when only project settings load

AdityaUmale7ec3ed68ee66
diff --git a/server/drivers/claude-bot-settings.ts b/server/drivers/claude-bot-settings.ts
index 011e33e8ea..3af2ead16b 100644
--- a/server/drivers/claude-bot-settings.ts
+++ b/server/drivers/claude-bot-settings.ts
@@ -53,10 +53,11 @@ function readJson(path: string): unknown {
}
}
-/** An env value the turn's own folder sets in the settings Claude Code reads there itself (project, then local), or undefined. */
-export function folderSettingsEnv(cwd: string, name: string): string | undefined {
+/** An env value the turn's own folder sets in the settings Claude Code reads there itself (project, then local unless the
+ * launch loads project settings only), or undefined. */
+export function folderSettingsEnv(cwd: string, name: string, projectOnly = false): string | undefined {
let found: string | undefined;
- for (const file of ["settings.json", "settings.local.json"]) {
+ for (const file of projectOnly ? ["settings.json"] : ["settings.json", "settings.local.json"]) {
const parsed = readJson(join(cwd, ".claude", file));
const value = isObject(parsed) && isObject(parsed.env) ? parsed.env[name] : undefined;
if (typeof value === "string") found = value;
diff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.ts
index 06919c4067..a2a6d25095 100644
--- a/server/drivers/claude.test.ts
+++ b/server/drivers/claude.test.ts
@@ -1719,6 +1719,21 @@ describe("ClaudeDriver turns (fake CLI)", () => {
expect(JSON.parse(readFileSync(dump, "utf8")).env.MAX_MCP_OUTPUT_TOKENS).toBeUndefined();
});
+ it("skips the folder's settings.local.json limit when the launch loads project settings only", async () => {
+ const dump = join(scratch, "bot-settings-local-mcp-limit.json");
+ process.env.FAKE_CLAUDE_DUMP = dump;
+ await create();
+ const { bot, file } = botFolders("local-mcp-limit", {});
+ writeFileSync(join(bot, ".claude", "settings.local.json"), JSON.stringify({ env: { MAX_MCP_OUTPUT_TOKENS: "40000" } }));
+ await instance.adapter.sendTurn({ threadId: "t-bot-settings-local-mcp-limit", text: "hi", cwd: bot, botSettingsFile: file,
+ integrations: { custom: { docs: { type: "http", url: "https://docs.example/mcp", headers: {} } } } });
+ await recorder.until((e) => e.type === "turn.completed");
+ const seen = JSON.parse(readFileSync(dump, "utf8"));
+ // --setting-sources project leaves settings.local.json out, so its limit never reaches the CLI.
+ expect(seen.argv[seen.argv.indexOf("--setting-sources") + 1]).toBe("project");
+ expect(seen.env.MAX_MCP_OUTPUT_TOKENS).toBe(String(UNGATED_MCP_OUTPUT_TOKENS));
+ });
+
it("is left to Claude Code when the turn runs in the folder that holds it", async () => {
const dump = join(scratch, "bot-settings-own-folder.json");
process.env.FAKE_CLAUDE_DUMP = dump;
diff --git a/server/drivers/claude.ts b/server/drivers/claude.ts
index 28a96455ca..35786bd2d8 100644
--- a/server/drivers/claude.ts
+++ b/server/drivers/claude.ts
@@ -1043,7 +1043,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
}
const replaysUserMessages = turnCliVersion === null || versionAtLeast(turnCliVersion, CLAUDE_REPLAY_FLOOR);
if (replaysUserMessages) args.push("--replay-user-messages");
- const isolated = !inheritsUserConfig(turnEnvironment);
+ const isolated = !inheritsUserConfig(turnEnvironment); const projectSettingsOnly = isolated && claudeCliSupports(turnCliVersion, "--setting-sources");
const disallowed = [...(config.disallowedTools ?? []), ...unusableBuiltIns({ isolated, listsTools: config.tools !== undefined, guest: Boolean(turn.guestConfined) }), ...claudeDisabledNativeSkillRules(botId)];
if (disallowed.length) args.push("--disallowedTools", disallowed.join(","));
if (turn.toolScope !== undefined && (!isolated || turn.mcpFromUserConfig || turnCliVersion === null || !claudeCliSupports(turnCliVersion, "--strict-mcp-config"))) {
@@ -1052,7 +1052,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
if (isolated) {
// Without these every turn gets this machine's MCP servers, connectors, skills, hooks and CLAUDE.md (one desktop: 407 tools, ~10k tokens).
if (!turn.mcpFromUserConfig && claudeCliSupports(turnCliVersion, "--strict-mcp-config")) args.push("--strict-mcp-config");
- if (claudeCliSupports(turnCliVersion, "--setting-sources")) args.push("--setting-sources", "project");
+ if (projectSettingsOnly) args.push("--setting-sources", "project");
if (turn.userSkillsDir) args.push("--add-dir", turn.userSkillsDir);
}
const compactWindow = autoCompactWindow(turnEnvironment);
@@ -1184,7 +1184,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
// Approvals and browser credentials expire at the turn boundary; native background workers must not outlive it.
env.CLAUDE_CODE_DISABLE_BACKGROUND_TASKS = "1";
// Never for a guest: --restricted leaves project settings out, and a hook is a command. The MCP output limit comes after, so one the bot set there is kept.
- const botSettings = turn.guestConfined ? {} : botSettingsFor(turn.botSettingsFile, cwd, env); limitUngatedOutput(env, mcpServers, botOwned, turn.integrations?.customResultBudgets, (botSettings.env as Record<string, unknown> | undefined)?.MAX_MCP_OUTPUT_TOKENS ?? (turn.guestConfined ? undefined : folderSettingsEnv(cwd, "MAX_MCP_OUTPUT_TOKENS")));
+ const botSettings = turn.guestConfined ? {} : botSettingsFor(turn.botSettingsFile, cwd, env); limitUngatedOutput(env, mcpServers, botOwned, turn.integrations?.customResultBudgets, (botSettings.env as Record<string, unknown> | undefined)?.MAX_MCP_OUTPUT_TOKENS ?? (turn.guestConfined ? undefined : folderSettingsEnv(cwd, "MAX_MCP_OUTPUT_TOKENS", projectSettingsOnly)));
const settings = withBotSettings(botSettings, own);
const authSettingsPath = mcpConfigPath && Object.keys(settings).length
? join(dirname(mcpConfigPath), "auth-settings.json") : null;