Background agents fail on Termux - hardcoded /tmp path
Status Closed — not planned
Reported on v2.0.76
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 12 comments · opened Dec 29, 2025 · closed Mar 2, 2026
Bug Description
Claude Code uses hardcoded /tmp/claude for background task directories. On Termux/Android, /tmp is not accessible (permission denied).
Error
EACCES: permission denied, mkdir '/tmp/claude/-data-data-com-termux-files-home/tasks'
Expected Behavior
Should use os.tmpdir() (returns /data/data/com.termux/files/usr/tmp on Termux) or respect TMPDIR environment variable.
Environment
- Platform: Android/Termux (linux arm64)
- Claude Code version: 2.0.76
- Node.js
os.tmpdir()returns:/data/data/com.termux/files/usr/tmp
Reproduction
- Install Claude Code on Termux
- Try to spawn background agents using Task tool with
run_in_background: true - Error occurs
Workaround
Using proot wrapper to bind mount tmp:
proot -b /data/data/com.termux/files/usr/tmp:/tmp claude
12 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Comprehensive Root Cause Analysis and Fix Plan
Environment
os.tmpdir(): Returns/data/data/com.termux/files/usr/tmp(correct)TMPDIRenv var: Set correctly by TermuxRoot Cause Analysis
After deep investigation of
cli.js, I identified 6 distinct hardcoded/tmppatterns:
| Pattern | Purpose | Count |
| ----------------------------------------- | ------------------------ | -------- |
|
"/tmp/claude"| Main temp directory | Multiple ||
"/private/tmp/claude"| macOS alias | 1 ||
"/tmp/claude/"| Trailing slash variant | Multiple ||
"/tmp/claude_cli_latest_screenshot.png"| Screenshot capture | 1 ||
"/tmp/workspace"| Workspace sandbox | 1 ||
"TMPDIR=/tmp/claude"| Sandbox env override | 1 |Critical Finding
The most problematic issue is in the sandbox environment setup function which
explicitly overrides TMPDIR:
This means even though Termux correctly sets
TMPDIR=/data/data/com.termux/files/usr/tmp, the sandbox overwrites it withthe hardcoded
/tmp/claude.Why
/tmpFails on TermuxThis is Android's security model - apps are sandboxed and cannot write to system
/tmp.Affected Features
| Feature | Status | Reason |
| --------------------- | --------- | -------------------------------------------- |
| Main CLI | ✅ Works | Uses different path for CWD tracking |
| Task tool (subagents) | ❌ Broken | Tries
/tmp/claude/.../tasks|| Background agents | ❌ Broken | Same path issue |
| Explore agent | ❌ Broken | Same path issue |
| Screenshots | ❌ Broken | Uses
/tmp/claude_cli_latest_screenshot.png|Suggested Fix
Replace hardcoded paths with platform-aware paths using Node.js built-in:
Critical: The sandbox TMPDIR override in
yA1()should also useos.tmpdir():Workaround (for affected users)
I've created an automated patch script that:
cli.jswith SHA256 verificationThe workaround is available but requires re-application after every npm
update.
Recommendations for Official Fix
/tmpreferences in the codebaseos.tmpdir()consistently - it already respects TMPDIR on allplatforms
Additional Context
os.tmpdir()on Termux correctly returns/data/data/com.termux/files/usr/tmp/tmphas restricted permissionsI'm happy to help test any proposed fixes or provide additional debugging
information.
Patch Implementation Update
Successfully implemented and tested automated patch solution:
Patch Statistics:
Verification Results:
Replaced Patterns:
| Original | Count |
|----------|-------|
|
"/tmp/claude"| 5 ||
"/tmp/claude/"| 1 ||
"/tmp/claude_cli_latest_screenshot.png"| 2 ||
"/private/tmp/claude"| 1 ||
"/tmp/workspace"| 1 ||
"TMPDIR=/tmp/claude"| 1 |Automated Solution Features:
The patch script is working reliably. Happy to share the implementation details if helpful for the official fix.
Bug fix update: Patch script now preserves executable permissions.
Issue:
mktempcreates files with0600perms. Whenmvreplacescli.js, the executable bit is lost, breaking the/usr/bin/claudesymlink.Fix: Added
chmod 700 cli.jsaftermvin patch script.This edge case only affects systems where
cli.jsis executed directly via symlink (like npm global installs).✅ Full Verification Complete
All previously blocked features now work after applying the patch:
| Feature | Before Patch | After Patch |
|---------|--------------|-------------|
| Task tool (subagents) | ❌ EACCES | ✅ Working |
| Background agents | ❌ EACCES | ✅ Working |
| Explore agent | ❌ EACCES | ✅ Working |
| Plan agent | ❌ EACCES | ✅ Working |
| General-purpose agent | ❌ EACCES | ✅ Working |
| Parallel agent spawning | ❌ EACCES | ✅ Working |
| Temp directory writes | ❌ EACCES | ✅ Working |
The root cause is confirmed: Hardcoded
/tmp/claudepaths fail on Termux due to Android's permission model. Replacing withos.tmpdir()or respectingTMPDIRenv var resolves the issue completely.Patch implementation archived for reference. Happy to assist with testing any official fix.
Thank you for sharing this. Can confirm the issue still exists.
Worked for me!!
This breaks rg for me
We're saved!
Changelog
2.1.5
Added CLAUDE_CODE_TMPDIR environment variable to override the temp directory used for internal temp files, useful for environments with custom temp directory requirements
Confirming: proot workaround is the ONLY working solution
Testing on Termux with properly configured environment variables:
Result: Claude Code still fails with
EACCES: permission denied, mkdir '/tmp/claude/...'This confirms the path is hardcoded and ignores:
$TMPDIR$CLAUDE_CODE_TMPDIRos.tmpdir()in Node.jsEnvironment
Confirmed Working Workaround
Your proot solution is currently the only working method:
Request
Can we get a status update on implementing proper
$TMPDIR/os.tmpdir()support? There are now 8+ duplicate issues for this problem affecting all Termux users.---
Tested and reported via Claude Code on Termux
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
Workaround: https://github.com/anthropics/claude-code/pull/31701#issuecomment-4017294725
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.