AGENT SKILL

scratch-space

Single source of truth for agent scratch, temporary files, disposable builds, and evidence paths across macOS and Linux. Use whenever an agent, skill, or workflow needs a scratch directory, temporary file path, build output folder, or evidence directory instead of hardcoding /tmp or OS-specific mountpoints.

License 许可
MIT
最近更新
2026-11-14
Stars
★ 6
Forks
0

01 前言 Front Matter

name
scratch-space
description
Single source of truth for agent scratch, temporary files, disposable builds, and evidence paths across macOS and Linux. Use whenever an agent, skill, or workflow needs a scratch directory, temporary file path, build output folder, or evidence directory instead of hardcoding /tmp or OS-specific mountpoints.

02 资源文件 1

03 SKILL.md 正文

Scratch Space (/scratch-space) — Single Source of Truth

Purpose (Ponytail / DRY / ZFC Invariant)

Do not hardcode /tmp/..., /private/tmp/..., /Volumes/diskm-scratch, or ~/Scratch across individual skills, prompts, or agent instruction files.

All temporary, disposable build, test scratch, and evidence paths resolve dynamically through one canonical interface backed by diskm (~/.config/disk-magician/config.json) and exported by default in all shell/agent environments via $DISKM_SCRATCH and $CLAUDE_CODE_TMPDIR:

  1. Default Environment Variables (Pre-exported in ~/.zshenv, ~/.bashrc, ~/.profile, and ~/.claude/settings.json)

    • DISKM_SCRATCH: Pre-set to the host's active Scratch volume (/Volumes/diskm-scratch on macOS, ~/Scratch / ${HOME}/Scratch on Linux).
    • CLAUDE_CODE_TMPDIR: Pre-set to ${DISKM_SCRATCH}/tmp so Claude Code task scratchpads (claude-*) use the Scratch volume automatically by default.
    • PYTEST_DEBUG_TEMPROOT: Pre-set to ${DISKM_SCRATCH}/tmp so pytest debug artifacts and test scratch stay off the host root filesystem.
    • BASH_ENV: Pre-set to $HOME/.bashrc across shell configurations and settings.json so non-interactive agent bash subshells inherit the Scratch environment automatically before any interactive shell guards.
  2. Repo-Scoped Build, Test & Evidence Directories (Managed Lease + Admission)

    # Allocate a managed build or evidence directory. If no Scratch volume is configured,
    # stop and report it: /tmp workspaces are prohibited (see the section below), so the
    # helper must not be used as a /tmp fallback.
    OUT_DIR="$(diskm scratch-new <repo-path> <purpose> --kind build)"
    EVIDENCE_DIR="$(diskm scratch-new <repo-path> <purpose> --kind evidence)"
    
    • Pass --owner-pid <PID> when allocating for a long-lived background process.
    • diskm scratch-new enforces volume health, admission control, 48-hour recency, and active-lease protection.
  3. Ad-Hoc Helper Files, PR Bodies, Frame Dumps, Server Logs & Ephemeral Scripts

    # Resolve the host's active Scratch root (or create/return a subdirectory inside it)
    SCRATCH_ROOT="$(~/.claude/skills/scratch-space/scripts/scratch-dir.sh)"
    SCRATCH_TMP="$(~/.claude/skills/scratch-space/scripts/scratch-dir.sh tmp)"
    
    • Example (gh PR/issue body file):
      BODY_FILE="$(~/.claude/skills/scratch-space/scripts/scratch-dir.sh gh)/pr_body_$$.md"
      
    • Example (ephemeral mktemp directory for video frames, clones, or probes):
      SCRATCH_TMP="$(~/.claude/skills/scratch-space/scripts/scratch-dir.sh tmp)" || {
        echo "Scratch resolver unavailable; refusing allocation" >&2
        exit 75
      }
      [ -n "$SCRATCH_TMP" ] || {
        echo "Scratch resolver returned an empty path; refusing allocation" >&2
        exit 75
      }
      WORK_DIR="$(mktemp -d "$SCRATCH_TMP/work.XXXXXX")" || {
        echo "Scratch allocation failed" >&2
        exit 75
      }
      
    • Example (dev/test server logs):
      LOG_DIR="$(~/.claude/skills/scratch-space/scripts/scratch-dir.sh "logs/${REPO_NAME}/${BRANCH_NAME}")"
      

Task-Scoped Teardown

