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 rules/hamzaamjad/cursor-rules/105-context-trimgit clone --depth 1 https://github.com/hamzaamjad/cursor-rulesWhat 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.02492 | $0.02492 |
| Opus 5 | $0.01246 | $0.01246 |
| Sonnet 5 | $0.00498 | $0.00498 |
| Haiku 4.5 | $0.00249 | $0.00249 |
Grade A, and why
105-context-trim 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 2d 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 — 248 lines — stays where its author put it; the contents beside it link to each section on GitHub.
context-trim.mdc
-
Purpose: To maximize effective context utilization by intelligently compressing input data while preserving semantic integrity. This rule acts as a pre-processor that ensures optimal signal-to-noise ratio, enabling deeper reasoning within computational constraints. Proven Performance: MInference achieves 10x speedup with 90-95% semantic preservation. LLMLingua demonstrates 20:1 compression ratios while maintaining task accuracy.
-
Requirements:
- Compression Strategies:
- keep_edges: Preserve first 20% and last 20%, summarize middle
- semantic_skeleton: Maintain structure markers (headings, key transitions)
- perplexity_prune: Remove low-information tokens based on predictability
- hierarchical_summary: Recursive summarization preserving relationships
- task_aware: Adapt strategy based on task type (code vs. narrative vs. data)
- Token Budgets:
- Simple tasks: 4K tokens maximum
- Moderate tasks: 16K tokens target
- Complex tasks: 64K tokens with structured compression
- Never exceed 128K without explicit justification
- Preservation Priorities:
- User query and direct context
- Structural markers and transitions
- Unique/rare information (high perplexity)
- Causal relationships and dependencies
- Concrete examples and edge cases
- Compression Techniques:
- Replace verbose descriptions with concise labels
- Extract and index repeated patterns
- Convert narrative to structured data where possible
- Use reference pointers for redundant content
- Maintain running summary of trimmed content
- Compression Strategies:
-
Validation:
- Check: Is token count within specified budget?
- Check: Are document structure markers preserved?
- Check: Can key information be reconstructed from compressed version?
- Check: Is compression strategy appropriate for content type?
- Check: Is compression ratio logged for optimization?
-
Examples:
-
Scenario: Large log file analysis (1M tokens)
COMPRESSION PLAN: Input: Server logs (1M tokens, 50K lines) Strategy: hierarchical_summary + pattern_extraction Step 1: Pattern Detection - Identified: 5 error patterns (80% of content) - Extracted: Pattern templates + occurrence counts Step 2: Temporal Compression - Kept: First/last 100 lines verbatim - Summarized: Hourly aggregates for middle section Step 3: Anomaly Preservation - Preserved: 47 unique errors (full context) - Indexed: Location pointers for drill-down Result: 15K tokens (93% reduction) Retained: All errors, patterns, temporal flow -
Scenario: Multi-document research (300K tokens)
COMPRESSION EXECUTION: Documents: 12 research papers Semantic Skeleton: - Title, Abstract, Conclusions: KEEP FULL - Methods: EXTRACT key algorithms only - Results: CONVERT tables to key findings - Discussion: SUMMARIZE to main arguments - References: INDEX by relevance score Cross-Document: - Deduplicate common background (40% reduction) - Create citation graph (relationships preserved) - Build unified terminology map Output: 45K tokens with full semantic coverage
-
-
Advanced Patterns:
- Attention-Based Trimming: Use A-shape pattern for documents, Block-Sparse for code
- Sliding Window: Maintain detailed context for recent tokens, aggressive compression for older
- Semantic Chunking: Compress at natural boundaries (paragraphs, functions, sections)
- Lossless References: Store trimmed content with retrieval pointers
- Progressive Disclosure: Start compressed, expand on demand
-
Implementation Architecture:
Raw Input → Tokenizer → Strategy Selector → Compressor → Validator → Output ↓ ↓ ↓ ↓ ↓ [Token Count] [Content Type] [Techniques] [Fidelity] [Context]
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.
- 2d ago First seen · 248 lines · 2,492 tokens per session scan A d7bbcdcae21a
105-context-trim is a cursor rule published in the GitHub repository hamzaamjad/cursor-rules (2 stars, last pushed 1y ago), licensed MIT. It adds 2,492 tokens to every session, about $0.0125 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-31.
Other cursor rules, from other repositories
angular-20
This rule provides comprehensive best practices and coding standards for Angular development, focusing on modern TypeScript, standalone components, signals, and performance optimizations.
dev-standard
Apache Superset development standards and guidelines for Cursor IDE.
cli-error-handling
CLI command error handling patterns.
prefer-direct-imports-over-module-mocks
Prefer extracting a testable core over vi.mock / vi.resetModules when unit tests need to reach production logic entangled with config, env, or singletons.
control-plane-descriptors
Control plane descriptor and instance implementation patterns.
family-instance-domain-actions
Family instance domain action implementation patterns.