Extract Command

February 14, 2026 · View on GitHub

The extract command retrieves complete code blocks from files with full context. It's designed to extract functions, classes, and other code structures based on file locations, line numbers, or symbol names.


TL;DR

# Extract function at line 42
probe extract src/auth.rs:42

# Extract by symbol name
probe extract src/auth.rs#login_user

# Extract from git diff
git diff | probe extract --diff

# Extract with LLM prompt template
probe extract src/api.ts:100 --prompt engineer

# Copy to clipboard
probe extract src/utils.py:25 --to-clipboard

Basic Syntax

probe extract <FILE:LINE> [OPTIONS]
probe extract <FILE#SYMBOL> [OPTIONS]
probe extract <FILE:START-END> [OPTIONS]

Extraction Methods

MethodSyntaxDescription
Line-basedfile.rs:42Extract block containing line 42
Symbol-basedfile.rs#function_nameExtract named symbol
Range-basedfile.rs:10-20Extract lines 10-20
Multiple filesfile1.rs:10 file2.ts:20Extract from multiple locations

Input Sources

From Arguments

# Single file
probe extract src/main.rs:42

# Multiple files
probe extract src/auth.rs:10 src/user.rs:50 src/api.rs:100

# Mixed methods
probe extract src/auth.rs:42 src/user.rs#User src/api.rs:10-50

From Clipboard

# Read file:line references from clipboard
probe extract --from-clipboard

From File

# Read from a file containing references
probe extract --input-file references.txt

# From error logs
cat error.log | grep -E '\w+\.\w+:\d+' | probe extract --input-file -

From Git Diff

# Extract changed code blocks
git diff | probe extract --diff

# Extract from staged changes
git diff --cached | probe extract --diff

# Extract from specific commit
git show HEAD~1 | probe extract --diff

Command Options

Context Options

FlagTypeDefaultDescription
-c, --contextNumber0Lines of context before/after
-k, --keep-inputBooleanfalseKeep and display original input
# Add 5 lines of context
probe extract src/auth.rs:42 --context 5

# Keep original stack trace visible
probe extract --input-file error.log --keep-input

Output Options

FlagTypeDefaultDescription
-o, --formatString"color"Output format
--dry-runBooleanfalseOutput only file:line references
-t, --to-clipboardBooleanfalseCopy output to clipboard

Available Formats:

FormatDescription
colorSyntax-highlighted terminal output
markdownMarkdown with code fences
plainPlain text without formatting
jsonStructured JSON output
xmlStructured XML output
outline-xmlXML-formatted hierarchical outline
outline-diffDiff-style outline format
# Markdown for documentation
probe extract src/api.rs:42 --format markdown

# JSON for tooling
probe extract src/auth.rs:100 --format json

# Copy to clipboard
probe extract src/utils.ts:25 --to-clipboard

Input Options

FlagTypeDefaultDescription
-f, --from-clipboardBooleanfalseRead from clipboard
-F, --input-fileString-Read from file
--diffBooleanfalseParse input as git diff
# From clipboard (IDE stack trace)
probe extract --from-clipboard

# From error log file
probe extract --input-file crash.log

# From piped git diff
git diff HEAD~3 | probe extract --diff

LLM Prompt Templates

FlagTypeDefaultDescription
--promptString-System prompt template
--instructionsString-User instructions for LLM

Built-in Templates:

TemplateDescription
engineerSenior software engineer focus (code changes)
architectSoftware architect focus (design decisions)
code-reviewCode review focus
code-review-templateCode review with custom rules
Custom pathLoad template from file
# Engineer prompt for code modifications
probe extract src/auth.rs:42 --prompt engineer

# Code review with instructions
probe extract src/api.ts:100 --prompt code-review --instructions "Check for security issues"

# Custom template file
probe extract src/db.rs:50 --prompt ./prompts/database-review.md

Filter Options

FlagTypeDefaultDescription
--allow-testsBooleanfalseInclude test files
-i, --ignoreString[]-Patterns to ignore
--no-gitignoreBooleanfalseDon't respect .gitignore
# Include test utilities
probe extract tests/helpers.rs:10 --allow-tests

