{"slug": "from-github-issue-to-pull-request-running-claude-code-unattended", "title": "From GitHub Issue to Pull Request: Running Claude Code Unattended", "summary": "Sortie, an open-source tool, automates the process of turning GitHub issues into pull requests by running Claude Code in isolated workspaces with retry logic and state persistence. The tool eliminates manual babysitting by polling for labeled issues, executing agents, and opening PRs without developer intervention.", "body_md": "You already run Claude Code by hand: copy issues into a prompt, watch it work, check the diff, and if something breaks halfway through, you restart it. This works fine for one task at a time, but it falls apart when you have 10 tasks simultaneously.\n\nClaude Code is good at handling routine engineering tasks: bug fixes, dependency bumps, and small features, when the prompt is clear and the task is scoped. But when it comes to scaling, you need an infrastructure with isolated workspaces, retry logic, state that survives a restart, and tracker integration, not to waste time on babysitting.\n\n[Sortie](https://github.com/sortie-ai/sortie) removes the manual work. You label an issue, Sortie picks it up, creates an isolated workspace, runs the agent, retries it if it stalls, and opens a pull request when it's done. This article describes how to set the entire process from an empty directory to a GitHub issue turning into a PR without you touching the keyboard in between.\n\nA GitHub repository you control\n\nExport two environment variables:\n\n`ANTHROPIC_API_KEY`\n\n- authenticates Claude Code`GITHUB_TOKEN`\n\n- it's read by `tracker.api_key: $GITHUB_TOKEN`\n\nfor polling/updating issues, and it's the same token `gh pr create`\n\ninside the `after_run`\n\nhook uses to open the PR, so it needs Issues: read/write, Contents: read, and Pull requests: read/write scopes on that repository, all on one fine-grained PAT.Push access to the repository over SSH. The `after_create`\n\nhook below clones with `git@github.com:...`\n\n, so git authenticates with your SSH key, not with `GITHUB_TOKEN`\n\n. Verify with `ssh -T git@github.com`\n\n. If you'd rather stay on one credential, swap the clone URL for `https://${GITHUB_TOKEN}@github.com/yourorg/yourrepo.git`\n\nand give the token Contents: read/write.\n\nIn your repository, create the `agent-ready`\n\nlabel — you need it to exist before you can put it on an issue, and `query_filter`\n\nfinds nothing without it. Creating `in-progress`\n\n, `review`\n\n, and `done`\n\nup front is also worth doing: GitHub does create a missing label when Sortie applies it, but it comes out in default gray, and the colors are yours to pick.\n\nClaude Code installed on your machine. Verify with command: `claude --version`\n\nThe entire process takes about 15 minutes.\n\nTo install Sortie on Linux or macOS, run the command:\n\n```\ncurl -sSL https://get.sortie-ai.com/install.sh | sh\n```\n\nFor Homebrew:\n\n```\nbrew install --cask sortie-ai/tap/sortie\n```\n\nOn Windows, use the PowerShell equivalent. It runs on the PowerShell 5.1 that ships with Windows 10 and 11, as well as on PowerShell 7:\n\n```\nirm 'https://get.sortie-ai.com/install.ps1' | iex\n```\n\nThat one installs into `%LOCALAPPDATA%\\Programs\\sortie`\n\n, so it needs no administrator rights, and it adds the directory to your user `PATH`\n\nfor you. Shells you already have open keep their old environment, so reopen PowerShell before continuing.\n\nSortie is a single Go binary file, for which you need no database server, Docker, or Node.js. State lives in an embedded SQLite file (`.sortie.db`\n\n) that Sortie creates next to your workflow file — no need to create it manually.\n\nConfirm it's on your `PATH`\n\nby running the command:\n\n```\nsortie --version\n```\n\nThis file contains everything you need for Sortie, including trackers to pull tasks from, agents to run, and prompts telling them what to do. Create a directory and a file.\n\n```\n---\ntracker:\n  kind: github\n  api_key: $GITHUB_TOKEN\n  project: yourorg/yourrepo\n  query_filter: \"label:agent-ready\"\n  active_states:\n    - agent-ready\n    - in-progress\n  in_progress_state: in-progress\n  handoff_state: review\n  terminal_states:\n    - done\n\npolling:\n  interval_ms: 30000\n\nworkspace:\n  root: ./workspaces\n\nhooks:\n  after_create: |\n    git clone --depth 1 git@github.com:yourorg/yourrepo.git .\n  before_run: |\n    git fetch origin main\n    git checkout -B \"sortie/${SORTIE_ISSUE_IDENTIFIER}\" origin/main\n  after_run: |\n    git add -A\n    git diff --cached --quiet || \\\n      git commit -m \"sortie(${SORTIE_ISSUE_IDENTIFIER}): automated changes\"\n    git push origin \"sortie/${SORTIE_ISSUE_IDENTIFIER}\" --force-with-lease\n    gh pr create --fill \\\n      --head \"sortie/${SORTIE_ISSUE_IDENTIFIER}\" \\\n      --base main 2>/dev/null || true\n  timeout_ms: 120000\n\nagent:\n  kind: claude-code\n  command: claude\n  max_turns: 5\n  max_concurrent_agents: 1\n  turn_timeout_ms: 1800000\n  stall_timeout_ms: 300000\n\nclaude-code:\n  permission_mode: bypassPermissions\n  max_budget_usd: 5\n  max_turns: 50\n\nserver:\n  port: 8888\n---\n\nYou are a senior engineer working in this repository. Your work is tracked by\nan automated orchestrator (Sortie) that manages your session, retries failures,\nand monitors progress.\n\n## Task\n\n**#{{ .issue.identifier }}**: {{ .issue.title }}\n{{ if .issue.description }}\n\n### Description\n\n{{ .issue.description }}\n{{ end }}\n{{ if .issue.url }}\n\n**Ticket:** {{ .issue.url }}\n{{ end }}\n\n## Rules\n\n1. Read existing code and project conventions before writing anything new.\n2. Keep changes minimal. Implement exactly what the task requires.\n3. Run the project's lint and test commands before finishing. All checks must pass.\n4. Write tests for new functionality, covering edge cases, not just the happy path.\n{{ if not .run.is_continuation }}\n\n## First run\n\nStart by understanding the codebase structure. Check for existing patterns\nand follow them. Write the implementation, add a test, and verify everything passes.\n{{ end }}\n{{ if .run.is_continuation }}\n\n## Continuation (turn {{ .run.turn_number }}/{{ .run.max_turns }})\n\nYou are resuming this task. Run `git status` and check test output to understand\nthe current state. Continue from where the previous turn left off. Do not repeat\nwork already completed.\n{{ end }}\n```\n\nThe file consists of two parts. Everything between the two --- markers is YAML front matter for configuration. Everything after the closing --- is a Go text/template, rendered separately for each issue and sent to the agent as its prompt.\n\nIn this file:\n\n`query_filter: \"label:agent-ready\"`\n\n- Sortie only takes issues with this label. If the label is missing, it ignores the issue.`active_states`\n\n/ `in_progress_state`\n\n/ `handoff_state`\n\n/ `terminal_states`\n\n- a status map through GitHub labels. `active_states`\n\nmust include `in_progress_state`\n\n, otherwise Sortie refuses to start and `sortie validate`\n\nfails with a config error (enforced in code). `handoff_state`\n\nmust not match any of `active_states`\n\nor `terminal_states`\n\n(also enforced in code).`agent.max_turns: 5`\n\n- how many turns the orchestrator runs within one session: the first turn plus up to four continuations. Defaults to 20.`claude-code.max_turns: 50`\n\n- how many internal steps Claude Code itself takes in a single invocation. These are two different fields that happen to share a name, in different sections. At 5x50, that's up to 250 steps per task.`claude-code.max_budget_usd: 5`\n\n- a cost cap per invocation, not per session. Sortie passes `--max-budget-usd`\n\non every turn and Claude Code's counter starts from zero each time, so with `agent.max_turns: 5`\n\nthe worst case for one issue is five turns of $5, not $5 total. The cap is also checked at the turn boundary rather than mid-turn, so a single turn can overshoot it. To bound one issue, size it as `budget x max_turns`\n\nand lower one of the two.`permission_mode: bypassPermissions`\n\n- lets the agent act without stopping to ask for approval on each step; run it against a repository you control. Setting it explicitly is the right move, but omitting it does not make the run interactive: the adapter then falls back to the deprecated `--dangerously-skip-permissions`\n\n, which bypasses the same checks.Before running the config, do the following steps:\n\n`yourorg/yourrepo`\n\nwith your repository (URL cloning) in `tracker.project`\n\nand `hooks:after_create`\n\n.`cmd.exe /C`\n\nrather than `sh -c`\n\n, so write `%SORTIE_ISSUE_IDENTIFIER%`\n\ninstead of `${SORTIE_ISSUE_IDENTIFIER}`\n\nand drop the trailing `\\`\n\nline continuations.`sortie validate ./WORKFLOW.md`\n\nCreate a test issue with the `agent-ready`\n\nlabel and add the description, for example, “Add a /healthz endpoint returning 200” — the more specific your description is, the more specific result you get.\n\nRun the `sortie ./WORKFLOW.md`\n\nand watch the running process in the dashboard.\n\nAll git operations are Sortie's hooks:\n\n`after_create`\n\n— clones the repository into an isolated workspace under its working directory.`before_run`\n\n— creates the `sortie/<issue-identifier>`\n\nbranch off `origin/main`\n\n.`after_run`\n\n— stages, commits, pushes, and runs `gh pr create --fill`\n\nto open the actual PR.`in-progress`\n\nlabel for `review`\n\n. The `agent-ready`\n\nlabel is already gone by then — Sortie replaced it with `in-progress`\n\nback when it picked the issue up.In its turn, Claude Code edits the file in the isolated workspace.\n\nIf a run doesn’t go smoothly, here’s what happens, and how Sortie recovers on its own:\n\n`agent.max_retry_backoff_ms`\n\n(5 minutes by default). The issue tries again on its own.`stall_timeout_ms`\n\n(5 minutes by default), Sortie treats the session as dead, kills it, and requeues the issue for retry.`claude-code.max_budget_usd`\n\ncaps spend per session, independent of how many turns it takes. Combine it with `agent.max_concurrent_agents`\n\nto bound total exposure across everything running at once.`WORKFLOW.md`\n\n. If you kill the process and start it again, nothing is lost, and nothing gets dispatched twice.To switch the agent, change the line: swap `agent.kind: claude-code`\n\nfor `codex`\n\n, `copilot-cli`\n\n, `opencode`\n\n, or `kiro`\n\n, and the tracker configuration stays exactly as it is.\n\nJira, Linear, and Gitea work the same way on the tracker side - same file, different `tracker.kind`\n\n. Sortie also supports a CI feedback loop, where a failing check on the opened PR gets routed back to the agent instead of left for you to notice.\n\nFor full configuration reference and adapter details, check [docs.sortie-ai.com](https://docs.sortie-ai.com). Source and issue tracker: [github.com/sortie-ai/sortie](https://github.com/sortie-ai/sortie).", "url": "https://wpnews.pro/news/from-github-issue-to-pull-request-running-claude-code-unattended", "canonical_source": "https://dev.to/serghei/from-github-issue-to-pull-request-running-claude-code-unattended-2d6o", "published_at": "2026-07-27 15:42:39+00:00", "updated_at": "2026-07-27 16:02:53.017938+00:00", "lang": "en", "topics": ["developer-tools", "ai-agents", "ai-tools", "large-language-models"], "entities": ["Sortie", "Claude Code", "GitHub", "Anthropic"], "alternates": {"html": "https://wpnews.pro/news/from-github-issue-to-pull-request-running-claude-code-unattended", "markdown": "https://wpnews.pro/news/from-github-issue-to-pull-request-running-claude-code-unattended.md", "text": "https://wpnews.pro/news/from-github-issue-to-pull-request-running-claude-code-unattended.txt", "jsonld": "https://wpnews.pro/news/from-github-issue-to-pull-request-running-claude-code-unattended.jsonld"}}