termhub is an AI-native CLI for inspecting and controlling terminal windows, tabs, sessions, handles, and titles.
- Command:
termhub - Alias:
thub - npm package:
@duo121/termhub - macOS backends:
iTerm2,Terminal - Windows backends:
Windows Terminal,Command Prompt (CMD)
npm install -g @duo121/termhubThen let the AI read the contract:
termhub --help
termhub specThe user only needs to ask the AI in natural language.
The user does not need to learn the CLI.
Typical requests:
- "Use termhub to open a fresh iTerm2 window for me."
- "Use termhub to show me every iTerm2 tab I have open."
- "Use termhub to close the tab named Task1."
- "Use termhub to read the last 50 lines from my current Terminal tab."
- "Use termhub to run
npm testin the Windows Terminal tab called API."
User asks the AI:
Use termhub to open a fresh iTerm2 window for me.
AI workflow:
termhub open --app iterm2 --windowThe AI gets JSON with:
- the resolved
target - the backend
result - a reusable
handle/sessionIdfor the new terminal
User asks the AI:
Use termhub to show me every iTerm2 tab I have open.
AI workflow:
termhub list --app iterm2The AI gets JSON with:
- windows
- tabs
- sessions
- handles
- tab titles
- TTYs when the backend exposes them
User asks the AI:
Use termhub to close the tab named Task1.
AI workflow:
termhub resolve --title Task1
termhub close --session <resolved-handle-or-session-id>The AI should not guess.
If resolve returns count: 0 or count > 1, the AI should refine the selector or ask a follow-up question.
User asks the AI:
Use termhub to read the last 50 lines from my current Terminal tab.
AI workflow:
termhub resolve --app terminal --current-window --current-tab --current-session
termhub capture --app terminal --session terminal:session:<window-id>:<tab-index> --lines 50User asks the AI:
Use termhub to run npm test in the Windows Terminal tab called API.
AI workflow:
termhub resolve --app windows-terminal --title API
termhub send --app windows-terminal --session windows-terminal:session:<window-handle>:<tab-index> --text "npm test"The standard pattern is:
- Use
openwhen the user asks the AI to create a new terminal window or tab. - Use
listwhen the user asks what is open. - Use
resolvewhen the user describes a target by title, TTY, current tab, window id, or handle. - Use
send,capture,focus, orcloseonly after the target is exact. - Use
doctorwhen platform, permissions, or automation state are unclear.
Rules the AI should follow:
termhub specis the machine-readable source of truth.termhub --helpandtermhub <command> --helpare the human-readable source of truth.- All command results are printed as JSON to
stdout. openshould prefer a backend whose capabilities advertiseopenWindow/openTab.- If
--appis omitted foropen, termhub prefers the frontmost supported backend that supports the requested scope. --sessionaccepts either a session id or a namespaced handle.- On
send, submit is the default behavior. - Use
--no-enteronly when the payload should remain staged for a later real key press such aspress --key enter. - The AI must not append
\nor other literal newline characters inside--textor stdin to simulate submit. --title-containsand--name-containsare safer when the user gives an approximate label instead of an exact title.- When multiple terminal backends are running, the AI should add
--appfor deterministic targeting. - Use
--dry-runbeforeopen,send,focus, orclosewhen the user wants confirmation or when the action is high-risk. - Apple Terminal supports
--no-enter, but the AI should only use it when it intends to submit separately. - Windows Terminal and CMD use PowerShell/UI Automation for focus, send, capture, and close.
- Windows capture is best-effort and depends on visible text being readable through UI Automation.