ASK KNOX
beta
LESSON 377

Scoping Context to the Task

Domain scoping, sub-agent context isolation, and why a focused 80-line context for a trading agent beats a noisy 400-line context that includes design rules and content pipeline instructions.

7 min read·Context Engineering & CLAUDE.md Architecture

Introduction

The single-agent assumption — one Claude session, full CLAUDE.md, all tools, all context — breaks down as soon as you start running parallel agents or specialized sub-agents. A security agent that knows about design tokens doesn't produce better security findings. A trading agent that knows about bi-modal CSS design doesn't produce better trade analysis.

Context scoping is the discipline of giving each agent exactly the context it needs to do its job well — and nothing else. This is not about limiting agents. It is about improving them by removing the noise that degrades signal-specific reasoning.

Domain Scoping in Practice

Knox's stack has three primary agent domains, each with its own scoped context:

Trading Agent (the trading bot): The context includes Phemex USDT futures semantics, the asyncio timeout rules, launchd supervision patterns, Decimal not float for P&L math, and the USDT-margined futures wallet constraint. Explicitly excluded: academy content rules, design system requirements, CLAUDE.md global UI rules.

Academy Build Agent: The context includes 90% coverage floor, Supabase auth only, bi-modal design requirement, MDX frontmatter contract, Next.js 16 App Router patterns. Explicitly excluded: trading logic, Phemex API patterns, agent gateway tools, Mission Control backend rules.

Content Pipeline Agent: The context includes blog-autopilot pattern, voice profile rules, image fallback chain, Git PR gate (no direct publish), Discord announce channel IDs. Explicitly excluded: test coverage rules, trading risk parameters, auth stack constraints.

Each scoped context is approximately 60–120 focused lines versus a hypothetical 400-line omnibus context. The difference in output quality is measurable — trading agents with trading context make better trading decisions.

Sub-Agent Context Isolation

When dispatching sub-agents for parallel work, the orchestrator holds broad context and dispatches domain-scoped prompts — not the full CLAUDE.md.

The dispatch prompt anatomy for a security audit sub-agent:

You are a security audit agent for the trading bot.

Your context:
- Trading bot on Tesseract machine (198.51.100.42)
- Phemex perps trading (USDT-margined futures only)
- Environment: asyncio Python, launchd-supervised
- Key security concerns: API key exposure, order size bounds, wallet validation

Your task: Audit the order submission pipeline for these specific risks:
1. API key not in URLs or logs
2. qty bounds checked before submission (no >$X per order)
3. Wallet address validated before any transfer

Out of scope for this audit: design, content, non-trading code

This prompt gives the security agent everything it needs and nothing it doesn't. The agent does not need to know about bi-modal design, academy content rules, or content pipeline patterns. Excluding this context is not a limitation — it is precision engineering.

The Anti-Patterns: When Scoping Fails

Context leakage: The orchestrator gives a sub-agent the full CLAUDE.md when the dispatch prompt could include only the relevant section. This is the most common failure — it requires no extra work but produces degraded sub-agent quality.

Cross-domain contamination: A trading agent is given a global CLAUDE.md that includes "no dangerouslySetInnerHTML without sanitization" — a frontend security rule that is not relevant to trading bot code. The agent may apply frontend security heuristics to trading logic analysis.

Missing negative scope: Telling an agent what it should look at but not what it should ignore. "Audit the trading code" without "exclude design and content files from your analysis" may result in the agent expanding its scope unnecessarily.

Symmetric context assumption: Assuming that because the orchestrator has full context, sub-agents should too. The orchestrator needs full context to coordinate. Sub-agents need only their domain context to produce quality outputs in their domain.

Practical Scoping Implementation

Step 1: Identify the agent's domain. What specific type of task is this agent doing? Security audit? Test writing? Performance analysis? UI component review?

Step 2: List the context that matters. For the specific domain, which rules, constraints, and facts are directly relevant? Write this as a bullet list.

Step 3: Explicitly exclude cross-domain noise. State what is out of scope: "This agent does not need to know about design system rules, content pipeline patterns, or trading bot constraints."

Step 4: Scope the Semantic Memory Layer query. Filter to the relevant namespace: memory_query("the trading bot security", namespace="trading-kb") not memory_query("the trading bot security") across all namespaces.

Step 5: Scope the tools. Don't give the trading agent access to the content pipeline MCP server. Don't give the academy build agent access to Phemex API tools.

Why Focused Context Beats Comprehensive Context

The intuition is that more context should always help — "the model will filter out what's irrelevant." This is empirically wrong for two reasons:

  1. Attention dilution: Transformer attention is not perfectly selective. Irrelevant context competes for the attention that should go to relevant context. A security agent analyzing an order submission function allocates less attention to the relevant code when the context also contains design system rules.

  2. Hallucination risk from irrelevant pattern matching: A trading agent that has absorbed design system rules may apply UI security patterns (XSS prevention, input sanitization) to trading code analysis where they don't apply. The result is a false sense of comprehensive coverage combined with missed actual risks.

The focused context is not limiting the agent — it is directing its capability precisely at the domain where it is needed.

Summary

  • Domain scoping: each agent gets only the context relevant to its domain, explicitly excluding cross-domain noise
  • Sub-agent isolation: orchestrators hold broad context, dispatch domain-scoped prompts — not the full CLAUDE.md
  • Three failure modes: context leakage, cross-domain contamination, missing negative scope
  • Scoped Semantic Memory Layer queries: namespace filter prevents cross-domain knowledge from contaminating domain-specific retrieval
  • Focused 80-line context beats noisy 400-line context: attention dilution and irrelevant pattern matching degrade quality

What's Next

The next lesson — the capstone — brings every concept from this track together into the Context Engineering Playbook: a hands-on audit of your own CLAUDE.md and memory setup, with the complete system assembly and the 200K-token budget breakdown.