Skip to main content

AI-powered terminal manager — control and automate your machines from Telegram

Project description

OneCmd

An AI-powered terminal manager — control and automate your machines from Telegram.

Works on macOS and Linux.

One bot per machine. Each machine needs its own Telegram bot token. Create a separate bot for each machine you want to control (e.g. @my_macbook_bot, @my_server_bot). Only one onecmd instance can use a given bot token at a time.

Quick Start

curl -fsSL https://raw.githubusercontent.com/warlockee/1cmd-ai/main/setup.sh | bash

The setup script handles everything: clones the repo, installs Python dependencies, configures your Telegram bot and AI provider, and starts onecmd.

Or install manually:

git clone https://github.com/warlockee/1cmd-ai.git
cd 1cmd-ai
python3 -m venv .venv
.venv/bin/pip install ".[macos]"   # macOS (or just "." for Linux)
.venv/bin/onecmd --apikey YOUR_BOT_TOKEN

AI Manager

The AI manager is what makes OneCmd powerful. It's an LLM-powered agent that monitors, controls, and automates your terminals — so you can manage servers, run deployments, and debug issues all from a Telegram chat.

Send .mgr to enter manager mode. Your messages go to the AI agent, which can see and interact with all your terminals. Dot commands (.list, .1, etc.) still work normally. Send .exit to leave manager mode.

What it can do

  • List, read, and send commands to any terminal
  • Name terminals for easy identification (proactively suggests names based on content)
  • Execute commands asynchronously and notify you when they finish
  • Queue commands to the same terminal so they don't overlap
  • Auto-detect pending commands at prompts and submit them
  • Follow up on completed commands (results feed back to the LLM)
  • Run repeating background tasks ("watch this terminal until X happens")
  • Detect and recover stuck terminals (Smart Diff — probe, compare before/after)
  • Summarize long conversations to preserve context within token limits
  • Auto-fallback between Gemini and Claude on rate limits
  • Remember things across restarts (persistent memory)

Providers

The manager supports Gemini (Google) and Claude (Anthropic). The provider is selected automatically based on which API key is set. If both are set, Gemini is preferred. Override the model with ONECMD_MGR_MODEL.

# Using Gemini (recommended — fast and free tier available)
GOOGLE_API_KEY=... onecmd --apikey YOUR_BOT_TOKEN

# Using Claude
ANTHROPIC_API_KEY=sk-... onecmd --apikey YOUR_BOT_TOKEN

Standard Operating Procedure

On first run, the manager copies the default SOP to .onecmd/agent_sop.md. This file guides the AI on decision-making and stuck terminal recovery.

To add your own rules, create .onecmd/custom_rules.md:

- Always run tests before deploying
- Never restart the database without asking me first
- Prefer yarn over npm

Custom rules are appended to the default SOP automatically — no need to edit the base file.

Manager commands

Command Action
.mgr Enter AI manager mode
.exit Leave manager mode
.health Manager health report (uptime, memory, stats)

Manual Mode

Manual mode is always available as a stable, reliable fallback. It works without any AI provider — just you and your terminals over Telegram. No API keys, no token limits, no network dependencies beyond Telegram itself. When the AI is down or you need direct control, manual mode is always there.

In manual mode, any text you send is typed directly into the connected terminal as keystrokes.

Command Action
.list List available terminal sessions
.1 .2 ... Connect to a session by number
.rename <N> <name> Name a terminal for easy identification
.help Show all commands
Any other text Sent as keystrokes to the connected terminal

Keystroke Modifiers

Prefix your message with an emoji to add a modifier key:

Emoji Modifier Example
❤️ Ctrl ❤️c = Ctrl+C
💙 Alt 💙x = Alt+X
💚 Cmd macOS only
💛 ESC 💛 = send Escape
🧡 Enter 🧡 = send Enter
💜 Suppress auto-newline ls -la💜 = no Enter appended

Escape Sequences

\n for Enter, \t for Tab, \\ for literal backslash.

How It Works

On macOS, onecmd reads terminal window text via the Accessibility API (AXUIElement), injects keystrokes via CGEvent, and focuses windows using AXUIElement. It works with any terminal app — no Screen Recording permission needed.

