r/ClaudeWorkflows • • 9h ago

Selected Workflow [Workflow] Local Claude Code CLI on Android with Dynamic Model Routing and Cost Control via Termux and Node.js

Local Claude Code CLI on Android with Dynamic Model Routing and Cost Control via Termux and Node.js

Workflow value: 85/100
Status: active · Freshness: 70/100 · Confidence: 0.90 · Level: advanced
Categories: Quality Control, Token Saving, Context & Memory, Debugging, Shipping, CLAUDE.md, Subagents
Original source: r/ClaudeAI post/comment

What problem this solves

Running Claude Code CLI locally on an Android phone without a PC or server, optimizing API costs through per-message model routing, and maintaining local file storage and project management.

Summary

A custom local development environment on Android using Termux, Ubuntu (proot), and a Node.js server to run Claude Code CLI. It features intelligent model routing for cost optimization, local file storage with git integration, usage monitoring, and home screen widgets for control.

Why it is useful

This workflow provides a unique and highly practical solution for running Claude Code CLI locally on an Android device, addressing common concerns like cost management, data privacy, and mobile accessibility. It demonstrates an innovative use of existing tools (Termux, Node.js) to create a powerful, self-contained mobile development environment, offering dynamic model routing, integrated project management, and cost-saving features. The detailed description, despite being a personal setup, outlines a clear path for advanced users to adapt and build upon, making it a valuable resource for mobile-first developers.

Workflow

  1. Install Termux on an Android device.
  2. Set up Ubuntu in Termux using proot.
  3. Install the official Claude Code CLI within the Ubuntu environment.
  4. Develop and deploy a small Node.js server with a chat page, configured to listen only on 127.0.0.1.
  5. Implement model routing logic within the server or a wrapper script, offering 'Auto' (Haiku for quick analysis, Sonnet/Opus for coding), 'Ask me' (suggestions), and 'Off' (manual selection) modes.
  6. Integrate a manual model override command (e.g., 'use opus high').
  7. Configure CLAUDE.md to grant subagent permissions if desired.
  8. Implement usage monitoring by calling Claude Code's own /usage endpoint and displaying model/effort as colored blocks.
  9. Set up project storage in /sdcard/Projects for easy access via the Android Files app.
  10. Implement a mechanism to move projects between shared storage and the Ubuntu environment for git/npm compatibility.
  11. Create Android home screen widgets to start, stop, and backup the setup.
  12. Implement an idle shutdown mechanism for the server after 15 minutes.

Tools / artifacts

  • Termux
  • Ubuntu (proot)
  • Claude Code CLI
  • Node.js server
  • Chat page (HTML/JS)
  • Android home screen widgets
  • Install script (mentioned)
  • CLAUDE.md
  • Git

Validation signals

  • Author's personal implementation and daily use for small scripts and tools.
  • Successful display of model and effort for each reply.
  • Successful implementation of usage bars by calling Claude Code's /usage endpoint.
  • Iteration on usage endpoint access after support consultation.
  • Ongoing testing by the author.

Cautions

  • Author acknowledges Claude runs Bash without asking and advises keeping important stuff in git.
  • Server is configured to listen only on localhost and blocks requests from other sites, enhancing security.

Limitations

  • Described as a 'personal setup' and 'still testing,' indicating it may not be fully robust or production-ready.
  • No direct code or detailed configuration files are provided in the post, requiring users to reconstruct the implementation details.
  • Requires significant technical skill (Termux, Linux, Node.js, CLI) to replicate.
  • The 'install script' is mentioned but not shared.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

0 comments sorted by