CLAUDE_CODE_TMPDIR
mkdir -p /tmp/custom-claude-tmp
CLAUDE_CODE_TMPDIR is an environment variable that overrides the default temp directory where Claude Code stores internal session files, scratchpad, and transient artifacts.
How It Works
Setting CLAUDE_CODE_TMPDIR=/path/to/dir before invoking claude redirects all session-local temp storage to that directory. Claude Code replicates its standard directory hierarchy inside the custom root: {CLAUDE_CODE_TMPDIR}/claude/{project-path}/{session-id}/scratchpad/ and related structures. The project path encodes forward slashes as dashes for filesystem compatibility.
What the Test Found
Runtime testing (2026-01-16, version 2.1.5 on 2.1.9) confirmed the feature works as specified. A custom temp directory was set via environment variable, and Claude Code created its full internal structure at that location without errors. The scratchpad and session isolation remained intact. The layout mirrored the default behavior exactly, confirming no special logic is required at the application level—the override is transparently wired into the runtime's temp-file machinery.
Use Cases and Implications
Five classes of deployments benefit: ramdisk/tmpfs environments requiring fast temp I/O; Docker volumes persisting temp files across container restarts; cluster/NFS filesystems with custom mount points; debugging workflows isolating session artifacts for inspection; quota constraints or security isolation directing temp writes to separate partitions or secured locations.
Caveats
The override is orthogonal to other runtime features (scratchpad functionality, background task disabling, large output persistence). The variable applies session-wide and requires correct path permissions; Claude Code will not create parent directories. If unset, the runtime defaults to the platform's conventional temp location.
- file2.1.5/tests/01-tmpdir-env-var/TEST-RESULTS.md
primitive_6cdaf19393e90d4a5535636aed255199b87705613b1e2fd064d57fa75a6b679d2856ceafad6b1daa8f982493871b6ddaaed35c826362afd1c8f516cc306524c2b718a2ff5676049b770bf10ffec668bfb30adc177769594339d3601a7b304a818b4762cfc709fb216991c39c83bd70eSigned with an ed25519 key held off the repo. Anyone can verify against the published public key; nobody without the secret key can forge it. Click verify: it recomputes the signature in your browser. The signature proves integrity and authorship of this exact content — not a third-party timestamp or that the underlying claim is objectively true. signedAt is when the @f3/attest pipeline ran, not when the work happened; the evidence refs carry the source dates.
- instance-of Skill Runtime Class
- introduces (in) 2.1.5 Test (2.1.5) Release
- verifies (in) CLAUDE_CODE_TMPDIR — runtime test Test