ctx

WilletJiang's avatarfrom WilletJiang

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 Dec 23, 2025

When & Why to Use This Skill

The ctx skill is a high-performance context extraction tool designed to optimize Claude's interaction with large codebases. By leveraging ripgrep, it identifies specific patterns or symbols and retrieves a 'high-signal' context packet—small, relevant snippets of code surrounding matches. This skill is specifically engineered for fast LLM consumption, allowing agents to navigate massive repositories while strictly adhering to token budgets and output limits, ensuring the most relevant information is prioritized without overwhelming the context window.

Use Cases

  • Token-Efficient Code Search: Quickly locating function definitions or variable usages across large repositories without the need to read or paste entire files.
  • Targeted Debugging: Extracting precise code windows around error patterns or logs to provide the agent with immediate, relevant context for troubleshooting.
  • Large-Scale Repository Analysis: Gathering a condensed overview of how specific APIs or libraries are implemented across multiple files to assist in architectural reviews or refactoring.
  • Budget-Constrained Context Gathering: Using hit and file limits to ensure the agent receives a representative sample of code matches when dealing with extremely high-frequency patterns.
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.