Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/itsmostafa/llm-engineering-skills/context-engineeringnpx skills add itsmostafa/llm-engineering-skills --skill context-engineeringgit clone --depth 1 https://github.com/itsmostafa/llm-engineering-skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/itsmostafa/llm-engineering-skills/context-engineering)<a href="https://agentmods.dev/skills/itsmostafa/llm-engineering-skills/context-engineering"><img src="https://agentmods.dev/badge/skills/itsmostafa/llm-engineering-skills/context-engineering.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00042 | $0.02809 |
| Opus 5 | $0.00021 | $0.01404 |
| Sonnet 5 | $0.00008 | $0.00562 |
| Haiku 4.5 | $0.00004 | $0.00281 |
Grade A, and why
context-engineering scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 391 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Context Engineering
Context engineering is the discipline of curating and maintaining the optimal set of tokens during LLM inference. Unlike prompt engineering (crafting individual prompts), context engineering focuses on what information enters the context window and when.
Table of Contents
- Core Principles
- Context Management Strategies
- System Prompt Design
- Tool Design for Context Efficiency
- Long-Horizon Task Patterns
- Implementation Patterns
- Best Practices
- References
Core Principles
Context as a Finite Resource
LLMs have limited "attention budgets." As context length increases, models experience context rot—decreased ability to accurately recall information. The goal is finding the smallest possible set of high-signal tokens that maximize desired outcomes.
Effective Context = Relevant Information / Total Tokens
Key insight: More context isn't better. The right context is better.
The Context Pollution Problem
Every token added to context has costs:
- Increased latency and compute
- Diluted attention to important information
- Higher risk of hallucination from conflicting data
- Reduced model performance on retrieval tasks
Context Management Strategies
1. Context Trimming
Drop older conversation turns, keeping only the last N turns.
| Aspect | Details |
|---|---|
| Mechanism | Sliding window over conversation history |
| Pros | Deterministic, zero latency, preserves recent context verbatim |
| Cons | Abrupt loss of long-range context, "amnesia" effect |
| Best for | Independent tasks, short interactions, predictable workflows |
def trim_context(messages: list, keep_last_n: int = 10) -> list:
"""Keep system message + last N turns."""
system_msgs = [m for m in messages if m["role"] == "system"]
other_msgs = [m for m in messages if m["role"] != "system"]
return system_msgs + other_msgs[-keep_last_n:]
What ships with it
2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 5d ago First seen · 391 lines · 42 tokens per session scan A 62b8c5c90379
context-engineering is a skill published in the GitHub repository itsmostafa/llm-engineering-skills (23 stars, last pushed 4mo ago), licensed MIT. It adds 42 tokens to every session and 2,809 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other skills, from other repositories
context-optimizer
上下文优化专家。专注于长对话中的上下文管理、token 效率和性能优化。解决 lost-in-middle、context poisoning 等问题,提升 AI 代理在复杂任务中的表现。.
distill
One-time snapshot extracting patterns from work history and accumulated lessons, distills into concrete improvements — new agent/skill suggestions, memory pruning, consolidating lessons into rules/agent updates, or performing bin/ extraction from /audit --efficiency candidates. Roster boundary analysis →…
session
Session state that outlives a context reset — dump sweeps the live conversation and writes a compact handover doc (goal, decisions + why, lessons, standing instructions, files-touched table, outstanding items, next step), then prints /clear; the session-restore.js SessionStart hook re-injects it automatically. park…
session-handoff
Use when the user says "session handoff", "wrap up session", "hand off", "handoff summary", "let's wrap up", "summarize before I clear", or wants a structured end-of-session summary before clearing context. Also use proactively when the user says they are about to /clear and no handoff has been produced yet. Generates…
engineering-historian
Capture engineering knowledge as a promotion pipeline (CASE → JUDGMENT → PRINCIPLE → STANDARD) and retrieve answers from it. Capture is automatic — a post-session sweep drafts cases with status:auto; the user reviews them at /distill. Use whenever the user types "/history", "/case", or "/distill", says "log this…
agent-carnet
Use this skill when the user asks to save, recall, find, or organize notes. Triggers on: 'remember this', 'save this', 'note this', 'what did we discuss about...', 'check the notebook', 'find in carnet'. Also use proactively when discovering findings worth preserving across sessions.