diff --git a/src/agent/manager.ts b/src/agent/manager.ts index b25a26e..ca70ccd 100644 --- a/src/agent/manager.ts +++ b/src/agent/manager.ts @@ -39,6 +39,9 @@ import { /** * Result structure from Claude CLI with --output-format json + * + * When --json-schema is used, structured output is in `structured_output` field. + * The `result` field may be empty or contain the raw text. */ interface ClaudeCliResult { type: 'result'; @@ -46,6 +49,7 @@ interface ClaudeCliResult { is_error: boolean; session_id: string; result: string; + structured_output?: unknown; // Present when --json-schema is used total_cost_usd?: number; } @@ -187,7 +191,9 @@ export class ClaudeAgentManager implements AgentManager { await this.repository.updateSessionId(agentId, cliResult.session_id); } - const rawOutput = JSON.parse(cliResult.result); + // When --json-schema is used, structured output is in structured_output field + // Falls back to parsing result if structured_output is not present (backwards compatible) + const rawOutput = cliResult.structured_output ?? JSON.parse(cliResult.result); const active = this.activeAgents.get(agentId); // Parse output based on agent mode