| layout | default |
|---|---|
| title | Chapter 4: Terminal and Runtime Tools |
| nav_order | 4 |
| parent | Cline Tutorial |
Welcome to Chapter 4: Terminal and Runtime Tools. In this part of Cline Tutorial: Agentic Coding with Human Control, you will build an intuitive mental model first, then move into concrete implementation details and practical production tradeoffs.
One of Cline's strongest capabilities is command execution with output feedback. This chapter shows how to use that safely and effectively.
flowchart LR
A[Run Command] --> B[Capture Output]
B --> C[Interpret Failure or Success]
C --> D[Patch or Next Step]
D --> E[Re-run Validation]
E --> F[Done or Iterate]
| Command Type | Typical Use |
|---|---|
| lint/static checks | quick syntax and style signal |
| unit tests | verify behavior on targeted modules |
| integration tests | validate cross-module contracts |
| build checks | detect bundling/type/runtime issues |
| diagnostics | reproduce and isolate environment failures |
Set clear defaults:
- read-only and low-risk commands can be broadly approved
- mutating or destructive commands require explicit confirmation
- commands outside repo scope should be blocked by default
Define repo-level canonical commands for Cline to use:
lint: pnpm lint
test: pnpm test
test:target: pnpm test -- <module>
build: pnpm build
This reduces random command attempts and flaky behavior.
For dev servers/watchers:
- start one long-running process
- allow Cline to proceed while process is running
- run separate short validation commands for checks
- stop and restart only when environment changes require it
This avoids repeated startup overhead.
| Control | Why It Matters |
|---|---|
| per-command approval | prevents accidental destructive actions |
| timeout limits | avoids runaway loops |
| retry caps | stops endless failing retries |
| command denylist | blocks known-dangerous actions |
| scoped working directory | limits blast radius |
When command fails:
- classify error type (dependency, syntax, environment, flaky test)
- ask for minimal fix in known files
- rerun only relevant command first
- expand to broader checks after targeted pass
This speeds convergence.
Before accepting task completion, require:
- exact command(s) executed
- pass/fail status
- key error lines or success indicators
- relationship between patch and command outcome
You now have a command-execution model that balances:
- agent autonomy
- runtime safety
- deterministic validation
- fast failure recovery
Next: Chapter 5: Browser Automation
The TerminalManager in src/integrations/terminal/TerminalManager.ts manages VS Code terminal instances for Cline's command execution. It handles creating terminals, running commands, capturing output streams, and detecting when long-running processes have finished or need user intervention.
This file is the direct implementation of the terminal tool behavior described in this chapter. The runCommand method shows how Cline executes shell commands: it spawns them in a VS Code terminal, monitors output, and signals completion or timeout back to the agent loop.
Within src/core/Cline.ts, the execute_command tool handler shows the approval flow before any shell command runs: the proposed command is surfaced to the user in the Cline sidebar, and execution only proceeds after explicit approval. This is the human-in-the-loop gate for all terminal operations.
The handler also covers the "background process" pattern: commands that produce a server or watcher are detected by output patterns, and Cline continues without waiting for process exit.
The shell integration in src/services/shell/ShellIntegration.ts hooks into VS Code's terminal shell integration API to detect command boundaries — when a command starts and ends — without relying on fragile output parsing. This is what allows Cline to know when a build or test run has completed and capture the full exit code.
flowchart TD
A[Agent proposes execute_command tool call]
B[Cline.ts surfaces command to user sidebar]
C{User approves?}
D[TerminalManager creates or reuses VS Code terminal]
E[Command runs with ShellIntegration tracking]
F[Output streamed to Cline context]
G[Completion or timeout detected]
H[Command blocked, not executed]
A --> B
B --> C
C -- yes --> D
D --> E
E --> F
F --> G
C -- no --> H