LLM-based code agents treat repositories as unstructured text, applying edits through brittle string matching that frequently fails due to formatting drift or ambiguous patterns. We propose reframing the codebase as a structured action space where agents operate on named AST entities rather than text spans. Our framework, CODESTRUCT, provides readCode for retrieving complete syntactic units and editCode for applying syntax-validated transformations to semantic program elements. Evaluated on SWE-Bench Verified across six LLMs, CODESTRUCT improves Pass@1 accuracy by 1.2-5.0% while reducing token consumption by 12-38% for most models. Models that frequently fail to produce valid patches under text-based interfaces benefit most: GPT-5-nano improves by 20.8% as empty-patch failures drop from 46.6% to 7.2%. On CodeAssistBench, we observe consistent accuracy gains (+0.8-4.4%) with cost reductions up to 33%. Our results show that structure-aware interfaces offer a more reliable foundation for code agents.
Figures & tables
Figure 1: Contrasting action spaces for code agents. Text-based agents (left) read ~300 lines to locate a function and regenerate ~44 lines verbatim for removal, making edits brittle to formatting changes. CodeStruct (right) reads only the target symbol (~50 lines) and specifies removal in ~2 lines via a symbol-scoped edit.
Figure 2: Overview of CodeStruct . Code agents interact with repositories through a structured AST action space. Source code is parsed into an AST, exposing addressable nodes. The readCode and editCode tools operate directly on these nodes, enabling structure-aware code navigation and modification without string matching, line numbers, or brittle edits.
Model
Interface
Pass@1 (%) ↑
Input Tokens
Output Tokens
LLM Calls ↓
Cost ()\downarrow$
GPT-5
Baseline
66.0
452.7M
0.81M
16,436
574.0
CodeStruct
67.2 (+1.2)
366.3M (-19.1%)
0.44M (-45.7%)
16,307 (-0.8%)
462.2 (-19.5%)
GPT-5-mini
Baseline
60.4
593.7M
1.27M
18,560
151.0
CodeStruct
62.0 (+1.6)
404.5M (-31.9%)
0.35M (-72.4%)
14,811 (-20.2%)
101.8 (-32.6%)
GPT-5-nano
Baseline
19.6
808.0M
0.86M
24,037
40.7
CodeStruct
40.4 (+20.8)
1,137.4M (+40.8%)
0.95M (+10.5%)
27,278 (+13.5%)
57.3 (+40.8%)
Table 1: Main results on SWE-Bench Verified. Agents follow SWE-Agent-style workflows—iterative loops that alternate between reading repository files and applying code edits via tool calls. We compare text-based interaction ( Baseline ) against CodeStruct . Inline percentages indicate relative change compared to Baseline (percentage points for Pass@1; relative % for tokens, calls, and cost). Green denotes improvement; red denotes regression.
Model
Interface
Accuracy (%) ↑
Input Tokens
Output Tokens
LLM Calls ↓
Cost ()\downarrow$
GPT-5
Baseline
53.3
143.9M
1.27M
566
$19.57
CodeStruct
54.1 (+0.8)
122.1M (-15.1%)
1.18M (-7.0%)
550 (-2.8%)
$16.74 (-14.5%)
GPT-5-mini
Baseline
51.1
125.3M
1.26M
648
$3.45
CodeStruct
51.9 (+0.8)
83.1M (-33.7%)
0.89M (-28.7%)
630 (-2.8%)
$2.30 (-33.3%)
GPT-5-nano
Baseline
46.7
56.0M
1.25M
742
$0.34
CodeStruct
48.1 (+1.4)
52.8M (-5.7%)
1.05M (-15.6%)
652 (-12.1%)
$0.32 (-5.9%)
Table 2: CodeAssistBench results comparing text-based interaction ( Baseline ) against CodeStruct . Inline values show relative change over Baseline (percentage points for Accuracy; relative % for tokens, calls, and cost).
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 3: Comparison of CodeStruct (AST-based) vs. text-based code editing approaches. CodeStruct completes in 24 steps vs. 54 steps for text-based—a 55.6% reduction.
Metric
CodeStruct
Text-Based
Total Steps
24
54
Steps to Locate Target
2
21
Edit Success on First Try
Yes
Yes
Final Outcome
Success
Success
Appendix
Table 3: Comparison on django__django-11211
Qwen3-32B
GPT-5-mini
Configuration
Pass@1 (%)
Input (M)
Output (M)
Calls
Cost ($)
Pass@1 (%)
Input (M)
Output (M)
Calls
Cost ($)
Baseline
14.8
366.0
1.23
25,543
55.64
60.4
593.7
1.27
18,560
150.97
CodeStruct
16.0
302.1
1.03
24,653
45.93
62.0
404.5
0.35
14,811
101.83
w/o editCode
12.8
291.6
0.85
24,535
44.25
60.6
562.1
0.35
15,757
141.22
w/o readCode
8.2
423.4
1.78
35,670
64.58
56.8
435.2
0.33
15,715
109.46
Appendix
Table 4: Ablation results with cost analysis on SWE-Bench Verified. Removing either readCode or editCode degrades performance, with readCode causing the largest accuracy drop while editCode removal causes the largest cost penalty relative to performance. Input/Output tokens shown in millions. Cost is computed using per-model API pricing, consistent with Table 1 .
Model
Approach
Total Errors
Errors/Instance
Reduction
GPT-5
Text-based
426
0.845
-
GPT-5
CodeStruct
52
0.103
-87.8%
GPT-5-mini
Text-based
568
1.125
-
GPT-5-mini
CodeStruct
127
0.252
-77.6%
GPT-5-nano
Text-based
459
0.911
-
GPT-5-nano
CodeStruct
551
1.093
+20.0%
Appendix
Table 5: Error rates across models and interfaces. CodeStruct dramatically reduces errors for capable models but increases them for GPT-5-nano, identifying a capability threshold.