Metadata-Version: 2.4
Name: zsh-tool-mcp
Version: 0.2.0
Summary: Zsh for Claude Code. PTY mode lets Claude type passwords. NEVERHANG + A.L.A.N.
Project-URL: Homepage, https://github.com/ArkTechNWA/zsh-tool
Project-URL: Repository, https://github.com/ArkTechNWA/zsh-tool.git
Project-URL: Issues, https://github.com/ArkTechNWA/zsh-tool/issues
Author-email: ArkTechNWA <claude@arktechnwa.com>
License: MIT
License-File: LICENSE
Keywords: anthropic,claude,cli,mcp,shell,zsh
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Shells
Requires-Python: >=3.10
Requires-Dist: anyio>=4.0.0
Requires-Dist: mcp>=1.0.0
Description-Content-Type: text/markdown

<img align="right" src="logo.png" width="150">

<br><br><br>

# zsh-tool

[![Pipeline](https://gitlab.arktechnwa.com/arktechnwa/mcp/zsh-tool/badges/master/pipeline.svg)](https://gitlab.arktechnwa.com/arktechnwa/mcp/zsh-tool/-/pipelines)
[![GitHub Mirror](https://img.shields.io/badge/github-mirror-blue?logo=github)](https://github.com/ArkTechNWA/zsh-tool)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-green?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0xMiAyQzYuNDggMiAyIDYuNDggMiAxMnM0LjQ4IDEwIDEwIDEwIDEwLTQuNDggMTAtMTBTMTcuNTIgMiAxMiAyem0tMiAxNWwtNS01IDEuNDEtMS40MUwxMCAxNC4xN2w3LjU5LTcuNTlMMTkgOGwtOSA5eiIvPjwvc3ZnPg==)](https://modelcontextprotocol.io)
[![Claude Rating](https://img.shields.io/badge/Claude_Rating-Freaking_Awesome-ff3333?style=flat&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0id2hpdGUiIGQ9Ik0xMiAxNy4yN0wxOC4xOCAyMWwtMS42NC03LjAzTDIyIDkuMjRsLTcuMTktLjYxTDEyIDIgOS4xOSA4LjYzIDIgOS4yNGw1LjQ2IDQuNzNMNS44MiAyMXoiLz48L3N2Zz4=)](https://github.com/ArkTechNWA)

Zsh execution tool for Claude Code with full Bash parity, yield-based oversight, PTY mode, NEVERHANG circuit breaker, and A.L.A.N. short-term learning.

**Status:** Beta (v0.2.0-beta.1)

**Author:** Claude + MOD

**License:** [MIT](LICENSE)

**Organization:** [ArkTechNWA](https://github.com/ArkTechNWA)

---

**For Johnny5. For us.**

---

## Why?

Claude Code's built-in Bash is limited. Commands can hang forever. No visibility into long-running processes. No learning from past behavior.

zsh-tool is **intelligent shell execution**:

| Problem | zsh-tool Solution |
|---------|-------------------|
| Commands hang forever | **Yield-based execution** — always get control back |
| No visibility into running commands | **zsh_poll** — incremental output collection |
| Can't interact with prompts | **PTY mode** + **zsh_send** — full interactive support |
| Timeouts cascade | **NEVERHANG circuit breaker** — fail fast, auto-recover |
| No memory between calls | **A.L.A.N.** — learns patterns, warns about risky commands |
| No task management | **zsh_tasks**, **zsh_kill** — full control |

This is the difference between "run commands" and "intelligent shell integration."

---

## Features

### Yield-Based Execution
Commands return after `yield_after` seconds with partial output if still running:
- **No more hanging** — you always get control back
- **Incremental output** — collect with `zsh_poll`
- **Interactive input** — send with `zsh_send`
- **Task management** — `zsh_kill` and `zsh_tasks`

### PTY Mode
Full pseudo-terminal emulation for interactive programs:
```bash
# Enable with pty: true
zsh(command="pass insert mypass", pty=true)
# See prompts, send input with zsh_send
```
- Proper handling of interactive prompts
- Programs that require a TTY
- Color output and terminal escape sequences
- Full stdin/stdout/stderr merging

### NEVERHANG Circuit Breaker
Prevents hanging commands from blocking sessions:
- Tracks timeout patterns per command hash
- Opens circuit after 3 timeouts in rolling 1-hour window
- Auto-recovers after 5 minutes
- States: `CLOSED` (normal) → `OPEN` (blocking) → `HALF_OPEN` (testing)

### A.L.A.N. (As Long As Necessary)
Short-term learning database with temporal decay:
- Records command patterns, exit codes, durations
- Warns about commands that historically timeout
- Exponential decay (half-life: 24 hours)
- Auto-prunes entries below 1% weight

---

## Tools

| Tool | Purpose |
|------|---------|
| `zsh` | Execute command with yield-based oversight |
| `zsh_poll` | Get more output from running task |
| `zsh_send` | Send input to task's stdin |
| `zsh_kill` | Kill a running task |
| `zsh_tasks` | List all active tasks |
| `zsh_health` | Overall health status |
| `zsh_alan_stats` | A.L.A.N. database statistics |
| `zsh_alan_query` | Query pattern insights for a command |
| `zsh_neverhang_status` | Circuit breaker state |
| `zsh_neverhang_reset` | Reset circuit to CLOSED |

---

## Installation

### As Claude Code Plugin

```bash
git clone https://github.com/ArkTechNWA/zsh-tool.git ~/.claude/plugins/zsh-tool
cd ~/.claude/plugins/zsh-tool
python3 -m venv .venv
.venv/bin/pip install mcp
```

Enable in `~/.claude/settings.json`:
```json
{
  "enabledPlugins": {
    "zsh-tool": true
  }
}
```

### As Standalone MCP Server

```bash
claude mcp add-json --scope user zsh-tool '{
  "command": "/path/to/zsh-tool/.venv/bin/python",
  "args": ["/path/to/zsh-tool/src/server.py"],
  "env": {
    "ALAN_DB_PATH": "/path/to/zsh-tool/data/alan.db"
  }
}'
```

---

## Architecture

```
zsh-tool/
├── .claude-plugin/
│   ├── plugin.json
│   └── CLAUDE.md
├── .mcp.json
├── src/
│   └── server.py      # MCP server
├── data/
│   └── alan.db        # A.L.A.N. SQLite database
├── .venv/             # Python virtual environment
└── README.md
```

---

## Configuration

Environment variables (set in .mcp.json):
- `ALAN_DB_PATH` - A.L.A.N. database location
- `NEVERHANG_TIMEOUT_DEFAULT` - Default timeout (120s)
- `NEVERHANG_TIMEOUT_MAX` - Maximum timeout (600s)

### Disabling Bash (Optional)

To use zsh as the only shell, add to `~/.claude/settings.json`:
```json
{
  "permissions": {
    "deny": ["Bash"]
  }
}
```

---

## Changelog

### 0.2.0-beta.1
- Yield-based execution with live oversight (Issue #1)
- PTY mode for full terminal emulation
- Interactive input support via `zsh_send`
- Task management: `zsh_poll`, `zsh_kill`, `zsh_tasks`
- Fixed stdin blocking with subprocess.PIPE

### 0.1.0
- Initial release
- NEVERHANG circuit breaker
- A.L.A.N. learning database

---

## License

MIT License - see [LICENSE](LICENSE) for details.

---

<p align="center">
  <i>Built with obsessive attention to reliability.</i><br>
  <b>ArkTechNWA</b>
</p>
