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
累计下载
3,862
星标
2
全站排名
#2,701
全站前 54% · 「开发编程」前 61%
平台累计安装累计下载星标评论
ClawHub ↗1013,5131-
SkillHub ↗1003,8622—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

它可切换运行用户、将项目复制到临时目录、执行任务后同步改动,并捕获标准输出与错误;还会自动回答确认提示。运行依赖 Unix 类系统和已安装的 Claude Code,切换用户需要 root 或 sudo 权限。自动确认及回写项目都可能产生实际影响,使用前应检查任务权限、临时副本和同步范围。

资料发布于 2026-10-29

可以用来做什么

  • 为非交互式环境规划 PTY 调用流程。
  • 梳理运行用户、超时和项目同步设置。
  • 检查自动回答确认提示可能带来的副作用。

什么时候用

  • 需要在非交互环境中包装 Claude Code 调用时。
  • 需要了解临时目录、用户切换、超时或输出捕获行为时。
  • 涉及自动确认、root/sudo 权限或将改动同步回项目时,应先审查任务和写回范围。

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

概述 Claude Code Runner 的运行步骤及其自动确认和文件同步行为。
为使用 PTY 包装器前拟定权限、临时文件和回写范围检查清单。

月度数据趋势

累计下载3,862
8602,4724,0842026-03 · 累计下载 1,0822026-05 · 累计下载 2,4962026-06 · 累计下载 2,7252026-07 · 累计下载 3,3362026-08 · 累计下载 3,5172026-09 · 累计下载 3,86226-0326-09
星标2
1222026-03 · 星标 12026-05 · 星标 12026-06 · 星标 12026-07 · 星标 22026-08 · 星标 22026-09 · 星标 226-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。 该技能有同名的其他版本,调整前的数据归属当前下载量最大的这一个。

月份累计下载环比星标
2026-093,862—2
2026-083,517+5.4%2
2026-073,336+22.4%2
2026-062,725+9.2%1
2026-052,496—1
2026-031,082—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),按月更新。口径说明见数据方法。