Grepai Trace Callers

yoanbernabeu/grepai-skills/skills/trace/grepai-trace-callers

作者 yoanbernabeu382d40261c0d41109c6e11872574ba0be9b064d0無授權條款收錄於 2026年10月9日更新於 2026年10月9日

Find function callers with GrepAI trace. Use this skill to discover what code calls a specific function.

AI 產生的概覽

指導使用 grepai trace callers 指令找出呼叫某個函式的程式碼位置。

功能
說明如何執行 grepai trace callers 來定位函式或方法的呼叫點,涵蓋基本用法、JSON、精簡 JSON 與 TOON 輸出格式,以及 fast 與 precise 兩種擷取模式。文件也介紹 .grepai/config.yaml 設定、支援的語言、使用 jq 與 Python 的指令稿範例,以及結果缺少或過多時的排解方式。產出的是操作指引與指令範例,而非產生的檔案。
適用情境
適用於重構或重新命名函式之前、評估修改函式簽章的影響時,或在瀏覽與偵錯程式碼庫時查看某個函式被誰呼叫。
執行需求
需要 grepai 命令列工具,並已更新其符號索引(例如透過 grepai watch)。precise 模式還需要 tree-sitter。此技能未附指令稿,僅為說明文件。

GrepAI Trace Callers

This skill covers using grepai trace callers to find all code locations that call a specific function or method.

When to Use This Skill

  • Finding all usages of a function before refactoring
  • Understanding function dependencies
  • Impact analysis before changes
  • Code navigation and exploration

What is Trace Callers?

grepai trace callers answers: "Who calls this function?"

func Login(user, pass) {...}        ↑        │┌───────┴───────────────────┐│   Who calls Login()?      │├───────────────────────────┤│ • HandleAuth (auth.go:42) ││ • TestLogin (test.go:15)  ││ • CLI (main.go:88)        │└───────────────────────────┘

Basic Usage

bash
grepai trace callers "FunctionName"

Example

bash
grepai trace callers "Login"

Output:

🔍 Callers of "Login"
Found 3 callers:
1. HandleAuth   File: handlers/auth.go:42   Context: user.Login(ctx, credentials)
2. TestLoginSuccess   File: handlers/auth_test.go:15   Context: result := Login(testUser, testPass)
3. RunCLI   File: cmd/main.go:88   Context: err := auth.Login(username, password)

JSON Output

For programmatic use:

bash
grepai trace callers "Login" --json

Output:

json
{  "query": "Login",  "mode": "callers",  "count": 3,  "results": [    {      "file": "handlers/auth.go",      "line": 42,      "caller": "HandleAuth",      "context": "user.Login(ctx, credentials)"    },    {      "file": "handlers/auth_test.go",      "line": 15,      "caller": "TestLoginSuccess",      "context": "result := Login(testUser, testPass)"    },    {      "file": "cmd/main.go",      "line": 88,      "caller": "RunCLI",      "context": "err := auth.Login(username, password)"    }  ]}

Compact JSON (AI Optimized)

bash
grepai trace callers "Login" --json --compact

Output:

json
{  "q": "Login",  "m": "callers",  "c": 3,  "r": [    {"f": "handlers/auth.go", "l": 42, "fn": "HandleAuth"},    {"f": "handlers/auth_test.go", "l": 15, "fn": "TestLoginSuccess"},    {"f": "cmd/main.go", "l": 88, "fn": "RunCLI"}  ]}

TOON Output (v0.26.0+)

TOON format offers ~50% fewer tokens than JSON:

bash
grepai trace callers "Login" --toon

Output:

callers[3]:  - call_site:      context: "user.Login(ctx, credentials)"      file: handlers/auth.go      line: 42    symbol:      name: HandleAuth      ...

Note: --json and --toon are mutually exclusive.

Extraction Modes

GrepAI offers two extraction modes:

Fast Mode (Default)

Uses regex patterns. Fast and dependency-free.

bash
grepai trace callers "Login" --mode fast

