claude-code-runner
Execute programming tasks via Claude Code using PTY-based invocation. Handles non-TTY environments, auto-responds to prompts, and manages file synchronization.
What this skill does
# 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.
## 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
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.