For an aged task-scratch container, preview with diskm cleanup-task-scratch --dry-run --roots <exact-dedicated-task-parent>. This scans eligible task-container names beneath the supplied root; use it only when that root is dedicated to this task and the preview identifies only its disposable container. Its safety checks preserve live/open paths, secret-like filenames, and containers with dirty or unpushed nested repositories, but it can remove clean, pushed linked worktrees, so do not use it where those are intentional. The filename check is not a scan for secrets inside ordinary files; inspect the disposable scope rather than treating it as content protection. Add --clean only when the preview is correct and removal is authorized.

diskm scratch-prune is a pool-wide C14 cleanup command, dry-run by default; it does not accept an arbitrary single-path target. Do not use it to tear down one task directory. If the existing scoped cleanup command cannot safely identify the task container, leave it in place and report that limitation; never substitute rm -rf on a variable path.

What NOT to Put in Scratch

  • Git worktrees: Always use ~/.worktrees/<repo>/<name> via diskm worktree-new <repo-path> <branch>. Never put git worktrees in Scratch or /tmp.
  • Durable reports & roadmaps: Keep in ~/roadmap/.
  • Mutable agent state, credentials & transcripts: Keep in $HOME (~/.claude, ~/.codex, ~/.gemini, ~/.config).
  • Global TMPDIR: Never remap global TMPDIR or replace /tmp.

Host Provisioning Reference

Operators provision or inspect the quota-bounded Scratch volume via diskm:

  • Provision (optional, recommended 200 GiB): diskm setup --scratch [--quota-gb 200]
  • Query active mountpoint: diskm volume path scratch
  • Check volume status: diskm volume status scratch

/tmp workspaces are prohibited — enforcement depends on the host

A PreToolUse scratch-routing guard, where the host installs one (a hook wired into the active runtime's settings, exit 2 = blocked), rejects tool calls that would create a workspace under /tmp. It fires for git clone/git worktree add/mkdir/mktemp -d/cp/rsync/tar -C/unzip -d/pip --target destinations and for document writes under /tmp.

Why blocking rather than advice: /tmp is on the root filesystem whose free space gates self-hosted runner admission, and lane clones there have drained a CI fleet twice (20 -> 0 containers, then 20 -> 7). Relocating existing directories did not stop new ones appearing, so a host that installs the guard enforces the rule there.

This export does not ship that hook. Enabling it is a host decision; where it is not installed, the rules below are still the required behavior for an agent, and nothing rejects a violation automatically.

/tmp remains correct — and is allowed — for: logs (.log), sockets, pid/lock/marker files, single temp files, .json/.jsonl state, scripts (.sh/.py), pip unpack dirs, X11/ssh-agent/chromium profile dirs. Durable documents belong in the reports repository, never /tmp.

Where the runtime's own temp already points at the scratch volume, the guard covers the Bash commands an agent types, which is where the drift was. A human operator can bypass one call with SCRATCH_GUARD_ALLOW_TMP=1; an agent never sets it on its own behalf. Global TMPDIR is still never remapped and /tmp is never replaced.

04 同仓库更多 Skills

jleechanorg
jleechanorg/jleechan-skills

disk-reclaim-playbook

Use Disk Magician to diagnose disk growth or qualify cleanup on macOS or Linux.

★ 6
jleechanorg
jleechanorg/jleechan-skills

claudea-bench

Compare `claudea` and normal `claude` on a fair split of comparable work by default; use `--strict` for duplicate runs of the exact same task.

★ 6
jleechanorg
jleechanorg/jleechan-skills

pr

Alias for the canonical pr-lifecycle PR workflow skill (/pr-workflow, /prw).

★ 6
jleechanorg
jleechanorg/jleechan-skills

whisper

OpenAI's general-purpose speech recognition model. Supports 99 languages, transcription, translation to English, and language identification. Six model sizes from tiny (39M params) to large (1550M params). Use for speech-to-text, podcast transcription, or multilingual audio processing. Best for robust, multilingual ASR.

★ 6
jleechanorg
jleechanorg/jleechan-skills

webapp-testing

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

★ 6
jleechanorg
jleechanorg/jleechan-skills

pr-report

This skill should be used when the user asks for a PR report, PR audit, PR delta analysis, /pr-report, or wants per-PR summary with delta files/lines. Generates a structured report for one or more open PRs covering purpose, files changed, +/− line counts, /code-standards + /thermo review findings, /ponytail simplification opportunities, file-overlap combination candidates, and /green status per pr-green-definition. Output: machine-readable JSONL + human-readable markdown. Read-only by default; can apply simplifications if user opts in.

★ 6