CLAUDE_CODE_TMPDIR

Updated by

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.

StatusPresent in v2.1.332
AddedPresent since v2.1.69 or earlier
Default/tmp on macOS; os.tmpdir() on Linux and Windows
ValuesA 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
CategoryOther
Official docsListed
Checked againstv2.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

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.