This document summarizes the implementation of the Codebot CLI tool.
Codebot is a CLI tool that automates AI-assisted development tasks by:
- Accepting task prompts in JSON or YAML format
- Cloning repositories into isolated environments
- Running Claude Code CLI in headless mode to make changes
- Committing changes and creating GitHub pull requests
Codebot is organized into four main packages:
runner.py: Implements theruncommand for executing tasks from the CLI- Handles task prompt parsing and validation
- Manages GitHub token validation
- Coordinates with the orchestrator to execute tasks
app.py: Implements theservecommand for starting the webhook serverwebhook_server.py: Flask-based webhook endpoint for GitHub eventsreview_processor.py: Processes PR review comments from the queuereview_runner.py: Specialized Claude runner for review comments
models.py: Data models (TaskPrompt)parser.py: Task prompt parsing (JSON/YAML)utils.py: Utility functions (UUID generation, branch naming, validation)environment.py: Environment manager for isolated workspacesgit_ops.py: Git operations (commit, push, branch management)github_pr.py: GitHub API integration (PR creation, comments)orchestrator.py: Main orchestrator coordinating all components
runner.py: Claude Code CLI integration and executionmd_detector.py: CLAUDE.md file detection
- Main CLI entry point that delegates to
cli_runnerandservermodules - Registers the
runandservecommands - Loads environment variables
TaskPromptdataclass with fields:repository_url(required)description(required)ticket_id(optional)ticket_summary(optional)test_command(optional)base_branch(optional)
- Includes validation for required fields
- Supports both JSON and YAML formats
- Auto-detects format based on content
parse_task_prompt()for string contentparse_task_prompt_file()for file-based parsing
generate_short_uuid(): Creates 7-character UUID hashgenerate_branch_name(): Creates branch names in formatu/codebot/[TICKET-ID/]uuid/short-namegenerate_directory_name(): Creates directory names in formattask_[TICKET-ID_]uuidvalidate_github_app_config(): Validates GitHub App configurationget_git_env(): Returns non-interactive Git environmentextract_uuid_from_branch(): Extracts UUID from branch namesfind_workspace_by_uuid(): Finds workspace directories by UUID
- Creates isolated development environments
- Clones repositories into temporary directories
- Detects default branch (main/master)
- Creates and checks out new branches
- Manages git operations for environment setup
- Supports workspace reuse for PR review comments
- Commits changes with messages
- Pushes branches to remote
- Checks for uncommitted changes
- Retrieves commit hashes and branch names
- Gets commit messages
- Extracts repo owner/name from URLs
- Creates pull requests via GitHub REST API
- Generates PR titles and bodies
- Uses GitHub token for authentication
- Supports both HTTPS and SSH URLs
- Posts PR comments and review comment replies
- Fetches PR details and files changed
- Updates PR descriptions
- Gets comment threads
- Coordinates all components in sequence:
- Parse task prompt
- Setup environment
- Check for CLAUDE.md
- Run Claude Code CLI
- Verify commits
- Push branch
- Create GitHub PR
- Summary output
- Handles errors gracefully
- Preserves work directories for inspection
- Tracks git state before and after Claude runs
- Detects
CLAUDE.mdorAgents.mdfiles - Provides warnings if files are missing
- Supports project-specific guidance for Claude Code
- Checks if Claude Code CLI is installed
- Runs Claude Code in headless mode using
-pflag - Uses comprehensive system prompt that guides AI through engineering workflow
- Uses
--append-system-promptfor additional instructions - Uses
--output-format stream-jsonfor structured output - Extracts Claude's final response from stream output
- Verifies changes were committed
- Retrieves commit messages
- Implements the
serveCLI command - Validates GitHub token and webhook secret
- Starts Flask server and review processor
- Manages server lifecycle
- Receives GitHub webhook events
- Verifies webhook signatures
- Handles three types of PR comments:
- Issue comments (general PR comments)
- Pull request reviews (review summaries)
- Pull request review comments (inline code comments)
- Queues comments for processing (FIFO)
- Filters out codebot's own comments
- Health check endpoint
- Processes review comments from queue sequentially
- Manages workspace reuse and updates
- Classifies comments using Claude AI (query/change request/ambiguous)
- Provides full context to Claude (PR details, code snippets, threads)
- Posts replies to GitHub
- Updates PR descriptions after changes
- Handles errors gracefully
- Specialized Claude runner for PR review comments
- Builds contextual system prompts with:
- PR title and description
- Files changed
- Comment location (file, line, diff hunk)
- Full comment thread
- Handles both queries and change requests
- Extracts Claude's responses
- Implements the
runCLI command - Parses task prompts from files or strings
- Validates GitHub tokens
- Creates and manages work directories
- Coordinates with orchestrator to execute tasks
pyproject.toml: Package configuration with dependenciesREADME.md: Comprehensive documentation and usage examplesexample-task.yaml: Example task prompt file.gitignore: Ignores virtual env and work directories
- Supports both JSON and YAML
- Required fields:
repository_url,description - Optional fields:
ticket_id,ticket_summary,test_command,base_branch - Automatic format detection
- Format:
u/codebot/[TICKET-ID/]<uuid>/<short-name> - UUID is a 7-character hash
- Includes ticket ID if provided
- Includes short name if provided
- Format:
task_[TICKET-ID_]uuid - Simpler format than branch names
- Excludes "u/codebot" prefix
- Headless mode execution
- Comprehensive system prompt with workflow guidance
- Six-step workflow: understand task → plan → implement → test → verify → commit
- Detailed guidelines for code quality, maintainability, and best practices
- Supports
CLAUDE.mdfor project context - Structured JSON output
- Error handling and logging
- Automatic branch creation
- Commit verification
- Push to remote
- Supports existing git credentials
- Automatic PR creation
- Title and body generation
- Ticket ID inclusion
- Task description in PR body
- GitHub API integration
- Graceful error messages
- Work directory preservation on failure
- Verbose mode for debugging
- Clear progress indicators
click: CLI frameworkpyyaml: YAML parsingrequests: GitHub API callspython-dotenv: Environment variable loading from .env files- Standard library:
subprocess,pathlib,json,hashlib,uuid,dataclasses
GITHUB_APP_ID: GitHub App ID (can be set via environment variable or .env file)GITHUB_APP_PRIVATE_KEY_PATH: Path to GitHub App private key fileGITHUB_APP_INSTALLATION_ID: GitHub App installation ID
--task-prompt: Inline task prompt (JSON/YAML)--task-prompt-file: File path to task prompt--work-dir: Base directory for work spaces--verbose: Enable verbose output
- Import test verifies all modules can be imported
- CLI help test verifies command-line interface works
- All Python files compile successfully
As noted in the README:
- Docker/dev container support
- GitHub MCP integration
- Multiple repository support
- Automated cleanup of temporary directories
# Create a task file
cat > task.yaml << EOF
repository_url: https://github.com/user/repo.git
ticket_id: TASK-123
ticket_summary: fix-bug
description: |
Fix the critical bug in the authentication system.
Ensure all tests pass.
EOF
# Run codebot
codebot --task-prompt-file task.yaml-
Temporary Directory Persistence: Work directories are left behind for inspection after task completion or failure
-
UUID Generation: Uses SHA256 hash of UUID4 for deterministic, collision-resistant 7-character IDs
-
GitHub Token Handling: Falls back to environment variable if not provided via command line
-
Claude Code CLI Dependency: Exits gracefully if Claude Code CLI is not installed with helpful error message
-
Error Recovery: Work directories are preserved to allow manual inspection and recovery
-
CLAUDE.md Support: Warns if not found but continues execution, as Claude Code can still work without it