Unified AI session manager for Claude Code and Gemini CLI
Project description
ai-cli-utils
Unified AI session manager and automation toolkit for Claude Code and Gemini CLI.
Run multiple AI coding sessions in parallel, each isolated in its own git worktree, with auto-resume, remote server support, cross-machine sync, resilient Gemini API access with automatic auth fallback, and persistent SSH tunnels via autossh.
What it does
ai-cli-utils wraps Claude Code and Gemini CLI in tmux sessions with production workflow features: numbered sessions, git worktree isolation, mosh/SSH remote access, cross-machine memory sync, and session lifecycle management. It also provides ai gemini — a Gemini CLI wrapper with 3-tier auth fallback (OAuth → free API key → paid API key) that automatically retries on capacity errors, so your research prompts keep working even when one auth method is exhausted. If you run multiple AI coding sessions daily, this tool eliminates the boilerplate.
Features
| Feature | Description |
|---|---|
| Session management | ai c 1, ai c 2 — numbered tmux sessions with auto-resume on disconnect |
| Process hygiene | ai ps — inspect and clean up stale ai-cli processes and PID files |
| Session picker | ai ls — fzf-powered session picker sorted by activity; ai attach <name> to attach directly |
| Git worktree isolation | Each session gets its own worktree — parallel work without branch conflicts |
| Remote sessions | ai c -R — run sessions on a remote server via mosh or SSH; Tailscale auto-started if mosh fails (macOS) |
| Cross-machine sync | ai sync push/pull — sync Claude Code memory and conversations between machines |
| Handoff queue | ai handoff post/check/claim/complete — delegate tasks between sessions |
| Fleet messaging | NATS-based heartbeats, events, and sync notifications |
| Stale session cleanup | Automatic detection and cleanup of orphaned sessions |
| Gemini with fallback | ai gemini "prompt" — 3-tier auth fallback (OAuth → free API → paid API), auto-retry on capacity errors |
| SSH tunnels | ai tunnel start/stop/status — persistent reverse tunnels via autossh (auto-reconnects on drop) |
| Signal-watch | Handoff delivery via Circus-managed background process — isolated from CC session lifecycle |
| Notifications | Desktop and push notifications on task completion |
| iTerm2 layout system | ai layout <name> — YAML-driven window/tab/pane definitions; nested splits, startup commands, per-tab profiles |
| iTerm2 session naming | Automatically sets the iTerm2 Session Name and configures allow-passthrough + automatic-rename off so the session title stays correct |
| Runtime tinted icons | Pillow-based PNG icon generation at session launch; auto-contrast tint derived from tab color via HSL color theory |
| Collision-free tab colors | Lease-file-based color slot assignment; each session gets a unique color from a configurable palette |
Installation
uv tool install ai-cli-utils
Or with pipx:
pipx install ai-cli-utils
Quick Start
# Verify install
ai --version
# Launch Claude Code session 1
ai c 1
# Launch a second session in parallel (isolated worktree)
ai c 2
# Launch Gemini CLI session
ai g research
# Resume a disconnected session
ai c -r 1
# Run a session on your remote dev server
ai c -R 1
# Sync Claude Code memory to another machine
ai sync push
Usage
Session management
ai c <name> # Start/resume Claude Code session
ai g <name> # Start/resume Gemini CLI session
ai c -r/--resume # Resume existing session explicitly
ai c -b/--bare # Run bare (no tmux wrapper)
ai c -o/--once # Run once (no auto-resume loop)
ai c -n/--notify # Fire system notifications on task completion
ai c -s/--sandbox # Explicitly enable sandboxing
ai c -W/--no-worktree # Disable git worktree isolation
Remote sessions
ai c -R/--remote <name> # Connect to remote server (uses config)
ai c -R -p/--project myproject <name> # Specify remote project directory
Cross-machine sync
ai sync push [-m] [-n] [-v] [-f] # Push state to remote; aborts if remote has newer files (use -f to force)
ai sync pull [-m] [-n] [-v] [-f] # Pull remote state to local
ai sync conflicts # Show unresolved sync conflicts
ai sync watch [-v] # Watch for sync events via NATS
Flags: -m/--memories-only, -n/--dry-run, -v/--verbose, -f/--force
Gemini with auth fallback
ai gemini "prompt" -m deep-think # Run with 3-tier fallback, stdout + auto file
ai gemini "prompt" -m pro -o output.md # Specify output file
ai gemini "prompt" -m flash -q # File only, no stdout (-q/--quiet)
cat prompt.txt | ai gemini -m deep-think # Pipe from stdin
ai gemini "prompt" -m flash -F # Stdout only, no file (-F/--no-file)
ai gemini "prompt" -m flash -t 120 # 120s timeout (-t/--timeout)
ai gemini "prompt" -m deep-research # Gemini Deep Research (Interactions API, polls until done)
ai gemini "prompt" -m deep-think -s 2 # Skip OAuth, go straight to REST API key
Auth fallback chain (automatic on 429/capacity errors):
- Gemini CLI OAuth (free — Google AI subscription)
- REST API with
GOOGLE_API_KEY_FREE_TIER— Flash/Gemma models only. Pro, image-generation variants, and deep-research have no free quota; tier 2 is skipped automatically for ineligible models. - REST API with
GOOGLE_API_KEY_TIER_1— paid, works for all models.
deep-research uses OAuth first and falls back directly to tier 3 — tier 2 is always skipped for it. Use -s 2 to skip OAuth for Flash calls. For Pro/deep-think where OAuth fails, use -s 3.
Model aliases: deep-think, pro, flash, flash-lite, deep-research, or any full Gemini model ID.
Logs: ~/.local/state/ai-cli/gemini-logs/ (JSONL). Auto output: ~/.local/state/ai-cli/gemini-output/.
Session picker
ai ls # Interactive fzf session picker (installs fzf via apt if absent)
ai ls -a/--all # Show all tmux sessions, not just ai-cli sessions
ai attach <name> # Attach directly to a named tmux session
SSH tunnels
Keep a reverse tunnel alive across network drops (useful for remote browser automation via CDP):
ai tunnel start 9222 # Reverse tunnel: localhost:9222 → server:9222 (auto-reconnects)
ai tunnel start 9222 9223 # Different remote port
ai tunnel start 9222 -L/--forward # Forward tunnel instead of reverse
ai tunnel stop 9222 # Stop the tunnel
ai tunnel status # List all active tunnels
Requires autossh (brew install autossh / apt install autossh). Host/user from [remote] config.
Handoff queue
ai handoff post # Post a task for another session to pick up
ai handoff check # Check for pending handoffs
ai handoff claim # Claim a handoff
ai handoff complete # Mark a handoff as done
iTerm2 layouts
ai layout list # List available layouts in ~/.config/iterm2/layouts/
ai layout validate <name> # Validate YAML schema
ai layout profiles <name> # Regenerate Dynamic Profiles without relaunching window
ai layout <name> # Apply layout: open new iTerm2 window with tabs/panes as defined
Layout files live at ~/.config/iterm2/layouts/<name>.yaml. Each tab can define a base profile, tab color, icon tint, and a root pane with optional nested vertical/horizontal splits, each with a startup directory and command.
Other commands
ai ps # Show ai-cli processes with health scores; flag suspect/stale ones
ai ps --kill # Terminate processes above the suspect threshold
ai signal-watch status # List Circus-managed signal-watch processes
ai memory watch # Watch for Claude Code memory file changes
ai quota watch # Monitor API quota usage
ai telemetry writer # Run telemetry writer daemon
ai update [-f/--force] # Update to latest from source; --force also reinstalls all deps
ai reconnect # Print reconnect commands for remote sessions
Configuration
Claude Code Session Config
This repo ships two Claude Code session config files:
CLAUDE.md— lean config for users with a shared~/projects/CLAUDE.md(managed platform setup), where global AI orchestration rules are inherited from there.CLAUDE-full.md— standalone config with all rules included, for everyone else.
After installing, run ai setup once to automatically detect your environment and configure the right file:
ai setup
ai setup checks for a shared ~/projects/CLAUDE.md. If found, it confirms the lean CLAUDE.md is correct and takes no action. If not found, it copies CLAUDE-full.md → CLAUDE.md and marks the file as assume-unchanged in git so it won't show as locally modified.
Tool Config
Configuration lives in ~/.config/ai-cli/config.toml. A default config is created on first run.
[project]
main_project = "myproject" # default project directory under ~/projects/
[remote]
host = "1.2.3.4" # remote dev server
user = "ubuntu"
transport = "mosh" # "mosh" (default) or "ssh"
# port = 22
# identity_file = "~/.ssh/id_ed25519"
[worktree]
enabled = true # git worktree isolation per session
[session]
stale_session_timeout = 15 # minutes before cleanup considers a session stale
[sync]
remote_host = "user@host" # for cross-machine sync
[behavior]
notify_on_exit = true # desktop notifications on task completion
[machine]
# host_id = "mac" # optional: identify this machine for targeted handoffs (ai handoff --for-machine)
[update]
# extra_venvs = [] # optional: additional venv paths to reinstall into after 'ai update'
iTerm2 Config
iTerm2 visual identity settings live in ~/.config/ai-cli-utils/iterm2.toml (created on first use):
[iterm2.base_profiles]
# Base Dynamic Profile each session type inherits from
cc = "ClaudeCode"
gemini = "GeminiCLI"
shell = "ShellUtility"
[iterm2.project_colors]
# Pin specific projects/sessions to preferred palette colors
# myproject = "purple"
# research = "teal"
[iterm2.icon_color_overrides]
# Override auto-contrast icon tint per palette color slot
# purple = "#da7756"
The color palette (16 entries, configurable) is defined in [iterm2.palette]. Each session gets a collision-free slot via lease files. When a tab color is set, the session icon is automatically tinted with a contrasting color (180° HSL hue rotation). When no color is set, the Claude brand orange (#da7756) is used as fallback.
Set AI_CLI_HOST in ~/.zshenv (sourced by all zsh sessions, including non-interactive ones) to identify the machine. This is used when posting targeted handoffs (ai handoff post --for-machine mac ...):
export AI_CLI_HOST=mac # or "hetzner", "work-laptop", etc.
Requirements
- Python 3.11+
- tmux
- Claude Code and/or Gemini CLI
- mosh (optional, for remote sessions — falls back to SSH)
- autossh (optional, for
ai tunnel—brew install autossh/apt install autossh) - NATS (optional — enables real-time handoff delivery, sync watch, and session events; see NATS Setup Guide)
Contributing
See CONTRIBUTING.md for development setup, testing, and contribution guidelines.
License
MIT -- Sergei Wallace
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_cli_utils-0.3.0.tar.gz.
File metadata
- Download URL: ai_cli_utils-0.3.0.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79437ab860ef0dc853784651ee387107000095b16754c621aec65b7460dfa081
|
|
| MD5 |
3cf19b5ac0db53ca8e682fa020256d9a
|
|
| BLAKE2b-256 |
fd52c10c4db413d018b0a904ef754d7eeddf1ac5bae0ccdcdbaa5f945dd684dc
|
Provenance
The following attestation bundles were made for ai_cli_utils-0.3.0.tar.gz:
Publisher:
publish.yml on sergeiwallace/ai-cli-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_cli_utils-0.3.0.tar.gz -
Subject digest:
79437ab860ef0dc853784651ee387107000095b16754c621aec65b7460dfa081 - Sigstore transparency entry: 1280226700
- Sigstore integration time:
-
Permalink:
sergeiwallace/ai-cli-utils@dd6549399e817814413bc7629e584e2bfdc5630b -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/sergeiwallace
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dd6549399e817814413bc7629e584e2bfdc5630b -
Trigger Event:
push
-
Statement type:
File details
Details for the file ai_cli_utils-0.3.0-py3-none-any.whl.
File metadata
- Download URL: ai_cli_utils-0.3.0-py3-none-any.whl
- Upload date:
- Size: 134.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
520a312fb4946fedf6ee06346ef5d57588377209242b9f6daf79d8e29ff19f25
|
|
| MD5 |
e8f656654f44703d026db562cec326bc
|
|
| BLAKE2b-256 |
4855dc39990b25a0598b18e250768847fd88d2976a41f36424c470207f422a97
|
Provenance
The following attestation bundles were made for ai_cli_utils-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on sergeiwallace/ai-cli-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_cli_utils-0.3.0-py3-none-any.whl -
Subject digest:
520a312fb4946fedf6ee06346ef5d57588377209242b9f6daf79d8e29ff19f25 - Sigstore transparency entry: 1280226702
- Sigstore integration time:
-
Permalink:
sergeiwallace/ai-cli-utils@dd6549399e817814413bc7629e584e2bfdc5630b -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/sergeiwallace
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dd6549399e817814413bc7629e584e2bfdc5630b -
Trigger Event:
push
-
Statement type: