CLAUDE_CODE_TMPDIR
Updated by Alex Sorokoletov
CLAUDE_CODE_TMPDIR sets the base directory for Claude Code's internal temp files; Claude Code creates a claude-<uid> subfolder (claude on Windows) inside it. Default: /tmp on macOS; os.tmpdir() on Linux and Windows. Values: A directory path you own. Claude Code creates <path>/claude-<uid> with mode 0700 and refuses it if another user owns it or it is a symlink. Present since v2.1.69 or earlier and still present in v2.1.332. It is listed in the official reference.
| Status | Present in v2.1.332 |
|---|---|
| Added | Present since v2.1.69 or earlier |
| Default | /tmp on macOS; os.tmpdir() on Linux and Windows |
| Values | A directory path you own. Claude Code creates <path>/claude-<uid> with mode 0700 and refuses it if another user owns it or it is a symlink |
| Category | Other |
| Official docs | Listed |
| Checked against | v2.1.330 |
How to set it
For one session, export it in the shell that starts Claude Code:
export CLAUDE_CODE_TMPDIR=$HOME/.cache/claude-tmp
claude$HOME/.cache/claude-tmp /tmp is a small tmpfs or shared with other users.
To apply it to every session, add it to the env object of a settings file:
// ~/.claude/settings.json
{
"env": {
"CLAUDE_CODE_TMPDIR": "$HOME/.cache/claude-tmp"
}
}Known issues
- Sandboxed Bash commands get a short fallback $TMPDIR under the system default when your path is long, because some tools fail on long temp paths. Unsandboxed commands inherit your shell's $TMPDIR when it is set. Source: docs: env vars.
- Session scratchpad folders under this directory are not deleted when a session ends. On a tmpfs /tmp they use RAM and swap, which is a reason to point the variable at a disk path. Source: issue #104612.
Release notes that mention it
Related variables
CLAUDE_TMPDIR: Alternative temp directory; fallback for CLAUDE_CODE_TMPDIR.ANTHROPIC_BETAS: Comma-separated beta feature headers.ANTHROPIC_CUSTOM_HEADERS: Custom HTTP headers (newline-separated Key: Value).ANTHROPIC_FEDERATION_RULE_IDANTHROPIC_ORGANIZATION_IDANTHROPIC_WORKSPACE_IDBETA_TRACING_ENDPOINT: Custom endpoint for beta tracing.CLAUDE_AFK_COUNTDOWN_MS: Milliseconds before the away-from-keyboard timeout at which the warning countdown begins; defaults to 20000 and is capped at the timeout length.
Frequently asked questions
What does CLAUDE_CODE_TMPDIR do?
Sets the base directory for Claude Code's internal temp files; Claude Code creates a claude-<uid> subfolder (claude on Windows) inside it.
What is the default value of CLAUDE_CODE_TMPDIR?
/tmp on macOS; os.tmpdir() on Linux and Windows.
What values does CLAUDE_CODE_TMPDIR accept?
A directory path you own. Claude Code creates <path>/claude-<uid> with mode 0700 and refuses it if another user owns it or it is a symlink.
Which Claude Code version has CLAUDE_CODE_TMPDIR?
Present since v2.1.69 or earlier and still present in v2.1.332.
How do I set CLAUDE_CODE_TMPDIR?
Export it before starting Claude Code (export CLAUDE_CODE_TMPDIR=$HOME/.cache/claude-tmp), or add it to the "env" object in ~/.claude/settings.json to apply it to every session. $HOME/.cache/claude-tmp /tmp is a small tmpfs or shared with other users.
All variables, searchable: Claude Code environment variables.