12 Agentic Harness Patterns From Claude Code
文章目录
The model is only one part of a coding agent.
The harness decides what the model remembers, which context it sees, how work is split, what tools it can use, which actions require approval, and what happens automatically around every tool call.
Looking across Claude Code's design, twelve reusable patterns emerge. They fall into four categories: memory and context, workflow and orchestration, tools and permissions, and automation.
Memory and context
- Persistent Instruction File
Load a durable project file at the start of every session. It carries build commands, architecture rules, naming conventions, and coding standards with the repository.
This prevents every conversation from starting blank. The cost is maintenance: stale instructions can confidently teach the wrong behavior.
- Scoped Context Assembly
Large repositories cannot fit all guidance into one useful file. Assemble context from organization, user, repository, and directory scopes so the agent sees rules relevant to the area it is changing.
This is powerful in monorepos, but makes it harder to understand the final instruction set when scopes conflict.
- Tiered Memory
Do not load every memory with equal priority. Keep a compact index always available, load topic-specific files on demand, and leave full transcripts on disk for search.
Different memories deserve different retention and loading strategies.
- Dream Consolidation
Long-lived memory accumulates duplicates, contradictions, and obsolete facts. Run a background process that reviews, deduplicates, prunes, and reorganizes it during idle time.
This is garbage collection for agent state. It also carries risk: an aggressive cleanup can remove something the user still needs.
- Progressive Context Compaction
Long sessions need lossy compression. Keep recent turns in full detail, summarize older turns lightly, and collapse very old history more aggressively.
The goal is not perfect recall. It is retaining the decisions and state required to continue useful work after the raw transcript no longer fits.
Workflow and orchestration
- Explore-Plan-Act Loop
Separate reading from writing. First map the codebase with read-only tools, then agree on an approach, and only then grant full edit access.
This adds ceremony to simple tasks but prevents premature changes in unfamiliar systems.
- Context-Isolated Subagents
Give research, planning, review, or log analysis to agents with their own context windows and restricted tools. Return a focused conclusion rather than the whole noisy transcript.
Isolation protects the main thread. The trade-off is handoff quality and coordination overhead.
- Fork-Join Parallelism
When work decomposes into independent units, fork several agents into isolated worktrees, let them progress in parallel, and join their results.
The speedup is real only when boundaries are clean. Overlapping edits turn parallelism into merge work.
Tools and permissions
- Progressive Tool Expansion
Do not expose every possible tool at startup. Begin with a small default set and activate MCP tools, remote capabilities, or specialized skills when the task requires them.
This reduces selection error and context cost, but the harness must recognize when expansion is needed.
- Command Risk Classification
Neither unrestricted shell access nor approval for every command scales. Parse commands before execution, classify risk from the verb, flags, and target, then apply allow, ask, or deny rules.
Deterministic classification reduces fatigue, but its rules require continuous tuning as new commands and failure modes appear.
- Single-Purpose Tool Design
Replace common shell improvisation with typed tools for reading, editing, searching, and listing files. Narrow inputs and clear boundaries make operations easier for both the model and the permission system to reason about.
Keep a general shell as a fallback for edge cases, not the default interface for everything.
Automation
- Deterministic Lifecycle Hooks
Some actions must happen every time: validate a command before execution, run a formatter after an edit, reload configuration when the working directory changes, or capture an audit event.
Put invariants in lifecycle hooks outside the prompt. Anything that must never be forgotten should not depend on the model remembering it.
Hooks improve reliability while adding a second execution layer that must be observable and debuggable.
The architecture behind the agent
These are not temporary prompt tricks. They are architectural decisions that remain valuable even as the underlying models improve.
Originally published at The Generative Programmer.




