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:
- 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
- No cleanup - Temp files persist after sessions end with no automatic cleanup
- 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
- 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.
- 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.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