holenlin

Claude Code Runner

開發程式設計v0.1.0
作者:holenlin更新於 2026-05-18共 2 個版本 · 最新版本釋出於 2026-02-27claude-code-runner@clawhub_lhl09120/claude-code-runner
程式碼生成指令碼工具

據 AlphaMoat 統計,截至 2026-09,Claude Code Runner 累計下載 3,862 次、獲 2 個星標,在全部 5,078 個 AI 技能中排名第 2,701 位,在「開發程式設計」分類(577 個)中排名第 351 位。

累計安裝
101
累計下載
3862
星標
2
全站排名
#2,701
全站前 54% · 「開發程式設計」前 61%
平台累計安裝累計下載星標評論
ClawHub ↗10135131-
SkillHub ↗10038622—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

它可切換執行使用者、將專案複製到臨時目錄、執行任務後同步改動,並捕獲標準輸出與錯誤;還會自動回答確認提示。執行依賴 Unix 類系統和已安裝的 Claude Code,切換使用者需要 root 或 sudo 許可權。自動確認及回寫專案都可能產生實際影響,使用前應檢查任務許可權、臨時副本和同步範圍。

資料釋出於 2026-10-29

可以用來做什麼

  • 為非互動式環境規劃 PTY 呼叫流程。
  • 梳理執行使用者、超時和專案同步設定。
  • 檢查自動回答確認提示可能帶來的副作用。

什麼時候用

  • 需要在非互動環境中包裝 Claude Code 呼叫時。
  • 需要了解臨時目錄、使用者切換、超時或輸出捕獲行為時。
  • 涉及自動確認、root/sudo 許可權或將改動同步回專案時,應先審查任務和寫回範圍。

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

概述 Claude Code Runner 的執行步驟及其自動確認和檔案同步行為。
為使用 PTY 包裝器前擬定許可權、臨時檔案和回寫範圍檢查清單。

月度資料趨勢

累計下載3862
860247240842026-03 · 累計下載 10822026-05 · 累計下載 24962026-06 · 累計下載 27252026-07 · 累計下載 33362026-08 · 累計下載 35172026-09 · 累計下載 386226-0326-09
星標2
1222026-03 · 星標 12026-05 · 星標 12026-06 · 星標 12026-07 · 星標 22026-08 · 星標 22026-09 · 星標 226-0326-09

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。 該技能有同名的其他版本,調整前的資料歸屬當前下載量最大的這一個。

月份累計下載環比星標
2026-093862—2
2026-083517+5.4%2
2026-073336+22.4%2
2026-062725+9.2%1
2026-052496—1
2026-031082—1

SKILL.md 原文

以下是作者釋出的原始檔案,按純文字顯示,本站未做修改或稽核;其中的連結不可點選,命令請核實後再執行。抓取於 2026-10-23。

5.3 KB · ClawHub v0.1.0
---
name: claude-code-runner
description: "Execute programming tasks via Claude Code using PTY-based invocation. Handles non-TTY environments, auto-responds to prompts, and manages file synchronization."
---

# Claude Code Runner

## Overview

A wrapper skill for running Claude Code programmatically in non-interactive environments. Uses PTY (pseudo-terminal) to handle TTY-required operations and automatically responds to confirmation prompts.
展開全部(共 223 行)

## Features

- **PTY-based execution**: Works in non-TTY environments (containers, CI/CD, background processes)
- **Auto-respond to prompts**: Automatically answers "Do you want to..." confirmations
- **User switching**: Runs as specified non-root user
- **File synchronization**: Copies project to temp directory, executes, syncs changes back
- **Timeout handling**: Configurable timeout with proper cleanup
- **Output capture**: Captures and returns full stdout/stderr

## Installation

```bash
# Clone the skill
git clone https://github.com/lhl09120/claude-code-runner-en.git

# Make script executable
chmod +x claude-code-runner-en/scripts/run_claude.py
```

## Usage

### Basic Usage

