# Optimize AI Context for Longer Tasks

Long AI sessions can waste tokens, increase latency, and lose important context. This skill provides practical methods for compaction, masking, caching, partitioning, and budgeting.

## Install

```bash
npx skillstore add sickn33/context-optimization
```

## Metadata

- Status: approved
- Slug: sickn33-context-optimization
- Skillstore revision: r2
- Version status: missing
- Tree hash: 6399593ad8f639da509a177c6aefccff289580f7e5749a680a7449ebd687011b
- Author: sickn33
- GitHub username: sickn33
- License: MIT
- Repository: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/context-optimization
- Ref: f9e2c34b4f19c7f3e6b0a1e93227b5f77cc12526
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/sickn33-context-optimization
- Manifest: https://skillstore.pages.dev/api/skills/sickn33-context-optimization/manifest

## Capabilities

- Selects optimization strategies based on whether tools, documents, or message history dominate token usage.
- Defines compaction triggers and summary priorities for long conversations.
- Classifies observations for retention, summarization, or reference-based masking.
- Orders stable and unique prompt elements to improve prefix-cache reuse.
- Allocates context budgets and partitions complex work across isolated agents.

## Use Cases

- Reduce production agent costs: Define token budgets, cache-stable prefixes, and compaction triggers for long-running agent workflows.
- Preserve long research sessions: Summarize older material while retaining decisions, key facts, citations, and unresolved questions.
- Control verbose tool output: Replace completed tool observations with compact summaries and retrievable references.

## Prompt Templates

### Find the largest context costs

```
Review this agent context: [context]. Identify the largest token consumers and recommend one low-risk optimization.
```

### Create a compaction plan

```
Create a compaction plan for [conversation]. Preserve decisions, constraints, unresolved questions, and recent evidence. Set a trigger based on token utilization.
```

### Design an observation policy

```
Design an observation-masking policy for [workflow]. Classify outputs as retain, summarize, or reference. Define retrieval rules for masked details.
```

### Architect a context system

```
Design a measured context architecture for [system]. Include budgets, cache-stable prefixes, partition boundaries, compaction triggers, quality checks, and rollback criteria.
```

## Limitations

- It provides design guidance and examples, not a runtime context management library.
- It cannot increase a model's actual context-window limit.
- Recommended reduction and cache targets require validation with each workload.
- Aggressive summarization or masking can remove evidence needed for later decisions.

## Best Practices

- Measure token use, latency, cache hits, and answer quality before changing the context strategy.
- Preserve recent evidence, active constraints, decisions, and unresolved questions during compaction.
- Test optimization thresholds with representative production workloads and define rollback criteria.

## Anti Patterns

- Do not summarize the entire context without identifying information that must remain exact.
- Do not mask recent observations or evidence supporting an active decision.
- Do not add timestamps or request-specific data to otherwise stable prompt prefixes.

## Security Audit

- Audited at: 2026-07-23T21:19:11.69\+00:00
- Summary: All eight static findings are false positives caused by Markdown code fences, benign Python examples, and ordinary prose. No executable shell commands, reconnaissance behavior, prompt injection, or malicious intent were found.

## Stats

- Views: 105
- Downloads: 25
- Favorites: 0
- Popularity score: 0
