search-code

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Search GitHub Code

搜索GitHub代码

Name

名称

github:search-code - Search for code across GitHub repositories
github:search-code - 在GitHub仓库中搜索代码

Synopsis

概要

/search-code [arguments]
/search-code [arguments]

Description

描述

Search for code across GitHub repositories
在GitHub仓库中搜索代码

Implementation

实现

Search for code, files, or implementations across GitHub repositories.
在GitHub仓库中搜索代码、文件或实现方案。

Usage

使用方法

/search-code [query]
This command helps you find relevant code across repositories.
/search-code [query]
此命令可帮助你在各个仓库中找到相关代码。

What This Command Does

该命令的功能

  1. Accepts a search query (keywords or GitHub search syntax)
  2. Searches across accessible repositories using
    search_code
  3. Returns relevant code snippets with:
    • File paths and line numbers
    • Repository names
    • Code context around matches
    • Links to view full files
  1. 接收搜索查询(关键词或GitHub搜索语法)
  2. 使用
    search_code
    在可访问的仓库中进行搜索
  3. 返回包含以下信息的相关代码片段:
    • 文件路径和行号
    • 仓库名称
    • 匹配内容的上下文代码
    • 查看完整文件的链接

Prerequisites

前提条件

  • GitHub MCP server must be installed and configured
  • OAuth authentication must be completed
  • 必须安装并配置GitHub MCP服务器
  • 必须完成OAuth身份验证

Example Interaction

交互示例

User: /search-code JWT token validation

Claude: Searching for "JWT token validation"...

Found 4 relevant code snippets:
用户: /search-code JWT token validation

Claude: 正在搜索“JWT token validation”...

找到4个相关代码片段:

1. my-org/auth-service - src/middleware/validateToken.ts

1. my-org/auth-service - src/middleware/validateToken.ts

typescript
export function validateJWT(token: string): UserPayload {
  try {
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    return decoded as UserPayload;
  } catch (error) {
    throw new UnauthorizedError('Invalid token');
  }
}
typescript
export function validateJWT(token: string): UserPayload {
  try {
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    return decoded as UserPayload;
  } catch (error) {
    throw new UnauthorizedError('Invalid token');
  }
}

2. my-org/api-gateway - lib/security/jwt.ts

2. my-org/api-gateway - lib/security/jwt.ts

typescript
async function verifyToken(req: Request): Promise<boolean> {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return false;
  return await jwt.verify(token, publicKey, { algorithms: ['RS256'] });
}
Would you like to see more results or explore any of these files?
undefined
typescript
async function verifyToken(req: Request): Promise<boolean> {
  const token = req.headers.authorization?.split(' ')[1];
  if (!token) return false;
  return await jwt.verify(token, publicKey, { algorithms: ['RS256'] });
}
是否需要查看更多结果或浏览这些文件?
undefined

Search Syntax

搜索语法

GitHub code search supports advanced syntax:
  • Exact phrase:
    "function authenticate"
  • File type:
    language:typescript
  • Path filter:
    path:src/auth
  • Repository:
    repo:owner/repo-name
  • Organization:
    org:my-org
  • Extension:
    extension:ts
GitHub代码搜索支持高级语法:
  • 精确短语
    "function authenticate"
  • 文件类型
    language:typescript
  • 路径过滤
    path:src/auth
  • 指定仓库
    repo:owner/repo-name
  • 指定组织
    org:my-org
  • 文件扩展名
    extension:ts

Examples

示例

undefined
undefined

Find all TypeScript files with "authenticate"

查找所有包含“authenticate”的TypeScript文件

authenticate language:typescript
authenticate language:typescript

Search in specific path

在特定路径中搜索

validate path:src/middleware
validate path:src/middleware

Search specific repository

搜索特定仓库

JWT repo:my-org/auth-service
JWT repo:my-org/auth-service

Combine filters

组合过滤条件

async function org:my-org language:javascript
undefined
async function org:my-org language:javascript
undefined

Tips

提示

  • Use specific keywords for better results
  • Filter by language to reduce noise
  • Search across an organization with
    org:
  • Combine with path filters to narrow scope
  • Use quotes for exact phrases
  • Review multiple implementations for patterns
  • 使用具体关键词以获得更准确的结果
  • 通过语言过滤减少无关内容
  • 使用
    org:
    在整个组织范围内搜索
  • 结合路径过滤缩小搜索范围
  • 使用引号匹配精确短语
  • 查看多种实现方案以总结模式

Related Commands

相关命令

  • /review-pr
    : Review PRs that modify found code
  • /create-issue
    : File issues for problems found
  • /create-pr
    : Create PR to fix or improve code
  • /review-pr
    :审查修改了找到代码的PR
  • /create-issue
    :为发现的问题创建Issue
  • /create-pr
    :创建PR以修复或改进代码