arXiv:2610.01769cs.SEOct 2026

Manuscript Offprint

arXiv:2610.01769

CONTRA: Discovering and Qualifying Behavior-Changing Questions for Selective Clarification in LLM Code Generation

Zheng Fang, Yongmin Li, Yichang Zhang, Dongming Jin, Haoyu Wang, Shuai Wang, Zhi Jin, Ge Li

ABSTRACT

Coding agents can generate code that appears correct but implements behavior the user never intended. This mismatch can arise when an agent silently resolves underspecified requirements through its own assumptions. As subsequent development builds on these assumptions, correcting the resulting behavior can become increasingly costly. Early clarification can help prevent such mismatches, but unnecessary questions can interrupt developers and slow down development. Existing methods struggle to identify key clarification questions while avoiding unnecessary ones. Therefore, we propose CONTRA, a training-free method that combines broad question discovery with semantic and execution-based question qualification. CONTRA first generates candidate questions and filters out those unrelated to required behavior or already resolved by the requirement. For each remaining question, it generates programs conditioned on two plausible answers and checks for stable behavioral differences on shared inputs. It then uses the interaction history to select among qualified questions or stop asking. Experiments on ClarifyCodeBench show that CONTRA achieves the highest F1 with all four coding agents, exceeding the best baseline macro-average F1 by 13.88 percentage points. With the same LLM and evaluation protocol, CONTRA also achieves higher clarification recall and F1 than the coding harnesses Claude Code and OpenHands. To support practical use, we also implement CONTRA as a Claude Code plugin that integrates selective clarification into everyday development. 1^{1}

1 INTRODUCTION

Coding agents are increasingly used to generate and modify code from natural-language requirements (Hong et al., 2024; Wang et al., 2025; Yang et al., 2024). However, these requirements often leave important aspects of program behavior underspecified, such as how to handle edge cases or format outputs (Fakhoury et al., 2024; Mu et al., 2024; Fang et al., 2026). Faced with such requirements, an agent may silently adopt one plausible interpretation and proceed with implementation. The resulting code may be correct under that interpretation, yet fail to match the user's intended behavior (Fakhoury et al., 2024; Vijayvargiya et al., 2026b; Edwards & Schuster, 2026). If this mismatch goes unnoticed, subsequent development may build on the same assumptions, making correction increasingly costly. Therefore, clarification helps make these assumptions explicit and resolve the underlying choices with the user before the code becomes the basis for further development.

However, excessive questioning can impose unnecessary interaction costs on developers (Zhang & Choi, 2025; Vijayvargiya et al., 2026a). For example, an agent may ask questions already answered by the requirements or earlier interactions, or raise questions unrelated to the task. This motivates selective clarification, where an agent seeks additional user input only when needed (Kuhn et al., 2022). For coding agents, this requires identifying necessary questions within a task while avoiding redundant or irrelevant ones.

*Corresponding author: Ge Li (lige@pku.edu.cn).

1^{1}Released method components and plugin: https://github.com/fangz-cs/Contra.

Our results in Table 1 illustrate this trade-off. Direct Prompting (Vijayvargiya et al., 2026b; Fang et al., 2026) and Ask-or-Assume (Edwards & Schuster, 2026) rely on the model to decide whether to ask, but often miss necessary questions. By comparison, ClarifyGPT (Mu et al., 2024) generates questions from behavioral disagreement among sampled programs, but asks many unnecessary questions. Such disagreement can reflect implementation errors even when the requirements are clear. Therefore, selective clarification requires both broad question discovery and careful qualification.

To address this challenge, we propose CONTRA, which combines broad question discovery with careful qualification. It first discovers candidate questions and checks whether each is relevant to the requirement and remains unresolved. For each remaining question, CONTRA generates programs conditioned on two plausible answers and checks for stable behavioral differences on shared inputs. During interaction, it uses the user's answers to select the next qualified question or stop asking. This design identifies key clarification questions while filtering out unnecessary ones.

We evaluate CONTRA on ClarifyCodeBench (Fang et al., 2026) with coding agents built on GPT-5-mini (OpenAI, 2025), GPT-5.5 (OpenAI, 2026), Grok 4.5 (SpaceXAI, 2026), and Gemini 3.1 Pro (Google DeepMind, 2026). Under the same five-question budget, we compare CONTRA with Direct Prompting, Ask-or-Assume (Edwards & Schuster, 2026), and ClarifyGPT (Mu et al., 2024). CONTRA achieves the highest F1 and turn-discounted key question rate (TKQR) for all four agents. Its macro-average F1 and TKQR reach 41.20% and 38.32%, exceeding the best baseline for each metric by 13.88 and 12.33 percentage points, respectively. Furthermore, using Qwen3.8-27B (Qwen Team, 2026) and the same evaluation protocol, CONTRA achieves higher recall and F1 than Claude Code (Anthropic, 2025) and OpenHands (Wang et al., 2025). Its F1 reaches 19.86%, compared with 9.63% for Claude Code and 10.61% for OpenHands. Finally, we integrate CONTRA into Claude Code as a plugin that identifies and reports implementation decisions requiring user clarification.

Our main contributions are as follows.

• We propose CONTRA, a selective clarification method that combines broad question discovery, semantic and execution-based question qualification, and adaptive question selection. Its execution-based qualification links candidate questions to behavioral differences between programs generated under alternative answers.

• We demonstrate consistent improvements on ClarifyCodeBench across four coding agents, achieving the highest F1 and TKQR among the compared methods. Under the same LLM and evaluation protocol, CONTRA also achieves higher clarification recall and F1 than the coding harnesses Claude Code and OpenHands.

• We implement CONTRA as a Claude Code plugin that identifies and reports implementation decisions requiring clarification, helping developers confirm intended program behavior during everyday development.

References (26)