Temp file handling: use session-specific directories instead of /tmp

Resolved 💬 4 comments Opened Feb 12, 2026 by kojiromike Closed Mar 13, 2026

Problem

Claude Code writes temporary files directly to /tmp without creating a dedicated subdirectory. This causes several issues:

  1. Collision risk - Multiple Claude sessions (e.g., across git worktrees in the same project) can accidentally overwrite each other's files if they happen to use the same filename
  2. No cleanup - Temp files persist after sessions end with no automatic cleanup
  3. No isolation - Can't tell which session created which file

Workaround doesn't work

I've tried adding guidance to my CLAUDE.md:

**Temporary files:** Keep temp files within the worktree (e.g., `tools/foo/tmp/`), not in `/tmp`. Add a `.gitignore` to exclude them.

Despite this instruction, Claude still frequently requests to write files to /tmp directly. The instruction isn't reliably followed.

Suggested solutions

  1. Session-specific tmpdir - Automatically create /tmp/claude-<session-id>/ for each session and use that for all temp file operations. Clean up on session end.
  1. Configuration option - Allow users to configure temp file behavior in settings, e.g.:
  • tempDir: "session" (creates session-specific dir in system temp)
  • tempDir: "worktree" (creates .claude-tmp/ in working directory)
  • tempDir: "/custom/path" (user-specified location)

Either approach would be better than the current behavior of writing directly to /tmp.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