# Ignore generated files
probe extract src/generated.ts:50 --ignore "*.generated.*"

Output Examples

Color Output (Default)

probe extract src/auth/login.ts:15
─────────────────────────────────────────
📄 src/auth/login.ts:15-42
─────────────────────────────────────────
export async function login(
  email: string,
  password: string
): Promise<User> {
  const user = await db.findUserByEmail(email);
  if (!user) {
    throw new AuthError('User not found');
  }

  const valid = await bcrypt.compare(password, user.passwordHash);
  if (!valid) {
    throw new AuthError('Invalid password');
  }

  return generateSession(user);
}
─────────────────────────────────────────

JSON Output

probe extract src/auth/login.ts:15 --format json
{
  "blocks": [
    {
      "file": "src/auth/login.ts",
      "lines": { "start": 15, "end": 42 },
      "symbol": "login",
      "type": "function",
      "code": "export async function login(...) {...}",
      "language": "typescript"
    }
  ],
  "metadata": {
    "total_blocks": 1,
    "total_lines": 28
  }
}

Markdown Output

probe extract src/auth/login.ts:15 --format markdown
## src/auth/login.ts

### `login` (lines 15-42)

```typescript
export async function login(
  email: string,
  password: string
): Promise<User> {
  // ... implementation
}
```

Common Patterns

Debugging Workflows

# Extract from error stack trace
cat error.log | probe extract --input-file -

# Extract from clipboard (copy stack trace from IDE)
probe extract --from-clipboard --format markdown

# Extract with context for debugging
probe extract src/api.ts:142 --context 10

Code Review

# Extract changed functions for review
git diff main | probe extract --diff --prompt code-review

# Review specific file changes
git diff HEAD~1 -- src/auth.ts | probe extract --diff --prompt code-review \
  --instructions "Focus on authentication security"

Documentation

# Generate markdown documentation
probe extract src/api/endpoints.ts:* --format markdown > docs/api.md

# Extract public API for docs
probe extract src/index.ts#exportedFunction --format markdown

AI Integration

# Prepare code for AI analysis
probe extract src/complex.rs:100 --prompt architect | llm "Review this design"

# Extract and copy for ChatGPT
probe extract src/auth.rs:42 --prompt engineer --to-clipboard

# JSON for programmatic AI tools
probe extract src/api.ts:50 --format json | ai-tool analyze

Multiple Extractions

# Extract related code blocks
probe extract \
  src/models/user.ts:15 \
  src/services/auth.ts:42 \
  src/api/login.ts:100 \
  --format markdown

# From a list of references
cat important-functions.txt | xargs probe extract --format json

Symbol Extraction

Extract code by symbol name rather than line number:

# Extract a function
probe extract src/auth.rs#authenticate_user

# Extract a class
probe extract src/models/user.py#UserModel

# Extract a method
probe extract src/api/handler.ts#handleRequest

# Extract an interface
probe extract src/types.ts#ApiResponse

Note: Symbol extraction uses tree-sitter to find the named symbol in the AST.


Git Diff Integration

The --diff flag parses git diff output and extracts the changed code blocks:

# Current uncommitted changes
git diff | probe extract --diff

# Staged changes
git diff --cached | probe extract --diff

# Changes in a PR
git diff main...feature-branch | probe extract --diff

# Changes in last N commits
git diff HEAD~5 | probe extract --diff

# Specific file changes
git diff HEAD~1 -- src/auth.ts | probe extract --diff

The extractor identifies:

  • Modified functions/methods
  • Added code blocks
  • Changed class definitions
  • Updated configuration blocks

Performance Tips

  1. Use symbol extraction when you know the function name
  2. Use --dry-run to preview what will be extracted
  3. Batch extractions with multiple file arguments
  4. Use --context 0 for minimal output (default)
# Preview extraction targets
probe extract src/large-file.ts:100 --dry-run

# Batch extraction (faster than multiple commands)
probe extract file1.ts:10 file2.ts:20 file3.ts:30