Claude Code Runner
by @lhl09120
Execute programming tasks via Claude Code using PTY-based invocation. Handles non-TTY environments, auto-responds to prompts, and manages file synchronization.
clawhub install claude-code-runnerπ About This Skill
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.
Features
Installation
# Clone the skill
git clone https://github.com/lhl09120/claude-code-runner-en.gitMake script executable
chmod +x claude-code-runner-en/scripts/run_claude.py
Usage
Basic Usage
from claude_code_runner import run_claude_coderesult = 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
python3 scripts/run_claude.py /path/to/project "Your task description here"
Advanced Options
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 projectprompt (str): Natural language task descriptionuser (str): User to run as (default: 'lighthouse')timeout (int): Timeout in seconds (default: 300)Returns:
str: Combined stdout and stderr outputBehavior: 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
result = run_claude_code(
workdir='/root/repo/project',
prompt='Review this codebase and identify potential bugs or improvements'
)
2. Refactoring Tasks
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
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
result = run_claude_code(
workdir='/root/repo/web-app',
prompt='Fix the memory leak in the WebSocket connection handler'
)
Requirements
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:
Troubleshooting
"Permission denied" errors
Ensure the script is run with sufficient privileges to:
Claude Code not found
Make sure Claude Code is installed and in the system PATH:
which claude
Task timeout
Increase the timeout for long-running tasks:
run_claude_code(workdir, prompt, timeout=600) # 10 minutes
Interactive prompts not auto-responded
Add new prompt patterns to the auto-respond logic:
if b'new prompt text' in output:
os.write(master_fd, b'y\n')
Limitations
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)
β‘ When to Use
π‘ Examples
Basic Usage
from claude_code_runner import run_claude_coderesult = 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
python3 scripts/run_claude.py /path/to/project "Your task description here"
Advanced Options
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
)
βοΈ 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:
π Tips & Best Practices
"Permission denied" errors
Ensure the script is run with sufficient privileges to:
Claude Code not found
Make sure Claude Code is installed and in the system PATH:
which claude
Task timeout
Increase the timeout for long-running tasks:
run_claude_code(workdir, prompt, timeout=600) # 10 minutes
Interactive prompts not auto-responded
Add new prompt patterns to the auto-respond logic:
if b'new prompt text' in output:
os.write(master_fd, b'y\n')