How AI Coding Agent Harnesses Work: Context, Rules, Hooks, Skills, and Subagents
This article breaks down the internal mechanisms behind intelligent coding tools, focusing on the agent harness that determines how they behave in real, multi-file engineering projects. It covers what actually occupies the context window, how overflow triggers a two-step recovery process, and why summarization causes instruction drift. It then explains how project rule files, event hooks, skill modules, and subagent delegation work together to keep long-running tasks stable, auditable, and controllable. A final checklist summarizes how to apply these five layers in practice.
1. Why You Need to Understand What’s Inside the Harness
Many developers interact with intelligent coding tools at a surface level: ask a question, get code back. Once the work moves into long-running, cross-file engineering scenarios, three problems tend to appear:
- The model suddenly “forgets” conventions agreed on earlier.
- Batch changes accidentally trigger high-risk commands.
- The context fills up with irrelevant logs, and response quality drops.
None of these indicate that the model has degraded. They are the result of policies built into the runtime framework that hosts the model, commonly referred to in the industry as an agent harness. Those policies govern context scheduling, permission control, and task orchestration.
A mature coding tool typically stacks five layers of capability: context management, project rules, event hooks, skill modules, and subagent delegation. Understanding the boundaries between these layers and how they cooperate is what separates “using the tool” from “using it well.” The sections below walk through each layer.
2. What Actually Lives in the Context Window
A common misconception is that the context window equals the conversation history. In reality, conversation history is only one category. A complete window usually holds seven types of information at once:
- Conversation history — the multi-turn text exchanged between user and model.
- File content — source snippets that have been read or edited.
- Command output — results of terminal commands, often the largest item by volume.
- Project rules — convention files persisted in the repository.
- Automatic memory — preferences and lessons accumulated across sessions.
- Loaded skills — full instruction text injected after a skill is triggered.
- System instructions — the framework’s own runtime rules and tool definitions.
2.1 Two-Stage Recovery When the Window Fills Up
When the window approaches its limit, mainstream implementations apply two stages of handling. The first stage evicts bulky, time-sensitive artifacts, such as early file reads and command echoes. The second stage compresses conversation history into a summary, condensing exact wording, numbers, and code snippets into an overview.
2.2 The Information Loss Caused by Compression
Summarization is lossy. A naming convention stressed in turn three, or an architectural trade-off settled in turn five, may survive compression as a single vague sentence. This is the root cause of “instruction failure” in long conversations. There are two practical countermeasures:
- Push constraints that need to hold across turns down into the project rule file. It is re-injected after every compression and is unaffected by summarization. You can also add a dedicated “retain after compaction” list that spells out which decisions must not be dropped.
- Trigger compaction yourself and specify a focus topic, for example by asking it to retain details only around interface changes, so the limited window carries the information the current task genuinely needs.
Example usage:
/compact Keep only this round's interface field changes and compatibility constraints
3. Project Rule Files: Writing Conventions Into the Repository
The value of a rule file lies in being versionable, reviewable, and reusable. It is committed alongside the code, so every team member and every tool reads the same set of constraints.
A practical structure groups content into three categories: tech stack and directory conventions; coding and testing standards; and prohibited actions with approval boundaries. Keep it lean. Write only what the model cannot infer from the code itself. An overly long file crowds out the context window and dilutes the clauses that matter.
4. Event Hooks: Handing Determinism Back to Programs
Hooks run user-defined scripts before and after tool calls. They exist to handle deterministic work that should not be left to the model’s judgment:
- Automatic formatting and static checks before commit.
- Interception of dangerous commands.
- Backup before sensitive files are written.
- Operation logs persisted to storage for auditing.
The guiding principle is that the model makes judgments; hooks provide the safety net. Any check that can be expressed as an explicit rule should be scripted rather than repeated in prompts.
{"PreToolUse": "scripts/guard.sh","PostToolUse": "scripts/format_and_log.sh"}
5. Skill Modules: Domain Knowledge Loaded on Demand
A skill packages the methodology, templates, and checklists for a class of tasks into a pluggable unit that is injected only when it matches semantically. Compared with stuffing every standard into the context up front, this significantly reduces window usage and cross-interference.
Split skills by task domain rather than by technology keyword, for example “database migration review” or “frontend component creation.” Each skill should contain its applicable scenarios, execution steps, verification method, and failure fallback.
6. Subagent Delegation and Plan-First Execution
For cross-module refactors, single-threaded sequential execution is both slow and prone to polluting the main context. A better approach combines two orchestration patterns:
- Plan-execute separation — produce a reviewable implementation plan first, then land the changes step by step.
- Parallel subagents — hand off research, testing, and documentation subtasks to independent context instances, and have them return only conclusions and key evidence.
The main context then retains only the information needed for decisions, which both speeds things up and lowers the risk of incorrect edits.
7. Implementation Checklist
- Context — compact proactively before long tasks; push rules down into repository files.
- Rules — keep them lean and reviewable, with explicit prohibitions.
- Hooks — script formatting, validation, and auditing.
- Skills — split by task domain, including verification and fallback.
- Delegation — plan before executing; run subtasks in parallel and return conclusions.
Baking these five layers into an engineering template is what turns an intelligent coding tool from occasionally useful into reliably controllable. For team-level sharing of rules and skills, you can rely on general-purpose cloud services such as object storage, container platforms, and log monitoring tools for distribution and observability, without binding to any proprietary interface.
