ctx

Extract a small, high-signal context packet around ripgrep matches (bounded by hits/files/output budget) for fast LLM consumption.

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 5, 2026

When & Why to Use This Skill

The ctx skill is a high-performance context extraction tool designed to optimize LLM interactions by retrieving precise, high-signal code snippets using ripgrep. It solves the challenge of context window limitations by providing bounded packets of information around search matches, ensuring that AI agents receive relevant data without the noise of entire files, thereby improving token efficiency and processing speed in large-scale repositories.

Use Cases

  • Efficient Code Exploration: Quickly locating specific patterns or symbols across massive codebases while maintaining a minimal token footprint for the LLM.
  • Token-Optimized Debugging: Extracting targeted context windows around error-prone code segments to help agents diagnose issues without exceeding context limits.
  • High-Signal Repository Analysis: Providing AI agents with a filtered view of relevant logic and implementation details to facilitate faster and more accurate architectural reviews.
  • Budget-Constrained Data Retrieval: Using strict output and hit limits to ensure that automated workflows remain cost-effective and performant when processing large volumes of source code.
namectx
descriptionExtract a small, high-signal context packet around ripgrep matches (bounded by hits/files/output budget) for fast LLM consumption.

ctx

Use this skill when

  • You need to show the agent a small amount of source context around a pattern/symbol without pasting whole files.
  • The repository is large and token budget matters.

Command

ctx 'PATTERN' .
ctx 'literal string' . -F
ctx 'PATTERN' path/to/file.py
ctx 'PATTERN' . --no-scope
ctx 'PATTERN' . --prefer torch --prefer aten
ctx 'PATTERN' . --json

# (fallback if wrappers are not on PATH)
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
python3 "$CODEX_HOME/skills/ctx/scripts/ctx.py" 'PATTERN' . --no-scope -C 3 --max-hits 60 --max-files 20 --max-output-lines 500

Notes

  • Uses rg --vimgrep for fast match discovery and can stop early once --max-hits is reached.
  • Reads each matched file at most once, merges overlapping context windows, then prints a bounded packet.