Source-linked AI summary
Building Effective AI Coding Agents for the Terminal: Scaffolding, Harness, Context Engineering, and Lessons Learned
Nghi D. Q. Bui
TL;DR
Long-running terminal coding agents face unresolved challenges in context management, safety, and capability extension. OPENDEV presents an open, compound command-line architecture with specialized workflows and runtime mechanisms for addressing these constraints. The paper’s principal contribution is a production-oriented account of these design choices, while systematic benchmark evaluation remains future work.
Problem
Frontier agents struggle with continuous terminal operation, while long-running agents must manage finite context, prevent destructive operations, and extend capabilities within limited prompt budgets.
Method
OPENDEV combines independently configurable workflow-level LLMs with explicit thinking and critique phases, staged context compaction, event-driven reminders, lazy tool discovery, and experience-driven memory.
Results
OPENDEV documents a production-ready, extensible terminal-native architecture whose model bindings, safety enforcement, context management, and runtime capabilities can evolve through configuration and layered design.
Takeaways & Limitations
The paper offers architectural patterns and engineering lessons for building terminal-first coding agents that balance capability, autonomy, safety, and token efficiency.
Takeaways & Limitations
The paper lacks systematic quantitative evaluation on established benchmarks such as SWE-bench, Terminal-Bench, and LongCLI-Bench.
Abstract
from arXiv · showhide
The landscape of AI coding assistance is undergoing a fundamental shift from complex IDE plugins to versatile, terminal-native agents. Operating directly where developers manage source control, execute builds, and deploy environments, CLI-based agents offer unprecedented autonomy for long-horizon development tasks. In this paper, we present OPENDEV, an open-source, command-line coding agent written in Rust, engineered specifically for this new paradigm. Effective autonomous assistance requires strict safety controls and highly efficient context management to prevent context bloat and reasoning degradation. OPENDEV overcomes these challenges through a compound AI system architecture with workload-specialized model routing, a dual-agent architecture separating planning from execution, lazy tool discovery, and adaptive context compaction that progressively reduces older observations. Furthermore, it employs an automated memory system to accumulate project-specific knowledge across sessions and counteracts instruction fade-out through event-driven system reminders. By enforcing explicit reasoning phases and prioritizing context efficiency, OPENDEV provides a secure, extensible foundation for terminal-first AI assistance, offering a blueprint for robust autonomous software engineering.
1 Introduction
Terminal-native coding agents bring autonomous, multi-step software engineering into the development environment, but long-running operation requires deliberate solutions for context, safety, and extensibility. OPENDEV addresses these challenges with a configurable compound architecture, explicit reasoning workflows, and runtime orchestration mechanisms.
- The rise of terminal-native agents: Terminal-native agents operate alongside source control, build systems, remote SSH sessions, and headless servers, extending coding assistance beyond inline IDE completion.Benchmarks nevertheless show that frontier models struggle with continuous terminal operation.
- Engineering challenges: Long-running terminal agents must manage finite context windows, prevent destructive shell operations, and extend capabilities without exhausting prompt budgets.These challenges motivate the paper’s separation between scaffolding and the runtime harness.
- OPENDEV: OPENDEV is an open command-line agent designed to document production-oriented design decisions and lessons learned rather than present a novel algorithmic breakthrough.The paper positions it between benchmark-oriented frameworks, browser-based systems, undocumented CLI agents, and closed-source industrial practice.
- Architectural principles: OPENDEV uses a compound AI architecture in which agents and workflows independently bind to user-configured LLMs, enabling model selection and provider changes through configuration.This makes the system model-agnostic by construction and supports workflow-level routing of capability, latency, and cost.
- Design principles and contributions: The system emphasizes separation of concerns, progressive degradation, and transparency, applying these principles to configurable models, context compaction, safety, tool dispatch, reminders, and prompt composition.Its contributions include an extended ReAct pipeline with thinking and optional self-critique phases, event-driven reminders, and conditionally loaded instructions.
- Paper organization: The paper proceeds from system construction to cross-cutting lessons, research positioning, future directions, and reference catalogs of tools, prompts, schemas, and constants.The architecture spans agent reasoning, context engineering, tooling, and persistence.
2 System Architecture
OPENDEV combines explicit execution safeguards with context-management mechanisms that preserve useful information during long-running terminal-agent sessions. Its architecture also separates planning from execution, specializes subagents, and uses targeted runtime guidance to reduce failure modes.
- Agent runtime architecture: Schema-level separation gives Planner subagents only read-only tools, eliminating plan-mode state-machine risks while reducing their tool surface.The Planner cannot write because write tools are absent from its schema; it can also run concurrently with other subagents.
- Safety and failure prevention: Fingerprint-based doom-loop detection catches identical tool-and-argument repetitions within 3 repetitions, earlier than coarse iteration safeguards.The mechanism targets repeated calls such as reading a nonexistent file in a loop.
- Context engineering: Under 100 tokens in most cases, per-tool summarization compresses long outputs and, with 8,000-character offloading, extends typical sessions from 15–20 to 30–40 turns.A single long-running test suite previously consumed 30,000 tokens in one tool call.
- Context engineering: Hybrid compaction preserves critical identifiers while retaining long-range strategic context, avoiding failures caused by pure summarization or recency-only history.Pure summarization lost paths and names, whereas recent-only context lost the original goal after 10 turns.
- Runtime guidance: System reminders counter instruction fade-out by injecting short, single-purpose guidance immediately before decision points in long conversations.The system prompt’s influence was observed to fade predictably beyond 15 tool calls, while repeating the full prompt would waste tokens.
- Runtime guidance: User-role reminders appear at high dialogue recency and produced noticeably higher effectiveness than system-role injections in early experiments.The paper attributes this to the model treating the reminder as something that just happened and requires a response.
- Runtime guidance: Targeted error-recovery guidance converts raw tool failures into actionable recovery instructions instead of leaving the agent to respond with an apology.The mechanism addresses failures where an error result alone does not explain how to recover.
- Context engineering: Adaptive Context Compaction uses a five-stage progressively aggressive pipeline, including fast pruning and full compaction, to manage token pressure.Fast pruning replaces older tool results with markers, while full compaction archives history and summarizes the middle while preserving recent messages.
3 Discussion
OPENDEV’s discussion frames long-horizon terminal agents as a context, behavior, safety, and robustness engineering problem. Its lessons favor progressive context reduction, timely reminders, separated reasoning, explicit tool routing, architectural safety constraints, and tools that tolerate approximate outputs.
- Context as a Budget: Tool outputs consume 70–80% of typical session context, making finite context a budget shared by capabilities, history, and observations.The paper therefore treats context allocation as a core engineering constraint rather than a passive storage problem.
- Context as a Budget: Graduated context reduction—continuous monitoring, stale-output pruning, masking, and overflow summarization—outperforms compacting everything only at the hard limit.Fast pruning removes older tool results before expensive LLM-based summarization is needed.
- Context as a Budget: Large tool outputs can be offloaded to scratch files, returning a preview and reference so full content is retrieved only when needed.This converts repeated context consumption into an on-demand retrieval operation.
- Context as a Budget: Provider-reported prompt_tokens are essential for calibration because invisible provider-injected content can make local estimates trigger compaction too late.The paper reports that underestimation caused context overflow errors.
- Steering Behavior Over Long Horizons: After 30 or more tool calls, system-prompt influence can decay as instructions become distant and buried beneath tool results.The paper characterizes long-horizon behavioral control as a signal-to-noise problem.
- Steering Behavior Over Long Horizons: Recent user-role reminders improve compliance more than distant system instructions, but excessive reminder frequency turns them into ignorable background noise.The paper recommends injecting short reminders at decision points and capping each reminder type.
- Separating Thinking from Action: A tool-free thinking phase produces better reasoning traces than asking the model to think carefully while tool schemas remain available.The proposed mechanism is removing action affordances from the thinking call, not merely adding an instruction.
- Tool Selection: A concrete retrieval decision tree routes symbol names to semantic search, string patterns to text search, structural patterns to AST search, and file names to glob.The paper reports fewer unnecessary grep calls and improved first-attempt retrieval accuracy.
4 Related Work
Related work places OPENDEV within research on code intelligence, autonomous software engineering, tool-use protocols, memory, lifecycle management, and context engineering. The cited literature also shows that terminal agents remain difficult to evaluate and that human guidance can improve long-horizon task completion.
- Code Intelligence and Autonomous Software Engineering: Code intelligence has progressed from function-level generation to repository-level tasks requiring cross-file planning and multi-step reasoning.The progression includes benchmarks such as HumanEval, MBPP, ClassEval, and repository-level challenges.
- Code Intelligence and Autonomous Software Engineering: SWE-bench catalyzed research on autonomous issue resolution across single-agent, multi-agent, and workflow-based approaches.Related systems extend autonomous navigation and editing through iterative refinement, role specialization, and generalist task solving.
- Capability Improvement: Inference-time methods include backtracking with Monte Carlo Tree Search and parallel exploration, alongside training with curriculum learning, synthetic data, and process-oriented rewards.These approaches target stronger agent capabilities through both model training and search over repair trajectories.
- Interaction Protocols and Code-Driven Agents: Code-driven interaction gives agents precise tool invocation, reproducible state management, and composable action primitives.This work connects OPENDEV’s terminal execution model with a broader shift beyond purely natural-language reasoning.
- Interaction Protocols and Code-Driven Agents: ReAct, ReWOO, MCP, and A2A provide standardized patterns for tool invocation, state management, multi-turn orchestration, and inter-agent communication.These protocols form the interaction infrastructure surrounding contemporary agent systems.
- Interaction Protocols and Code-Driven Agents: Code-based reasoning frameworks translate plans into executable operations through methods such as PAL, Program-of-Thoughts, CodeAct, TaskWeaver, and CodeAgents.The cited systems use code or plugin-based calls to structure reasoning and action execution.
- Memory and Context: Voyager, Reasoning Bank, MemGPT, and ExpeRepair address context constraints through executable skills, rule-based learning, and hierarchical or dual-memory architectures.These systems motivate memory and context mechanisms relevant to persistent coding agents.
- Agentic Software Engineering: Agentic Software Engineering research identifies agent orchestration, environment design, and lifecycle management as foundational pillars.The cited roadmap frames collaboration between human engineers and LLMs as structured software workflows.
5 Conclusion and Future Directions
OPENDEV combines layered architectural mechanisms for model flexibility, context efficiency, safety, and long-running agent operation. The paper also identifies missing quantitative evaluation and unresolved trade-offs as directions for future work.
- Conclusion: OPENDEV integrates compound multi-model routing, an extended ReAct pipeline, adaptive context compaction, reminders, and persistent memory.These mechanisms are presented as the paper’s key architectural contributions.
- Conclusion: Adaptive Context Compaction reduced peak context consumption by approximately 54% and often avoided emergency summarization.Observations transition through active, faded, and archived states.
- Conclusion: Event-driven reminders and three-tier context management addressed instruction violations that reliably appeared after 30+ tool calls.The architecture combines static prompts, dynamic reminders, and long-horizon persistence.
- Lessons Learned: The paper synthesizes tensions involving context pressure, long-horizon behavioral steering, architectural safety enforcement, imprecise tools, and resource bounds.These tensions are framed as transferable lessons from iterative development.
- Future Directions: Shadow git snapshots were implemented as per-step undo during continued development, demonstrating extensibility of the layered architecture.This capability had previously been identified as future work.
- Future Directions: The paper lacks systematic quantitative evaluation and calls for benchmarking against SWE-bench, Terminal-Bench, and LongCLI-Bench.It also identifies adaptive resource allocation as a future direction because current parameters are globally fixed.
- Lessons Learned: Effective agentic coding systems must balance capability versus complexity, autonomy versus safety, and generality versus token efficiency.The paper presents these as competing design concerns without a single dominant choice.
A Complete Tool Catalog
The appendix catalogs OPENDEV’s built-in tools by handler category and notes that external tools can also be discovered dynamically through MCP.
- Tool Catalog: Table 1 provides the complete catalog of OPENDEV’s built-in tools.The catalog is organized by handler category.
- Tool Catalog: Each built-in tool is described in the main text’s Section 2.4.The appendix serves as a quick reference rather than replacing those descriptions.
- Tool Catalog: External tools can be dynamically discovered through MCP in addition to OPENDEV’s built-in tools.The passage does not enumerate those external tools.
B LSP Language Server Matrix
The appendices document language-server support and the modular prompt-composition system, including section registration, conditional loading, caching, variable substitution, and fallbacks.
- LSP Language Server Matrix: Table 2 lists programming languages supported through LSP integration with their corresponding language servers.The system includes standard languages and experimental servers configured in ls_config.py.
- Prompt Composition: PromptComposer uses a filter–sort–load–join pipeline and can partition prompts into stable cacheable and dynamic parts.Conditions are evaluated before file I/O, and surviving sections are sorted by priority.
- Prompt Composition: The default action-mode agent registers sections with activation conditions, cacheability metadata, and summaries, while thinking mode registers only four sections.Thinking mode omits tool-use and code-quality guidance to avoid premature action bias.
- Prompt Composition: Five standalone templates serve roles outside the normal section registry and are loaded directly by their respective subsystems.They are not auto-registered through PromptComposer.
- Prompt Composition: Prompt templates support runtime variable substitution through a centralized registry and two-tier fallback behavior when sections or modular composition fail.The fallback can skip missing individual sections or use a monolithic prompt when modular composition fails wholesale.
D Edit Tool Fuzzy Matching Chain
The edit_file tool uses a short-circuiting chain of replacers to tolerate mismatches between requested and actual file content while preserving original formatting.
- Matching Chain: The edit_file tool implements nine replacer classes in a chain-of-responsibility pattern.Each replacer addresses a specific mismatch category between the LLM’s old_content and the file.
- Matching Chain: Exact matches short-circuit the chain and incur zero overhead from fuzzy passes.Later replacers are used only when earlier matching strategies fail.
- Matching Chain: Each replacer returns the substring found in the original file rather than the search query.This preserves the file’s original formatting after a fuzzy match.
- Matching Chain: The chain progresses from exact matching through line trimming, block anchoring, whitespace normalization, indentation flexibility, and escape normalization.These strategies target increasingly tolerant forms of textual mismatch.
E Shell Execution Pipeline
The shell execution pipeline processes every run_command invocation through six stages. Figure 17 illustrates this pipeline.
- The shell execution pipeline handles every run_command invocation.
- The pipeline contains six stages.
- Figure 17 illustrates the six-stage pipeline.
E.1 Six-Stage Pipeline Details
The pipeline begins with safety gates and command preparation, then enforces timeout and interrupt controls during execution.
- Safety gates: Three safety checks run before any command executes.Permission configuration, allowed-command matching, and dangerous-pattern blocking govern execution approval and rejection.
- Safety gates: Dangerous patterns such as rm -rf /, sudo, fork bombs, curl|bash pipe chains, and dd to device files are rejected without user override.
- Command preparation: Interactive prompts for known package managers, including npm init and npx, are auto-confirmed during command preparation.The passage states that auto-confirmation is performed by prepending an operation, but the excerpt ends before specifying it.
- Timeout and interrupt: Idle timeout kills commands after 60 seconds without output, while absolute timeout caps execution at 600 seconds.
- Timeout and interrupt: The shared InterruptToken is checked each polling cycle and triggers process-group termination through os.killpg().
E.2 Server Detection Patterns
Server detection uses 16 regex patterns to auto-promote commands to background mode, with case-insensitive matching.
- Table 6 lists 16 regex patterns for auto-promoting commands to background mode.
- The patterns determine which commands are automatically promoted to background mode.
- All patterns are matched with re.IGNORECASE.
F System Reminder Catalog
The system reminder catalog contains 24 named reminders organized by category, with injection timing defined across nine steps in each ReAct iteration.
- The appendix catalogs 24 named system reminders.
- The reminders are organized by category.
- Reminder injection follows nine steps within each ReAct iteration.
F.1 Reminder Categories
OPENDEV organizes 24 reminders into six functional categories for managing agent behavior and workflow transitions.
- 24 reminders are organized into six functional categories.
- Phase control: Phase-control reminders manage thinking/action transitions and regulate whether the agent reasons deeply or acts directly.
- Task lifecycle: Task-lifecycle reminders steer multi-step workflows, including subagent-result synthesis, plan restatement, and session-resume continuity.
F.2 Injection Timing
The ReAct executor injects reminders in a strict nine-step sequence during each iteration, with safety guards limiting repeated nudges.
- Reminders are injected by the ReAct executor in a strict 9-step ordering within each iteration.
- The sequence checks context pressure and interrupts, runs thinking with optional trace injection, processes subagent and UI signals, calls the action-phase LLM, and dispatches responses.
- Response handling diverges between no-tool and tool-call paths, triggering different completion, todo, plan, denial, and read-pattern nudges.
- Session persistence performs an automatic save as the ninth step.
- Safety guards: One-shot flags and attempt budgets prevent reminder degeneration by limiting selected reminders to once per run or bounded repeats.
G Subagent Capability Matrix
OPENDEV’s subagent registry assigns domain-restricted tools to subagents, while retaining unlimited default iteration budgets and a special ask-user path.
- Table 7 documents the complete subagent registry.
- Each subagent receives a filtered tool set restricted to its domain.
- All subagents have unlimited iteration budgets by default, while the ask-user subagent bypasses the LLM execution path.
H Configuration Schema
OPENDEV’s AppConfig model includes a documented set of key configuration fields.
- Table 8 describes the key configuration fields in OPENDEV’s AppConfig model.
- The configuration schema is presented through the AppConfig model.
- Table 8 serves as the reference for OPENDEV’s key configuration fields.
I Implementation Constants
This section documents key implementation constants and explains their rationale.
- The section documents key implementation constants with their rationale.
J CLI Command Reference
OPENDEV provides terminal commands, interactive controls, and keyboard shortcuts for starting sessions, managing modes, and controlling execution. Its guidance distinguishes direct tools from subagents and requires immediate tool use during iterative reasoning.
- CLI options: OPENDEV starts interactive, non-interactive, resumed, project-scoped, and web-interface sessions through dedicated command-line options.
- Interactive commands: Interactive commands toggle modes, undo file operations, manage sessions, configure thinking, and exit the session.
- MCP workflow: MCP commands list, add, enable, and disable configured external servers, while discovered tools support data queries such as repository searches.
- Interaction pattern: The interaction pattern requires thinking, immediate tool action, observation, repetition, and concise completion, and forbids promising an action without calling the tool.
- Tool selection: The tool-versus-subagent guide assigns direct tools to known targets and subagents to exploration, specialization, multi-file work, or deep analysis.
- Tool selection: Specialized tool selection prefers dedicated file, editing, searching, and listing tools over shell commands, while parallel independent operations may be batched.