# Context Quality
<!--
ref: @protocol/context-quality
tags: [context management, agent optimization, data fetching, compression]
triggers: [detect context pollution, optimize agent performance, compress context, fetch data efficiently]
trigger_prompt: When users notice repeated errors, excessive context size, or unclear communication from agents, they should reach for this protocol to restore clarity and efficiency.
category: core
last_reviewed: 2026-05-23
complements: [@protocol/loop, @protocol/extract, @protocol/agent-config-integration]
audience: [agent-author, claude-code-user, openclaw-user]
version: 14
updated_at: 2026-10-24T21:10:37.207Z
-->

Identify and mitigate context quality issues in agent interactions.

## Warning Signs

- **MCP Sprawl**: Each MCP adds tokens to every request. Minimize active integrations, prefer focused tool sets.
- **Brute Force Context**: Signal drowns in noise. Use indexes + targeted reads instead of dumping files.
- **Role Agents**: Spawning "frontend agent" pollutes context with role-playing setup. Use task-focused agents: "find auth patterns", "analyze impact".
- **Raw Returns**: Parent context bloats when sub-agents return everything. Compress to <500 tokens: paths, line numbers, pattern summary.
- **Vague Steps**: "Improve the code" fails the dumb-model test. Be specific.
- **Trajectory Spiral**: 3+ corrections in sequence means the context is polluted.
- **Sunk Cost**: "We've come this far" in polluted context. Cut your losses.
- **Static Docs Drift**: Code is truth, docs are claims. Keep CLAUDE.md minimal.
- **Premature Detail**: Detailing Phase 3 when Phase 1 isn't done. Reality changes plans — keep future phases rough.
- **Silent Truncation**: Piping fetches through `| head -N` chops the back half with no signal. See *Fetching protocols* below.

## Recovery Actions
- Compact context, keep index
- Fresh start with learnings captured
- Task-focused agents, not role agents
- Compress sub-agent returns to paths + summary

## Fetching protocols — never `| head`, use `?max=N`

Agent harnesses (Claude Code, others) silently truncate command output around 200 lines. `curly protocol @some/thing | head -200` chops the back half of any fetch without telling you what was lost — you build context on half a document and don't notice.

**Rule:** ask the server for less, don't truncate locally.

```bash
# Wrong — silent truncation, no signal what was cut
curly protocol @protocol/spec | head -200

# Right — server condenses to fit, structure preserved
curly protocol "@protocol/spec?max=200"     # 200 lines (bare = lines)
curly protocol "@protocol/spec?max=2000t"   # 2000 tokens
curly protocol "@protocol/spec?max=8000c"   # 8000 characters
```

`?max=N` returns an LLM-condensed version sized to your budget and emits metadata so you can see what happened:

- `condensed: true` — the body was shrunk
- `effective: <actual size>` — what you got in the requested unit
- `source_chars: <pre-condense size>` — what the full body was

Same condensation cache backs bootstrap include rows, so repeat fetches are warm. Units quantize down to a fixed ladder; the current rungs, and the lines-mode cap that has no full-content escape, are in `@protocol/bootstrap-core`. In lines mode the cap is strict; tokens/chars are soft (±15%).

**When `?max=` isn't supported yet** (some list endpoints — search, ls, find — still return full output): don't `| head`. Narrow the query instead — `?q=`, `?name=`, scope by `@repo/path` — so the server returns fewer rows in the first place.

## Context Compression

When context is degraded, compress — don't keep working in polluted context.

### When to Compress
- Context budget >35% (proactive)
- Context budget >50% (urgent)
- Phase transition
- Pollution detected (circular reasoning, repeated errors)

### Compression Format
```
## Summary
[What was accomplished, current state]

## Active Plan
[Current phase, next steps]

## Index
- Files: [paths + purpose]
- Decisions: [what + why]
- Assumptions: [HIGH/MED/LOW certainty]
```

**Rule:** Keep ALL references. Never inline large content — point to it.

---

*Related: `@content/youtube/yifan-bth/how-to-prompt-cursor-windsurf-copilot-to-get-reliable-output` · `@content/youtube/yifan-bth/windsurf-vs-cursor-in-depth-ai-code-editor-comparison` · `@content/youtube/yifan-bth/the-complete-claude-code-workflow-90-skip-this` · `@content/youtube/steph-france/i-build-ai-agents-for-4-businesses-none-of-them-use-teams` · `@content/youtube/cole-medin/11-more-tiny-coding-agent-fixes-with-a-stupid-amount-of-payoff-learn-these-now`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*