filesystem

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Filesystem Skill

Filesystem Skill

<identity> Filesystem Skill - Guidance for file system operations using Claude Code's built-in tools. Read, write, search, and manage files efficiently. </identity> <capabilities> - Reading single or multiple files - Creating or modifying files - Searching for files by pattern - Searching file contents - Directory navigation </capabilities> <instructions> <execution_process>
<identity> Filesystem Skill - 指导如何使用Claude Code内置工具进行文件系统操作,高效地读取、写入、搜索和管理文件。 </identity> <capabilities> - 读取单个或多个文件 - 创建或修改文件 - 按模式搜索文件 - 搜索文件内容 - 目录导航 </capabilities> <instructions> <execution_process>

Claude Code Built-in Tools

Claude Code内置工具

Reading Files

读取文件

Read Tool: Read file contents
Read file_path="/path/to/file.txt"
Options:
  • offset
    : Start line (for large files)
  • limit
    : Number of lines to read
Read工具: 读取文件内容
Read file_path="/path/to/file.txt"
选项:
  • offset
    : 起始行(针对大文件)
  • limit
    : 要读取的行数

Finding Files

查找文件

Glob Tool: Find files by pattern
Glob pattern="**/*.ts"
Common patterns:
  • **/*.ts
    - All TypeScript files
  • src/**/*.tsx
    - React components in src
  • **/test*.js
    - Test files anywhere
Glob工具: 按模式查找文件
Glob pattern="**/*.ts"
常见模式:
  • **/*.ts
    - 所有TypeScript文件
  • src/**/*.tsx
    - src目录下的React组件
  • **/test*.js
    - 任意位置的测试文件

Searching Content

搜索文件内容

Primary Search: Use
pnpm search:code "query"
or
Skill({ skill: 'ripgrep' })
for content searching. The built-in Grep tool is fallback-only.
Grep Tool: Search file contents (fallback only — prefer
pnpm search:code
or ripgrep skill first)
Grep pattern="function myFunc" path="/src"
Options:
  • output_mode
    : "content", "files_with_matches", or "count"
  • -A
    ,
    -B
    ,
    -C
    : Context lines
优先搜索: 使用
pnpm search:code "query"
Skill({ skill: 'ripgrep' })
进行内容搜索。内置的Grep工具仅作为备选方案。
Grep工具: 搜索文件内容(仅作为备选——优先使用
pnpm search:code
或ripgrep skill)
Grep pattern="function myFunc" path="/src"
选项:
  • output_mode
    : "content"、"files_with_matches"或"count"
  • -A
    ,
    -B
    ,
    -C
    : 上下文行数

Writing Files

写入文件

Write Tool: Create or overwrite files
Write file_path="/path/to/file.txt" content="..."
Edit Tool: Modify existing files
Edit file_path="/path/to/file.txt" old_string="..." new_string="..."
Write工具: 创建或覆盖文件
Write file_path="/path/to/file.txt" content="..."
Edit工具: 修改现有文件
Edit file_path="/path/to/file.txt" old_string="..." new_string="..."

Directory Operations

目录操作

Bash Tool: For directory operations
bash
undefined
Bash工具: 用于目录操作
bash
undefined

List directory

列出目录

ls -la /path/to/dir
ls -la /path/to/dir

Create directory

创建目录

mkdir -p /path/to/new/dir
mkdir -p /path/to/new/dir

Move/rename

移动/重命名

mv /old/path /new/path

</execution_process>

<best_practices>
mv /old/path /new/path

</execution_process>

<best_practices>

Common Workflows

常见工作流

Reading Multiple Files

读取多个文件

undefined
undefined

Read files in parallel (multiple Read calls in one message)

并行读取文件(在一条消息中调用多个Read)

Read file_path="/src/app.ts" Read file_path="/src/config.ts" Read file_path="/src/utils.ts"
undefined
Read file_path="/src/app.ts" Read file_path="/src/config.ts" Read file_path="/src/utils.ts"
undefined

Search and Read

搜索并读取

undefined
undefined

1. Find files

1. 查找文件

Glob pattern="**/*.config.ts"
Glob pattern="**/*.config.ts"

2. Read matching files

2. 读取匹配的文件

Read file_path="/path/from/glob/result"
undefined
Read file_path="/path/from/glob/result"
undefined

Find and Replace

查找并替换

undefined
undefined

1. Search for pattern

1. 搜索模式

Grep pattern="oldFunction" path="/src"
Grep pattern="oldFunction" path="/src"

2. Edit each file

2. 编辑每个文件

Edit file_path="/src/file.ts" old_string="oldFunction" new_string="newFunction"
undefined
Edit file_path="/src/file.ts" old_string="oldFunction" new_string="newFunction"
undefined

Best Practices

最佳实践

  1. Read Before Edit: Always read a file before editing it
  2. Use Glob Over Bash: Prefer Glob to
    find
    for file discovery
  3. Search Tool Hierarchy: Use
    pnpm search:code
    or
    Skill({ skill: 'ripgrep' })
    first; use the Grep tool as fallback over raw bash grep only
  4. Parallel Reads: Read multiple files in one message for speed
  5. Verify Changes: Read file after editing to verify
</best_practices> </instructions>
<examples> <usage_example> **Find and read all TypeScript files**:
Glob pattern="src/**/*.ts"
  1. 编辑前先读取: 编辑文件前务必先读取文件内容
  2. 优先使用Glob而非Bash: 文件发现优先使用Glob而非
    find
  3. 搜索工具层级: 优先使用
    pnpm search:code
    Skill({ skill: 'ripgrep' })
    ;仅在必要时使用Grep工具作为原生bash grep的备选
  4. 并行读取: 在一条消息中读取多个文件以提升速度
  5. 验证更改: 编辑后读取文件以验证更改
</best_practices> </instructions>
<examples> <usage_example> **查找并读取所有TypeScript文件**:
Glob pattern="src/**/*.ts"

Then read the results

然后读取结果

Read file_path="/src/app.ts"

</usage_example>

<usage_example>
**Search for a function and edit it**:
Grep pattern="export function oldName" path="/src"
Read file_path="/src/app.ts"

</usage_example>

<usage_example>
**搜索函数并编辑**:
Grep pattern="export function oldName" path="/src"

Found in /src/utils.ts:23

在/src/utils.ts:23找到

Edit file_path="/src/utils.ts" old_string="export function oldName" new_string="export function newName"

</usage_example>
</examples>
Edit file_path="/src/utils.ts" old_string="export function oldName" new_string="export function newName"

</usage_example>
</examples>

Rules

规则

  • Always read files before editing
  • Use built-in tools (Read, Glob, Grep) instead of bash equivalents
  • Verify changes after editing
  • 编辑文件前务必先读取
  • 使用内置工具(Read、Glob、Grep)而非bash等效命令
  • 编辑后验证更改

Memory Protocol (MANDATORY)

内存协议(强制要求)

Before starting:
bash
cat .claude/context/memory/learnings.md
After completing:
  • New pattern ->
    .claude/context/memory/learnings.md
  • Issue found ->
    .claude/context/memory/issues.md
  • Decision made ->
    .claude/context/memory/decisions.md
ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
开始前:
bash
cat .claude/context/memory/learnings.md
完成后:
  • 新模式 ->
    .claude/context/memory/learnings.md
  • 发现问题 ->
    .claude/context/memory/issues.md
  • 做出的决策 ->
    .claude/context/memory/decisions.md
假设会被中断: 你的上下文可能会重置。如果内容不在内存中,就视为未发生过。