文件系统操作技能Skill filesystem

该技能提供使用Claude Code内置工具进行文件系统操作的指南,包括文件读取、写入、搜索和管理等功能,帮助用户高效处理文件任务。关键词:文件系统、文件操作、Claude Code、读取、写入、搜索、管理、开发工具。

DevOps 0 次安装 3 次浏览 更新于 3/10/2026

名称: 文件系统 描述: 文件系统操作指南 - 使用Claude Code的内置工具读取、写入、搜索和管理文件。 版本: 1.0 模型: sonnet 调用方式: 两者 用户可调用: true 工具: [Read, Write, Edit, Bash, Glob, Grep] 最佳实践:

  • 使用Read工具读取文件内容
  • 使用Glob工具进行文件模式匹配
  • 使用pnpm search:code或ripgrep技能进行内容搜索;Grep工具仅作为备选
  • 使用Edit工具进行修改 error_handling: graceful streaming: supported verified: false lastVerifiedAt: 2026-02-19T05:29:09.098Z

文件系统技能

<identity> 文件系统技能 - 使用Claude Code的内置工具进行文件系统操作指南。高效地读取、写入、搜索和管理文件。 </identity>

<capabilities>

  • 读取单个或多个文件
  • 创建或修改文件
  • 按模式搜索文件
  • 搜索文件内容
  • 目录导航 </capabilities>

<instructions> <execution_process>

Claude Code内置工具

读取文件

Read工具: 读取文件内容

Read file_path="/path/to/file.txt"

选项:

  • offset: 起始行(用于大文件)
  • limit: 要读取的行数

查找文件

Glob工具: 按模式查找文件

Glob pattern="**/*.ts"

常见模式:

  • **/*.ts - 所有TypeScript文件
  • src/**/*.tsx - src中的React组件
  • **/test*.js - 任何地方的测试文件

搜索内容

主要搜索: 使用pnpm search:code "query"Skill({ skill: 'ripgrep' })进行内容搜索。内置的Grep工具仅作为备选。

Grep工具: 搜索文件内容(仅作为备选 — 优先使用pnpm search:code或ripgrep技能)

Grep pattern="function myFunc" path="/src"

选项:

  • output_mode: “content”, “files_with_matches”, 或 “count”
  • -A, -B, -C: 上下文行数

写入文件

Write工具: 创建或覆盖文件

Write file_path="/path/to/file.txt" content="..."

Edit工具: 修改现有文件

Edit file_path="/path/to/file.txt" old_string="..." new_string="..."

目录操作

Bash工具: 用于目录操作

# 列出目录
ls -la /path/to/dir

# 创建目录
mkdir -p /path/to/new/dir

# 移动/重命名
mv /old/path /new/path

</execution_process>

<best_practices>

常见工作流

读取多个文件

# 并行读取文件(在一个消息中多个Read调用)
Read file_path="/src/app.ts"
Read file_path="/src/config.ts"
Read file_path="/src/utils.ts"

搜索并读取

# 1. 查找文件
Glob pattern="**/*.config.ts"

# 2. 读取匹配的文件
Read file_path="/path/from/glob/result"

查找并替换

# 1. 搜索模式
Grep pattern="oldFunction" path="/src"

# 2. 编辑每个文件
Edit file_path="/src/file.ts" old_string="oldFunction" new_string="newFunction"

最佳实践

  1. 编辑前先读取: 编辑文件前始终先读取它
  2. 使用Glob而非Bash: 优先使用Glob而非find进行文件发现
  3. 搜索工具层次: 优先使用pnpm search:codeSkill({ skill: 'ripgrep' });Grep工具仅作为备选,而非原始bash grep
  4. 并行读取: 在一个消息中读取多个文件以提高速度
  5. 验证更改: 编辑后读取文件以验证

</best_practices> </instructions>

<examples> <usage_example> 查找并读取所有TypeScript文件:

Glob pattern="src/**/*.ts"
# 然后读取结果
Read file_path="/src/app.ts"

</usage_example>

<usage_example> 搜索函数并编辑它:

Grep pattern="export function oldName" path="/src"
# 在/src/utils.ts:23找到

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

</usage_example> </examples>

规则

  • 编辑前始终先读取文件
  • 使用内置工具(Read、Glob、Grep)而非bash等效工具
  • 编辑后验证更改

记忆协议(强制)

开始前:

cat .claude/context/memory/learnings.md

完成后:

  • 新模式 -> .claude/context/memory/learnings.md
  • 发现的问题 -> .claude/context/memory/issues.md
  • 做出的决定 -> .claude/context/memory/decisions.md

假设中断:您的上下文可能会重置。如果不在记忆中,那它就没发生过。