TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/termux/termux-app/llms.txt
Use this file to discover all available pages before exploring further.
RUN_COMMAND intent API lets any Android app start commands inside Termux without building a full terminal integration. Your app sends a structured intent to RunCommandService, which validates it, checks permissions, and forwards it to the core TermuxService for execution in either a foreground terminal session or a background shell.
Prerequisites
Before sending any intent, two conditions must both be satisfied:Enable external apps in termux.properties
Open (or create) The secondary location
~/.termux/termux.properties and add the following line:~/.config/termux/termux.properties is also checked. Without this property set to true, Termux will reject all incoming RUN_COMMAND intents and show a notification warning that an external app attempted access.Service and action
| Item | Value |
|---|---|
| Service class | com.termux.app.RunCommandService |
| Package | com.termux |
| Intent action | com.termux.RUN_COMMAND |
Intent extras reference
Absolute path to the executable or script to run. Must be a regular, readable, executable file. Symlinks are supported — if the path is a symlink (e.g., a busybox/coreutils applet), the symlink path is used directly so that arguments are dispatched correctly.Example:
/data/data/com.termux/files/usr/bin/bashArray of arguments to pass to the executable. When sending via the
am shell command, commas delimit array elements. If an argument itself contains a comma, use the comma alternative character (U+201A ‚) and set com.termux.RUN_COMMAND_REPLACE_COMMA_ALTERNATIVE_CHARS_IN_ARGUMENTS to true.Data to pass to the command on standard input.
Working directory for the command. Defaults to
$HOME (/data/data/com.termux/files/home) when not set. The directory must exist and be readable and writable; Termux will attempt to create it if it falls under an allowed Termux path.When
true, run the command as a background app shell instead of a foreground terminal session. Deprecated — prefer com.termux.RUN_COMMAND_RUNNER instead.Explicit runner selection. Use
"app" for a background app shell or "terminal-session" for a foreground terminal session. Takes precedence over RUN_COMMAND_BACKGROUND when present.Controls how a foreground terminal session is displayed. Only applies when the command runs in a terminal session (not background). See Session action values below.
Optional name to assign to the shell session, visible in the Termux session list.
Human-readable label for this execution command. Shown in error notifications. Defaults to
"RUN_COMMAND Execution Intent Command".Markdown-formatted description of what the command does. Shown in error notifications and reports.
A
PendingIntent that Termux will fire with the execution result once the command completes. The result is delivered in a Bundle extra named "result" containing:| Key | Type | Description |
|---|---|---|
stdout | String | Standard output |
stderr | String | Standard error |
exitCode | int | Process exit code |
err | int | Internal error code (0 = success) |
errmsg | String | Internal error message |
Directory path where result files should be written. When set, Termux writes output files to this directory instead of (or in addition to) delivering a
PendingIntent.When
true, Termux replaces all occurrences of the comma-alternative character (U+201A ‚, or the custom character specified by RUN_COMMAND_COMMA_ALTERNATIVE_CHARS_IN_ARGUMENTS) with normal commas in each argument string. Useful when sending comma-containing arguments via am.Custom character(s) to use as the comma alternative when
RUN_COMMAND_REPLACE_COMMA_ALTERNATIVE_CHARS_IN_ARGUMENTS is true. Defaults to U+201A ‚ if not set.Session action values
Thecom.termux.RUN_COMMAND_SESSION_ACTION extra accepts a string representation of an integer:
| Value | Constant | Behaviour |
|---|---|---|
"0" | SWITCH_TO_NEW_SESSION_AND_OPEN_ACTIVITY | Make the new session current and open TermuxActivity if it is not already running. |
"1" | KEEP_CURRENT_SESSION_AND_OPEN_ACTIVITY | Keep the existing session current and open TermuxActivity if it is not already running. The new session appears in the left sidebar. |
"2" | SWITCH_TO_NEW_SESSION_AND_DONT_OPEN_ACTIVITY | Make the new session current but do not open TermuxActivity. Sessions are accessible from the Termux notification. If TermuxActivity is already running, behaves like 1. |
"3" | KEEP_CURRENT_SESSION_AND_DONT_OPEN_ACTIVITY | Keep the existing session current and do not open TermuxActivity. Sessions are accessible from the Termux notification. If TermuxActivity is already running, behaves like 1. |
Java / Kotlin example
- Java
- Kotlin
Receiving results via PendingIntent
To get stdout, stderr, and the exit code back in your app, create aPendingIntent pointing at a BroadcastReceiver:
BroadcastReceiver:
ADB / am command usage
You can trigger RUN_COMMAND intents from a connected PC or from a root shell using Android’s am tool:
The
--esa flag passes a comma-separated list as a String[]. If any individual argument contains a literal comma, replace it with the alternative comma character (U+201A ‚) and add --ez com.termux.RUN_COMMAND_REPLACE_COMMA_ALTERNATIVE_CHARS_IN_ARGUMENTS true to your am command.How it works internally
WhenRunCommandService receives a valid intent it:
- Verifies the
com.termux.RUN_COMMANDaction is present. - Checks that
allow-external-apps = trueis set intermux.properties. - Validates the executable path (must be a regular, readable, executable file).
- Resolves symlinks but preserves the original path for busybox/coreutils applets so arguments are dispatched to the applet rather than the underlying binary.
- Forwards a new intent to
TermuxServicewith actioncom.termux.service_execute. - Stops itself immediately (
START_NOT_STICKY) —RunCommandServiceis a pass-through and does not remain running.
The full API reference and additional examples are maintained at the RUN_COMMAND Intent wiki page.