scratch-workspace

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scratch Workspace Management

临时工作区管理

This skill covers proper use of the
.claude/.scratch/
directory for temporary, exploratory, and draft work.
本技能介绍了如何正确使用
.claude/.scratch/
目录来存放临时、探索性和草稿类工作内容。

Purpose

用途

The scratch workspace provides a gitignored location for:
  • Draft implementations
  • Experimental code
  • Temporary test files
  • Planning documents
  • Any work-in-progress that shouldn't be committed
临时工作区提供了一个被git忽略的存储位置,用于存放:
  • 草稿实现代码
  • 实验性代码
  • 临时测试文件
  • 规划文档
  • 任何不应提交的在研工作内容

Setup Checklist

设置检查清单

Before creating scratch files:
  1. Ensure directory exists
    bash
    mkdir -p .claude/.scratch
  2. Verify gitignore
    Check
    .gitignore
    contains:
    .claude/.scratch
    If missing, add it:
    bash
    echo '.claude/.scratch' >> .gitignore
创建临时文件前:
  1. 确保目录存在
    bash
    mkdir -p .claude/.scratch
  2. 验证gitignore配置
    检查
    .gitignore
    文件中是否包含:
    .claude/.scratch
    如果缺失,添加该配置:
    bash
    echo '.claude/.scratch' >> .gitignore

Directory Structure

目录结构

Organize scratch files by purpose:
.claude/
├── .scratch/
│   ├── drafts/           # Work-in-progress implementations
│   │   └── feature-x.ts
│   ├── experiments/      # Exploratory code
│   │   └── perf-test.js
│   ├── notes/            # Planning and notes
│   │   └── architecture.md
│   └── temp/             # Truly temporary files
└── settings.json         # Claude settings (NOT scratch)
按用途组织临时文件:
.claude/
├── .scratch/
│   ├── drafts/           # 待完善的实现代码
│   │   └── feature-x.ts
│   ├── experiments/      # 探索性代码
│   │   └── perf-test.js
│   ├── notes/            # 规划与笔记
│   │   └── architecture.md
│   └── temp/             # 纯临时文件
└── settings.json         # Claude配置文件(不属于临时内容)

Best Practices

最佳实践

DO

建议做法

  • Create subdirectories for organization
  • Use descriptive file names
  • Clean up when work is complete
  • Move finalized code to proper project locations
  • 创建子目录进行分类管理
  • 使用具有描述性的文件名
  • 工作完成后及时清理
  • 将定稿代码迁移到项目的正式目录

DON'T

禁止做法

  • Put sensitive data in scratch (still on disk)
  • Use scratch for files that should be committed
  • Leave stale scratch files indefinitely
  • Put scratch files outside
    .claude/.scratch/
  • 在临时目录中存放敏感数据(仍会存储在磁盘上)
  • 用临时目录存放应提交的文件
  • 长期保留过时的临时文件
  • 将临时文件存放在
    .claude/.scratch/
    目录之外

Workflow

工作流程

Starting Exploratory Work

开始探索性工作

bash
undefined
bash
undefined

Create scratch area

创建临时工作区

mkdir -p .claude/.scratch/experiments
mkdir -p .claude/.scratch/experiments

Work on experiment

进行实验工作

... create files in .claude/.scratch/experiments/

... 在.claude/.scratch/experiments/目录下创建文件

undefined
undefined

Promoting to Real Code

迁移为正式代码

When scratch work is ready:
  1. Review and refine the code
  2. Move to appropriate project location
  3. Delete scratch version
  4. Commit the promoted code
当临时工作内容准备就绪时:
  1. 审阅并优化代码
  2. 迁移到项目的对应正式目录
  3. 删除临时版本
  4. 提交迁移后的正式代码

Cleanup

清理工作

Periodically clean scratch:
bash
undefined
定期清理临时工作区:
bash
undefined

Review what's in scratch

查看临时工作区内容

ls -la .claude/.scratch/
ls -la .claude/.scratch/

Remove old experiments

删除旧的实验内容

rm -rf .claude/.scratch/experiments/old-test/
undefined
rm -rf .claude/.scratch/experiments/old-test/
undefined

Integration with Other Tools

与其他工具的集成

With Git

与Git集成

The
.claude/.scratch
directory is gitignored, so:
  • git status
    won't show scratch files
  • git add .
    won't stage scratch files
  • Scratch files won't appear in commits
.claude/.scratch
目录已被git忽略,因此:
  • git status
    不会显示临时文件
  • git add .
    不会暂存临时文件
  • 临时文件不会出现在提交记录中

With IDE

与IDE集成

Most IDEs will show
.claude/.scratch
in the file tree. You can:
  • Add to IDE's exclude patterns
  • Keep visible for easy access
  • Use IDE's "mark as excluded" feature
大多数IDE会在文件树中显示
.claude/.scratch
目录,你可以:
  • 将其添加到IDE的排除模式中
  • 保持可见以便快速访问
  • 使用IDE的“标记为排除”功能

Common Patterns

常见使用模式

Draft Implementation

草稿实现

.claude/.scratch/drafts/
└── new-feature/
    ├── index.ts
    ├── types.ts
    └── test.ts
.claude/.scratch/drafts/
└── new-feature/
    ├── index.ts
    ├── types.ts
    └── test.ts

Performance Experiment

性能实验

.claude/.scratch/experiments/
└── perf-comparison/
    ├── approach-a.ts
    ├── approach-b.ts
    └── benchmark.ts
.claude/.scratch/experiments/
└── perf-comparison/
    ├── approach-a.ts
    ├── approach-b.ts
    └── benchmark.ts

Architecture Notes

架构笔记

.claude/.scratch/notes/
└── refactor-plan.md
.claude/.scratch/notes/
└── refactor-plan.md

Troubleshooting

故障排除

Scratch files appearing in git status

临时文件出现在git status中

bash
undefined
bash
undefined

Verify gitignore entry

验证gitignore中的配置条目

grep -r ".claude/.scratch" .gitignore
grep -r ".claude/.scratch" .gitignore

If missing, add it

如果缺失,添加该配置

echo '.claude/.scratch' >> .gitignore
undefined
echo '.claude/.scratch' >> .gitignore
undefined

Directory doesn't exist

目录不存在

bash
mkdir -p .claude/.scratch
bash
mkdir -p .claude/.scratch

Accidentally committed scratch files

意外提交了临时文件

bash
undefined
bash
undefined

Remove from tracking but keep locally

从版本跟踪中移除但保留本地文件

git rm -r --cached .claude/.scratch git commit -m "chore: remove scratch files from tracking"
undefined
git rm -r --cached .claude/.scratch git commit -m "chore: remove scratch files from tracking"
undefined