Precise Mode

Uses tree-sitter AST parsing. More accurate but requires tree-sitter.

bash
grepai trace callers "Login" --mode precise

Comparison

ModeSpeedAccuracyDependencies
fast⚡⚡⚡GoodNone
precise⚡⚡Excellenttree-sitter

Configuration

Configure trace in .grepai/config.yaml:

yaml
trace:  mode: fast  # fast or precise
  enabled_languages:    - .go    - .js    - .ts    - .py    - .php    - .rs
  exclude_patterns:    - "*_test.go"    - "*.spec.ts"

Supported Languages

LanguageExtensions
Go.go
JavaScript.js, .jsx
TypeScript.ts, .tsx
Python.py
PHP.php
C/C++.c, .h, .cpp, .hpp, .cc, .cxx
Rust.rs
Zig.zig
C#.cs
Java.java
Pascal/Delphi.pas, .dpr

Use Cases

Before Refactoring

bash
# Find all usages before renaminggrepai trace callers "getUserById"
# Check impact of changing signaturegrepai trace callers "processPayment"

Understanding Codebase

bash
# Who uses this core function?grepai trace callers "validateToken"
# Find entry points to a modulegrepai trace callers "initialize"

Debugging

bash
# Where is this function called from?grepai trace callers "problematicFunction"

Code Review

bash
# Verify function usage before approving changesgrepai trace callers "deprecatedMethod"

Handling Common Names

If your function name is common, results may include unrelated code:

Problem

bash
grepai trace callers "get"  # Too common, many false positives

Solutions

  1. Use more specific name:
bash
grepai trace callers "getUserProfile"
  1. Filter results by path:
bash
grepai trace callers "get" --json | jq '.results[] | select(.file | contains("auth"))'

Combining with Semantic Search

Use together for comprehensive understanding:

bash
# Find what Login does (semantic)grepai search "user login authentication"
# Find who uses Login (trace)grepai trace callers "Login"

Scripting Examples

Bash

bash
# Count callersgrepai trace callers "MyFunction" --json | jq '.count'
# Get caller function namesgrepai trace callers "MyFunction" --json | jq -r '.results[].caller'
# Get file paths onlygrepai trace callers "MyFunction" --json | jq -r '.results[].file' | sort -u

Python

python
import subprocessimport json
result = subprocess.run(    ['grepai', 'trace', 'callers', 'Login', '--json'],    capture_output=True,    text=True)
data = json.loads(result.stdout)print(f"Found {data['count']} callers of Login:")for r in data['results']:    print(f"  - {r['caller']} in {r['file']}:{r['line']}")

Common Issues

❌ Problem: No callers found ✅ Solutions:

  • Check function name spelling (case-sensitive)
  • Ensure file type is in enabled_languages
  • Run grepai watch to update symbol index

❌ Problem: Too many false positives ✅ Solutions:

  • Use more specific function name
  • Add exclude patterns in config
  • Filter results with jq

❌ Problem: Missing some callers ✅ Solutions:

  • Try --mode precise for better accuracy
  • Check if files are in ignore patterns

Best Practices

  1. Use exact function name: Case matters
  2. Check symbol index: Run grepai watch first
  3. Use JSON for scripts: Easier to parse
  4. Combine with search: Semantic + trace = full picture
  5. Filter large results: Use jq or grep

Output Format

Trace callers result:

🔍 Callers of "Login"
Mode: fastLanguage files scanned: 245
Found 3 callers:
1. HandleAuth   File: handlers/auth.go:42   Context: user.Login(ctx, credentials)
2. TestLoginSuccess   File: handlers/auth_test.go:15   Context: result := Login(testUser, testPass)
3. RunCLI   File: cmd/main.go:88   Context: err := auth.Login(username, password)
Tip: Use --json for machine-readable output     Use --mode precise for more accurate results

來源與署名

來源:yoanbernabeu/grepai-skills位於skills/trace/grepai-trace-callers提交382d402

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架