```python
from claude_code_runner import run_claude_code

result = run_claude_code(
    workdir='/path/to/project',
    prompt='Refactor the authentication module to use JWT tokens',
    user='lighthouse',
    timeout=300
)

print(result)
```

### Via Command Line

```bash
python3 scripts/run_claude.py /path/to/project "Your task description here"
```

### Advanced Options

```python
result = run_claude_code(
    workdir='/root/repo/my-project',
    prompt='''
    1. Review the codebase
    2. Identify security vulnerabilities
    3. Fix any issues found
    4. Add appropriate tests
    ''',
    user='developer',
    timeout=600  # 10 minutes
)
```

## API Reference

### `run_claude_code(workdir, prompt, user='lighthouse', timeout=300)`

Execute a Claude Code task in a PTY environment.

**Parameters:**
- `workdir` (str): Working directory containing the project
- `prompt` (str): Natural language task description
- `user` (str): User to run as (default: 'lighthouse')
- `timeout` (int): Timeout in seconds (default: 300)

**Returns:**
- `str`: Combined stdout and stderr output

**Behavior:**
1. Copies project to temporary directory
2. Changes ownership to specified user
3. Executes Claude Code via PTY
4. Auto-responds to confirmation prompts
5. Syncs changes back to original directory
6. Cleans up temporary files

## Use Cases

### 1. Automated Code Review

```python
result = run_claude_code(
    workdir='/root/repo/project',
    prompt='Review this codebase and identify potential bugs or improvements'
)
```

### 2. Refactoring Tasks

```python
result = run_claude_code(
    workdir='/root/repo/legacy-app',
    prompt='Refactor the database layer to use SQLAlchemy ORM instead of raw SQL'
)
```

### 3. Adding Features

```python
result = run_claude_code(
    workdir='/root/repo/api-service',
    prompt='''
    Add a new REST endpoint for user profile management:
    - GET /api/users/{id}/profile
    - PUT /api/users/{id}/profile
    - Include validation and error handling
    - Add unit tests
    '''
)
```

### 4. Bug Fixes

```python
result = run_claude_code(
    workdir='/root/repo/web-app',
    prompt='Fix the memory leak in the WebSocket connection handler'
)
```

## Requirements

- Python 3.8+
- Claude Code installed and in PATH
- Unix-like environment (Linux/macOS)
- Root or sudo access (for user switching)

## Configuration

### Environment Variables

- `CLAUDE_CODE_USER`: Default user to run as (default: 'lighthouse')
- `CLAUDE_CODE_TIMEOUT`: Default timeout in seconds (default: 300)

### Customization

Edit `scripts/run_claude.py` to customize:
- Auto-response keywords
- Temp directory location
- Sync behavior
- Output formatting

## Troubleshooting

### "Permission denied" errors

Ensure the script is run with sufficient privileges to:
- Create temporary directories
- Change file ownership
- Switch to target user

### Claude Code not found

Make sure Claude Code is installed and in the system PATH:
```bash
which claude
```

### Task timeout

Increase the timeout for long-running tasks:
```python
run_claude_code(workdir, prompt, timeout=600)  # 10 minutes
```

### Interactive prompts not auto-responded

Add new prompt patterns to the auto-respond logic:
```python
if b'new prompt text' in output:
    os.write(master_fd, b'y\n')
```

## Limitations

- Requires Unix-like environment (uses PTY)
- Requires root/sudo for user switching
- Claude Code must be installed separately
- May not handle all edge cases of interactive prompts

## License

MIT License

Copyright (c) 2026 lhl09120

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

See LICENSE file for full details.

## Changelog

### v1.0.0 (2026-02-27)
- Initial release
- PTY-based Claude Code execution
- Auto-response to confirmation prompts
- File synchronization
- User switching support

「開發程式設計」分類下的熱門技能

資料月份:2026-09 · 下載/星標/安裝數聚合自公開技能註冊庫(ClawHub、SkillHub),按月更新。口徑說明見資料方法。