On Linux, onecmd uses tmux: tmux list-panes to discover sessions, tmux capture-pane to read content, and tmux send-keys to inject keystrokes. All sessions you want to control must run inside tmux.

In both cases, terminal output is sent as monospace text to Telegram with a refresh button to update on demand.

Linux: tmux requirement

On Linux, onecmd controls tmux sessions. Make sure your work is running inside tmux:

# Start a named session
tmux new -s dev

# Or start detached sessions
tmux new -s server1 -d
tmux new -s server2 -d

Then run onecmd separately (outside tmux or in its own tmux window) and use .list to see your sessions.

Configuration

Options

Flag Description
--apikey <token> Telegram bot API token
--enable-otp Enable TOTP authentication (off by default)
--use-weak-security Disable TOTP even if previously configured
--dbfile <path> Custom database path (default: ./mybot.sqlite)
--dangerously-attach-to-any-window Show all windows, not just terminals (macOS only)
--verbose Enable debug logging

Environment Variables

Variable Default Description
GOOGLE_API_KEY (none) Google API key for the AI manager (Gemini)
ANTHROPIC_API_KEY (none) Anthropic API key for the AI manager (Claude)
ONECMD_MGR_MODEL (auto) LLM model override
ONECMD_VISIBLE_LINES 40 Number of terminal lines to include in output
ONECMD_SPLIT_MESSAGES off Set to 1 to split long output across multiple messages

Terminal output is sent as a single message by default. Each new command or refresh deletes the previous output messages and sends fresh ones, creating a clean "live terminal" view rather than spamming the chat.

If your terminal produces very long output (e.g. build logs) and you want to see all of it, enable splitting:

ONECMD_SPLIT_MESSAGES=1 onecmd --apikey YOUR_BOT_TOKEN

Prerequisites

  • Python 3.11+
  • macOS: Accessibility permission (prompted on first use)
  • Linux: tmux

Manual Run

# Create venv and install
python3 -m venv .venv
.venv/bin/pip install ".[macos]"   # macOS
.venv/bin/pip install .            # Linux

# Run with AI manager
GOOGLE_API_KEY=... .venv/bin/onecmd --apikey YOUR_BOT_TOKEN

# Run without AI manager (manual mode only)
.venv/bin/onecmd --apikey YOUR_BOT_TOKEN

Security

  • Owner lock: The first Telegram user to message the bot becomes the owner. All other users are ignored.
  • TOTP: OTP is off by default for a frictionless first-time experience. Use --enable-otp to set up Google Authenticator — a QR code is shown on first launch. Use --use-weak-security to disable OTP even if previously configured.
  • One bot = one machine: Don't share a bot token across machines. Each machine should have its own bot.
  • Reset: Delete mybot.sqlite to reset ownership and TOTP.

Permissions

macOS: Requires Accessibility permission. macOS will prompt on first use, or grant it in System Settings > Privacy & Security > Accessibility.

Linux: No special permissions needed. Just ensure the user running onecmd can access the tmux socket.

Supported Terminals

macOS: Terminal.app, iTerm2, Ghostty, kitty, Alacritty, Hyper, Warp, WezTerm, Tabby.

Linux: Any terminal running inside tmux.

Architecture

See ARCHITECTURE.md for detailed technical documentation.

License

MIT -- see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onecmd-0.2.2.tar.gz (87.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onecmd-0.2.2-py3-none-any.whl (68.9 kB view details)

Uploaded Python 3

File details

Details for the file onecmd-0.2.2.tar.gz.

File metadata

  • Download URL: onecmd-0.2.2.tar.gz
  • Upload date:
  • Size: 87.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for onecmd-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d4321a8b1d232adc0be95face5d3d1ada84230a8f72335d5101c1d01e35452b0
MD5 cee5d21220b71ad8667d6363847c876e
BLAKE2b-256 4eb740e83accfd924858392d896469c4a9e85b3727f74e3ef25a9a486d14930c

See more details on using hashes here.

File details

Details for the file onecmd-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: onecmd-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 68.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for onecmd-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5507024c1394bb8d7f2704a7851f11697ea86c1ae2c8becdaaf6402e25fe9e69
MD5 a926a10cb65d7160af75a400e403ee0b
BLAKE2b-256 1ff4f41cd2cbf96c6175473315e8b297ca1e966211ff9763da042671199fd153

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page