https://github.com/sstraus/claude-commander
Run Claude Code with a socket API for programmatic command injection
https://github.com/sstraus/claude-commander
automation claude cli pty rust socket-api
Last synced: 4 days ago
JSON representation
Run Claude Code with a socket API for programmatic command injection
- Host: GitHub
- URL: https://github.com/sstraus/claude-commander
- Owner: sstraus
- License: mit
- Created: 2026-01-30T12:55:49.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-01-30T15:15:00.000Z (about 1 month ago)
- Last Synced: 2026-01-31T06:03:28.737Z (about 1 month ago)
- Topics: automation, claude, cli, pty, rust, socket-api
- Language: Rust
- Size: 25.4 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Claude Commander
Run [Claude Code](https://claude.ai/code) with a socket API for programmatic command injection.
## Features
- **Full TUI**: See Claude Code's interactive UI in your terminal
- **Socket API**: Send prompts via Unix socket / Windows named pipe
- **Zero overhead**: Native Rust binary, ~600KB
- **Cross-platform**: macOS, Linux, Windows
## Installation
### Download binary
Download from [Releases](https://github.com/sstraus/claude-commander/releases):
```bash
# macOS (Apple Silicon)
curl -L https://github.com/sstraus/claude-commander/releases/latest/download/claudec-macos-arm64 -o claudec
chmod +x claudec
# macOS (Intel)
curl -L https://github.com/sstraus/claude-commander/releases/latest/download/claudec-macos-x64 -o claudec
chmod +x claudec
# Linux (x64)
curl -L https://github.com/sstraus/claude-commander/releases/latest/download/claudec-linux-x64 -o claudec
chmod +x claudec
# Linux (ARM64)
curl -L https://github.com/sstraus/claude-commander/releases/latest/download/claudec-linux-arm64 -o claudec
chmod +x claudec
```
### Build from source
```bash
cargo install --git https://github.com/sstraus/claude-commander
```
## Usage
### Start Claude Commander
```bash
claudec
# With arguments for Claude Code
claudec -d /path/to/project
```
This will:
1. Launch Claude Code TUI
2. Detect the session ID from Claude's session file (after logo appears)
3. Start socket server at `/tmp/claudec-.sock` (Unix) or `\\.\pipe\claudec-` (Windows)
4. You can interact via keyboard AND socket API
### Send commands
**Using the Node.js client:**
```bash
node client/claude-send.js send "Hello Claude"
node client/claude-send.js ping
node client/claude-send.js status
```
**Using netcat (Unix):**
```bash
# Replace with the actual session ID shown by claudec
echo '{"action":"send","text":"Hello Claude"}' | nc -U /tmp/claudec-.sock
```
**Using Node.js:**
```js
const net = require('net');
function send(sessionId, cmd) {
const sock = process.platform === 'win32'
? `\\\\.\\pipe\\claudec-${sessionId}`
: `/tmp/claudec-${sessionId}.sock`;
return new Promise((resolve, reject) => {
const c = net.createConnection(sock, () => c.write(JSON.stringify(cmd) + '\n'));
c.on('data', d => { resolve(JSON.parse(d.toString())); c.end(); });
c.on('error', reject);
});
}
await send('abc123-def456', { action: 'send', text: 'Hello Claude' });
```
## API
All commands are JSON objects, newline-delimited.
### send
Send text to Claude Code.
```json
{"action": "send", "text": "Hello Claude"}
{"action": "send", "text": "partial", "submit": false}
```
### keys
Send raw key sequences.
```json
{"action": "keys", "keys": "\\x0d"}
```
Common keys:
- `\x0d` - Enter
- `\x03` - Ctrl+C
- `\x1b` - Escape
- `\x1b[A` - Up arrow
### status
Get session status.
```json
{"action": "status"}
```
## Using from Claude Code Hooks
Hooks receive session info via stdin JSON. Extract `session_id` to build the socket path:
```bash
#!/bin/bash
# Example hook: ~/.claude/hooks/my-hook.sh
# Read hook input from stdin
INPUT=$(cat)
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id')
# Build socket path
SOCKET="/tmp/claudec-${SESSION_ID}.sock"
# Send command to claudec
echo '{"action":"send","text":"Hello from hook!"}' | nc -U "$SOCKET"
```
The hook stdin JSON contains:
```json
{
"session_id": "abc123-def456-...",
"cwd": "/path/to/project",
...
}
```
## Configuration
| Variable | Default | Description |
|----------|---------|-------------|
| `CLAUDE_SOCKET` | `/tmp/claudec-.sock` | Override socket path |
| `CLAUDE_CMD` | `claude` | Claude Code command |
| `CLAUDE_CONFIG_DIR` | `~/.claude` | Claude config directory |
## License
MIT