Feature request: export the session scratchpad path as CLAUDE_SCRATCHPAD to Bash-tool processes

Status Open
Maintainer reply None cached
Activity 0 comments · opened Jul 16, 2026

Feature request: export the session scratchpad path as CLAUDE_SCRATCHPAD to Bash-tool processes

What

When Claude Code provisions a per-session scratchpad directory, export its absolute path to Bash-tool child processes as an environment variable — e.g. CLAUDE_SCRATCHPAD. Today the path exists only inside the # Scratchpad Directory system-prompt block; nothing reachable from a tool run names it.

Why

Tools and plugins that shell out want to co-locate their own scratch files with the session's scratchpad — a durable, session-scoped, outside-the-repo place that won't get swept into an auto-snapshot commit. Right now a Bash-tool process cannot discover that directory:

  • It is never written to the transcript (the system prompt is not recorded there).
  • No state file under the session dir records it (session-env/<id>/ is empty).
  • No environment variable exposes it.

The only faithful way to find it from a tool is to reconstruct the path formula — <tmp-realpath>/claude-<uid>/<cwd-slug>/<sessionId>/scratchpad — from CLAUDE_CODE_SESSION_ID (which is in the Bash env) plus the cwd-slug rule. That couples every consumer to an internal, undocumented layout that can change without notice.

Precedent

Claude Code already exports a family of session/config directory paths to child processes — CLAUDE_CODE_SESSION_ID, CLAUDE_CONFIG_DIR, CLAUDE_CODE_DEBUG_LOGS_DIR, CLAUDE_CODE_PLUGIN_CACHE_DIR, and CLAUDE_JOB_DIR for background sessions. CLAUDE_SCRATCHPAD fits that pattern exactly: a path the harness already computes, handed to tools instead of reconstructed.

Proposed behavior

  • When (and only when) the scratchpad is provisioned for the session, set CLAUDE_SCRATCHPAD=<absolute path> in the environment of Bash-tool (and plugin-bin) child processes.
  • Unset/absent when the session has no scratchpad, so consumers can branch on presence.
  • Creating the directory lazily on first use is fine; exporting the path does not require pre-creating it, but a consumer should treat "var set, dir absent" gracefully.

Impact

Removes the need for every shell-based tool to hand-roll the internal path formula, and lets plugins opt into the scratchpad with a one-line ${CLAUDE_SCRATCHPAD:-} check instead of a brittle glob over /tmp/claude-*.

View original on GitHub ↗