claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

EACCES: permission denied on Termux/Android - hardcoded /tmp path ignores $TMPDIR

Open JackKnifeAI opened this issue 10 months ago • 1 comments

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

  • curl and wget downloads
  • 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.

JackKnifeAI avatar Jan 15 '26 13:01 JackKnifeAI

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/15637
  2. https://github.com/anthropics/claude-code/issues/15628
  3. 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

github-actions[bot] avatar Jan 15 '26 13:01 github-actions[bot]

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.

salviz avatar Jan 17 '26 07:01 salviz

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.

kingpanther13 avatar Feb 18 '26 12:02 kingpanther13

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.

salviz avatar Feb 20 '26 17:02 salviz

Workaround: https://github.com/anthropics/claude-code/pull/31701#issuecomment-4017294725

rios0rios0 avatar Mar 07 '26 20:03 rios0rios0

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.

Thanks alot for this workaround. It is also possible to defined in ~/.claude/settings.json:

{
  "env": {
    "CLAUDE_CODE_TMPDIR": "$HOME/.tmp"
  }
}

Zhenyi-Wang avatar Mar 13 '26 03:03 Zhenyi-Wang

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Apr 11 '26 10:04 github-actions[bot]

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.

github-actions[bot] avatar Apr 19 '26 14:04 github-actions[bot]