EACCES: permission denied on Termux/Android - hardcoded /tmp path ignores $TMPDIR
Description
Claude Code fails to execute certain operations on Termux (Android) because it tries to create directories under /tmp/claude/ instead of respecting the $TMPDIR environment variable.
Environment
- Platform: Android (Termux)
- OS: Linux 6.6.77-android15
- Claude Code version: Latest
- $TMPDIR:
/data/data/com.termux/files/usr/tmp
Error
EACCES: permission denied, mkdir '/tmp/claude/-data-data-com-termux-files-home/tasks'
Root Cause
On Android/Termux, /tmp exists but is owned by shell:shell with 0771 permissions. Non-root users cannot create directories there. Termux correctly sets $TMPDIR to a writable location (/data/data/com.termux/files/usr/tmp), but Claude Code ignores this environment variable and hardcodes /tmp.
Expected Behavior
Claude Code should use $TMPDIR (or os.tmpdir() in Node.js which respects it) instead of hardcoding /tmp.
Affected Operations
curlandwgetdownloads- Background task execution
- Agent spawning and task delegation - Agents fail to launch because they cannot create task directories
- Any operation that spawns background processes
Impact
This effectively breaks agent-based workflows on Termux/Android, significantly limiting Claude Code's capabilities on mobile devices.
Workaround
Users must run downloads, background tasks, and agent-equivalent operations directly in terminal, bypassing Claude Code entirely.
Suggested Fix
Replace hardcoded /tmp references with:
const os = require('os');
const tmpDir = os.tmpdir(); // Respects $TMPDIR
Or explicitly check process.env.TMPDIR before falling back to /tmp.
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/15637
- https://github.com/anthropics/claude-code/issues/15628
- https://github.com/anthropics/claude-code/issues/16955
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
Confirmed Bug on v2.1.11: $TMPDIR Still Ignored
Test Environment (Verified)
- Claude Code: 2.1.11 (latest)
- Android: 13
- Device: Samsung Galaxy (aarch64)
- Termux: Latest version
- $TMPDIR:
/data/data/com.termux/files/usr/tmp(set and writable)
Verification Test Results
Test 1: Direct Bash Command
ffmpeg -loop 1 -i photo.jpg -i audio.wav output.mp4 -y
✅ Works - No /tmp/claude errors
Test 2: Agent Spawning (Explore, General-purpose)
Task(subagent_type: 'Explore')
❌ Fails - EACCES: permission denied, mkdir '/tmp/claude/-data-data-com-termux-files-home/tasks'
Evidence of Bug
- $TMPDIR is correctly set to
/data/data/com.termux/files/usr/tmp - But Claude Code still attempts to use
/tmp/claude/hardcoded path - Result: agents cannot spawn, background tasks impossible
Suggested Fix Implementation
Replace hardcoded /tmp/claude with:
const os = require('os');
const path = require('path');
// Respects $TMPDIR environment variable automatically
const tasksDir = path.join(os.tmpdir(), 'claude', 'tasks');
This is exactly as suggested in #15637 - the fix has NOT been applied yet.
Accessibility Note
This affects users with accessibility needs (TalkBack, screen readers) on Android who rely on Claude Code for terminal automation on mobile devices.
Still broken on v2.1.45. Node's os.tmpdir() correctly returns the Termux path, but Claude Code ignores it. Gemini CLI on the same Termux install respects $TMPDIR and works fine. Current workaround: termux-chroot claude which maps /tmp properly.
Fix: Use the built-in CLAUDE_CODE_TMPDIR env var
Claude Code already has an undocumented env var for this. No patching, no chroot needed:
# Add to ~/.bash_profile (Termux)
export CLAUDE_CODE_TMPDIR="$HOME/.tmp"
mkdir -p "$HOME/.tmp"
Restart Termux, launch claude. That's it.
Found by grepping cli.js — the code does process.env.CLAUDE_CODE_TMPDIR||"/tmp" internally. Setting this env var overrides the hardcoded /tmp fallback.
Tested on v2.1.45, Termux, Android 13, aarch64. Both direct bash and agent spawning (Task/Explore) work after this fix.
Workaround: https://github.com/anthropics/claude-code/pull/31701#issuecomment-4017294725
Fix: Use the built-in
CLAUDE_CODE_TMPDIRenv varClaude Code already has an undocumented env var for this. No patching, no chroot needed:
Add to ~/.bash_profile (Termux)
export CLAUDE_CODE_TMPDIR="$HOME/.tmp" mkdir -p "$HOME/.tmp" Restart Termux, launch claude. That's it.
Found by grepping cli.js — the code does
process.env.CLAUDE_CODE_TMPDIR||"/tmp"internally. Setting this env var overrides the hardcoded/tmpfallback.Tested on v2.1.45, Termux, Android 13, aarch64. Both direct bash and agent spawning (Task/Explore) work after this fix.
Thanks alot for this workaround. It is also possible to defined in ~/.claude/settings.json:
{
"env": {
"CLAUDE_CODE_TMPDIR": "$HOME/.tmp"
}
}
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.