用途:探索和分析本地或远程代码仓库,并就仓库内容回答问题。支持本地路径、远程 URL 以及 owner/repo 简写。
主要能力:从用户消息中提取仓库来源与问题;对远程仓库先做浅克隆再用只读工具探索;可针对指定分支或标签克隆;输出基于代码事实并标注文件路径与行号的结构化答案。
使用方式:远程仓库先克隆,例如 REPO_DIR=$(mktemp -d) && git clone --depth 1 <url> "$REPO_DIR";指定分支时用 git clone --depth 1 --branch <ref> <url> "$REPO_DIR"。随后在仓库目录下运行:cd <repo_path> && CLAUDECODE= claude -p "<question>" --model haiku --output-format text --max-turns 15 --allowedTools "Read" "Grep" "Glob" "Bash(find *)" "Bash(ls *)" "Bash(wc *)" "Bash(git log *)" "Bash(git show *)" "Bash(git diff *)" "Bash(git branch *)" "Bash(head *)" "Bash(tail *)" --append-system-prompt "You are a code exploration expert. Thoroughly explore the repository to answer the user's question. Strategy: 1) Glob to discover project structure. 2) Grep to find patterns, definitions, routes, classes. 3) Read to examine key files. Always cite file paths and line numbers. Give a structured answer based on code facts."。运行需设置超时 600000(10 分钟);大型仓库可将 --max-turns 增至 25;用户要求 sonnet 或 opus 时替换 --model haiku;远程仓库结果展示后执行 rm -rf "$REPO_DIR" 清理。
限制与注意:必须直接在 claude -p 前加 CLAUDECODE=(设置空环境变量),否则嵌套会话会被阻止;问题中的双引号需用 " 转义;含空格的路径需加引号;工具权限限于只读类命令。官方收费、平台与效果信息暂未提供。