# 2. Synchronous Claude Session with Questions - System Design > **Priority**: 🟑 HIGH β€” Interactive UX > **Complexity**: Medium > **Effort Estimate**: 4-6 hours --- ## Overview Handles **interactive communication** between Claude and the user during eval generation. When Claude calls `AskUserQuestion`, we display it in CLI, collect the answer, and return it to Claude. --- ## Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Claude Session Manager β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Claude Agent │◀──────────────────▢│ Question β”‚ β”‚ β”‚ β”‚ SDK β”‚ AskUserQuestion β”‚ Handler β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β–Ό β”‚ β”‚ Result CLI/stdin β”‚ β”‚ (EvalSpec) (inquirer) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## Session Modes | Mode | Usage | Behavior | |------|-------|----------| | `interactive` | Local dev | Full CLI prompts via inquirer | | `non-interactive` | CI/CD | Deny questions, use defaults | | `auto-answer` | Scripted | Use provided default answers | --- ## Core Types ```typescript interface Question { header: string; question: string; options?: QuestionOption[]; multiSelect?: boolean; freeText?: boolean; defaultValue?: string; } interface SessionOptions { interactive: boolean; defaultAnswers?: Record; timeout?: number; } type SessionMode = 'interactive' | 'non-interactive' | 'auto-answer'; ``` --- ## Key Implementation ```typescript class ClaudeSession { async run(systemPrompt: string, userPrompt: string, outputSchema?: object): Promise { const agentOptions: ClaudeAgentOptions = { systemPrompt, permissionMode: this.getPermissionMode(), canUseTool: this.createToolHandler(), outputFormat: outputSchema ? { type: 'json_schema', json_schema: { name: 'Output', schema: outputSchema } } : undefined, }; for await (const msg of query(userPrompt, agentOptions)) { if (msg.type === 'result') return msg.output as T; } } private async handleAskUserQuestion(input: any) { if (this.mode === 'non-interactive') { return { behavior: 'deny', message: 'Interactive questions not allowed in CI' }; } const answers: Record = {}; for (const question of input.questions) { answers[question.question] = await promptCLI(question); } return { behavior: 'allow', updatedInput: { questions: input.questions, answers } }; } } ``` --- ## CLI Adapter (inquirer) ```typescript async function promptSelect(question: Question): Promise { const { answer } = await inquirer.prompt([{ type: 'list', name: 'answer', message: question.question, choices: question.options!.map(opt => ({ name: `${opt.label} - ${opt.description}`, value: opt.label })), }]); return answer; } ``` **User sees:** ``` β”Œβ”€ Priority ──────────────────────── β”‚ I found 47 utility functions. Which should I prioritize? ? Select an option: ❯ all - Test all 47 functions top-10 - Focus on 10 most-used critical - Only critical path functions ``` --- ## File Structure ``` src/session/ β”œβ”€β”€ index.ts # Main exports β”œβ”€β”€ types.ts # TypeScript interfaces β”œβ”€β”€ client.ts # Claude SDK wrapper β”œβ”€β”€ question-handler.ts # AskUserQuestion logic β”œβ”€β”€ cli-adapter.ts # Terminal UI (inquirer) β”œβ”€β”€ modes.ts # Mode detection └── persistence.ts # Save/resume session ``` --- ## Dependencies ```json { "@anthropic-ai/claude-agent-sdk": "^0.1.0", "inquirer": "^9.2.0" } ``` --- ## Success Criteria - [ ] Interactive mode works in terminal - [ ] Non-interactive mode works in CI - [ ] Auto-answer mode uses provided defaults - [ ] Session state can be saved and resumed - [ ] Ctrl+C exits cleanly