Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(hetero-agent): disable Claude Code AskUserQuestion to avoid auto-decline (#14629)

Arvin Xuae8f9cfb274a
diff --git a/apps/desktop/src/main/modules/heterogeneousAgent/drivers/claudeCode.ts b/apps/desktop/src/main/modules/heterogeneousAgent/drivers/claudeCode.ts
index 7a730124312..a0a17058592 100644
--- a/apps/desktop/src/main/modules/heterogeneousAgent/drivers/claudeCode.ts
+++ b/apps/desktop/src/main/modules/heterogeneousAgent/drivers/claudeCode.ts
@@ -1,12 +1,13 @@
+import { CLAUDE_CODE_BASE_ARGS } from '@lobechat/heterogeneous-agents/spawn';
+
import type { HeterogeneousAgentBuildPlanParams, HeterogeneousAgentDriver } from '../types';
-const CLAUDE_CODE_BASE_ARGS = [
- '-p',
- '--input-format',
- 'stream-json',
- '--output-format',
- 'stream-json',
- '--verbose',
+// Desktop runs CC as the user (never root, so bypassPermissions is fine) and
+// renders the chat bubble live, so it always wants partial deltas. Compose
+// the shared invariant base args (`@lobechat/heterogeneous-agents/spawn`)
+// with those caller-specific flags.
+const DESKTOP_CLAUDE_CODE_ARGS = [
+ ...CLAUDE_CODE_BASE_ARGS,
'--include-partial-messages',
'--permission-mode',
'bypassPermissions',
@@ -24,7 +25,7 @@ export const claudeCodeDriver: HeterogeneousAgentDriver = {
return {
args: [
- ...CLAUDE_CODE_BASE_ARGS,
+ ...DESKTOP_CLAUDE_CODE_ARGS,
...(resumeSessionId ? ['--resume', resumeSessionId] : []),
...args,
],
diff --git a/packages/heterogeneous-agents/src/spawn/index.ts b/packages/heterogeneous-agents/src/spawn/index.ts
index 3b1ad4fde0d..28af4013b54 100644
--- a/packages/heterogeneous-agents/src/spawn/index.ts
+++ b/packages/heterogeneous-agents/src/spawn/index.ts
@@ -29,6 +29,11 @@ export {
type NormalizeImageOptions,
} from './input';
export { JsonlStreamProcessor } from './jsonlProcessor';
-export { spawnAgent, type SpawnAgentHandle, type SpawnAgentOptions } from './spawnAgent';
+export {
+ CLAUDE_CODE_BASE_ARGS,
+ spawnAgent,
+ type SpawnAgentHandle,
+ type SpawnAgentOptions,
+} from './spawnAgent';
export { toStreamEvent } from './streamEvent';
export type { AgentStreamEvent, AgentStreamEventType } from '@lobechat/agent-gateway-client';
diff --git a/packages/heterogeneous-agents/src/spawn/spawnAgent.test.ts b/packages/heterogeneous-agents/src/spawn/spawnAgent.test.ts
index 4640bff17ba..41833ed2de2 100644
--- a/packages/heterogeneous-agents/src/spawn/spawnAgent.test.ts
+++ b/packages/heterogeneous-agents/src/spawn/spawnAgent.test.ts
@@ -107,7 +107,14 @@ describe('spawnAgent', () => {
expect(call.args).toContain('--output-format');
expect(call.args.filter((a) => a === 'stream-json')).toHaveLength(2);
expect(call.args).toContain('-p');
- expect(call.args).toContain('--include-partial-messages');
+ // CC's built-in interactive Q&A is disabled at every spawn site so the
+ // model degrades to plain-text questioning instead of stalling on a
+ // synthetic "Answer questions?" tool_result.
+ const disallowedIdx = call.args.indexOf('--disallowedTools');
+ expect(disallowedIdx).toBeGreaterThan(-1);
+ expect(call.args[disallowedIdx + 1]).toBe('AskUserQuestion');
+ // Partial deltas are opt-in β€” terminal/sandbox callers want fewer events.
+ expect(call.args).not.toContain('--include-partial-messages');
// Prompt MUST go through stdin as a stream-json user message β€” never as argv.
expect(call.args).not.toContain('do a thing');
expect(fake.stdinWrites).toHaveLength(1);
@@ -121,6 +128,18 @@ describe('spawnAgent', () => {
for (const event of events) expect(event.operationId).toBe('op-1');
});
+ it('passes --include-partial-messages only when includePartialMessages=true', async () => {
+ nextFakeProc = createFakeProc().proc;
+ const { spawnAgent } = await import('./spawnAgent');
+ await spawnAgent({
+ agentType: 'claude-code',
+ includePartialMessages: true,
+ operationId: 'op-1',
+ prompt: 'do a thing',
+ });
+ expect(spawnCalls[0].args).toContain('--include-partial-messages');
+ });
+
it('appends --resume <id> for claude when resuming a session', async () => {
nextFakeProc = createFakeProc().proc;
const { spawnAgent } = await import('./spawnAgent');
diff --git a/packages/heterogeneous-agents/src/spawn/spawnAgent.ts b/packages/heterogeneous-agents/src/spawn/spawnAgent.ts
index c085dc41bfe..a982fc277b2 100644
--- a/packages/heterogeneous-agents/src/spawn/spawnAgent.ts
+++ b/packages/heterogeneous-agents/src/spawn/spawnAgent.ts
@@ -22,6 +22,13 @@ export interface SpawnAgentOptions {
env?: Record<string, string>;
/** Extra CLI arguments appended after the agent's preset flags. */
extraArgs?: string[];
+ /**
+ * (Claude Code only) Pass `--include-partial-messages` so the CLI streams
+ * delta chunks instead of only complete blocks. Off by default β€” terminal
+ * runs and bulk-ingest flows usually want fewer events. Turn on when a
+ * connected client renders live token streaming.
+ */
+ includePartialMessages?: boolean;
/**
* Image normalization options (URL fetch + on-disk cache + path
* materialization). Forwarded to `buildAgentInput`. When `prompt` is a
@@ -82,14 +89,28 @@ export interface SpawnAgentHandle {
stderr: NodeJS.ReadableStream;
}
-const CLAUDE_CODE_BASE_ARGS = [
+/**
+ * Invariant Claude Code CLI flags shared by every spawn site (desktop driver,
+ * `lh hetero exec`). Permission mode and `--include-partial-messages` vary by
+ * caller β€” the desktop UI wants live deltas + user-mode bypassPermissions, the
+ * sandbox CLI may run as root and skip partials β€” so they're composed on top
+ * of this base.
+ *
+ * `AskUserQuestion` is disabled because CC's CLI self-injects an
+ * `is_error: "Answer questions?"` tool_result in `-p` mode before the host
+ * can surface the questions, so the model falls back to plain-text prompting
+ * anyway. Remove this once a local MCP-backed replacement is wired to
+ * LobeHub's intervention UI.
+ */
+export const CLAUDE_CODE_BASE_ARGS = [
'-p',
'--input-format',
'stream-json',
'--output-format',
'stream-json',
'--verbose',
- '--include-partial-messages',
+ '--disallowedTools',
+ 'AskUserQuestion',
] as const;
// bypassPermissions is blocked when running as root (e.g. cloud sandbox).
@@ -109,42 +130,47 @@ const CLAUDE_CODE_PERMISSION_ARGS = (): string[] =>
const CODEX_REQUIRED_ARGS = ['--json', '--skip-git-repo-check', '--full-auto'] as const;
-const buildClaudeCodeArgs = (
- resumeSessionId: string | undefined,
- inputArgs: string[],
- extraArgs: string[],
-) => [
+interface BuildSpawnArgsParams {
+ agentType: string;
+ /** Extra CLI arguments appended after the agent's preset flags. */
+ extraArgs: string[];
+ /** (Claude Code only) Stream `--include-partial-messages` deltas. */
+ includePartialMessages: boolean;
+ /** Per-agent input args produced by `buildAgentInput` (e.g. Codex `--image`). */
+ inputArgs: string[];
+ /** Native session id for resume; undefined for fresh runs. */
+ resumeSessionId: string | undefined;
+}
+
+const buildClaudeCodeArgs = ({
+ extraArgs,
+ includePartialMessages,
+ inputArgs,
+ resumeSessionId,
+}: BuildSpawnArgsParams) => [
...CLAUDE_CODE_BASE_ARGS,
+ ...(includePartialMessages ? ['--include-partial-messages'] : []),
...CLAUDE_CODE_PERMISSION_ARGS(),
...(resumeSessionId ? ['--resume', resumeSessionId] : []),
...inputArgs,
...extraArgs,
];
-const buildCodexArgs = (
- resumeSessionId: string | undefined,
- inputArgs: string[],
- extraArgs: string[],
-) =>
+const buildCodexArgs = ({ extraArgs, inputArgs, resumeSessionId }: BuildSpawnArgsParams) =>
resumeSessionId
? ['exec', 'resume', ...CODEX_REQUIRED_ARGS, ...inputArgs, ...extraArgs, resumeSessionId, '-']
: ['exec', ...CODEX_REQUIRED_ARGS, ...inputArgs, ...extraArgs];
-const buildSpawnArgs = (
- agentType: string,
- resumeSessionId: string | undefined,
- inputArgs: string[],
- extraArgs: string[],
-): string[] => {
- switch (agentType) {
+const buildSpawnArgs = (params: BuildSpawnArgsParams): string[] => {
+ switch (params.agentType) {
case 'claude-code': {
- return buildClaudeCodeArgs(resumeSessionId, inputArgs, extraArgs);
+ return buildClaudeCodeArgs(params);
}
case 'codex': {
- return buildCodexArgs(resumeSessionId, inputArgs, extraArgs);
+ return buildCodexArgs(params);
}
default: {
- throw new Error(`spawnAgent: unsupported agent type "${agentType}"`);
+ throw new Error(`spawnAgent: unsupported agent type "${params.agentType}"`);
}
}
};
@@ -195,12 +221,13 @@ const killProcessTree = (proc: ChildProcess, signal: NodeJS.Signals): void => {
export const spawnAgent = async (options: SpawnAgentOptions): Promise<SpawnAgentHandle> => {
const command = options.command || defaultCommand(options.agentType);
const inputPlan = await buildAgentInput(options.agentType, options.prompt, options.inputOptions);
- const args = buildSpawnArgs(
- options.agentType,
- options.resumeSessionId,
- inputPlan.args,
- options.extraArgs ?? [],
- );
+ const args = buildSpawnArgs({
+ agentType: options.agentType,
+ extraArgs: options.extraArgs ?? [],
+ includePartialMessages: options.includePartialMessages ?? false,
+ inputArgs: inputPlan.args,
+ resumeSessionId: options.resumeSessionId,
+ });
const cwd = options.cwd || process.cwd();
const proc = spawn(command, args, {