{
  "id": "a1b2c3d4-0000-4000-8000-000000000000",
  "name": "GitHub Issue \u2192 Claude Fix & PR",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 5
            }
          ]
        }
      },
      "id": "a1b2c3d4-0001-4000-8000-000000000001",
      "name": "Every 5 Minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const staticData = $getWorkflowStaticData('global');\nconst lastChecked = staticData.lastChecked || new Date(Date.now() - 5 * 60 * 1000).toISOString();\nreturn { since: lastChecked };"
      },
      "id": "a1b2c3d4-0002-4000-8000-000000000002",
      "name": "Read Last Checked",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.github.com/search/issues",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.GITHUB_TOKEN }}"
            },
            {
              "name": "Accept",
              "value": "application/vnd.github+json"
            },
            {
              "name": "X-GitHub-Api-Version",
              "value": "2022-11-28"
            }
          ]
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "=is:issue created:>{{ $json.since }} assignee:tupe12334"
            },
            {
              "name": "sort",
              "value": "created"
            },
            {
              "name": "order",
              "value": "asc"
            },
            {
              "name": "per_page",
              "value": "100"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0003-4000-8000-000000000003",
      "name": "Search New Issues",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const staticData = $getWorkflowStaticData('global');\nstaticData.lastChecked = new Date().toISOString();\nconst items = $input.item.json.items || [];\nif (items.length === 0) return [];\nreturn items.map(issue => ({\n  issueNumber: issue.number,\n  issueTitle: issue.title || 'No title',\n  issueBody: issue.body,\n  issueUrl: issue.html_url,\n  repoFullName: issue.repository_url.replace('https://api.github.com/repos/', '')\n}));"
      },
      "id": "a1b2c3d4-0004-4000-8000-000000000004",
      "name": "Extract Issues & Save Cursor",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const issueNumber = $input.item.json.issueNumber;\nconst issueTitle = $input.item.json.issueTitle || 'No title';\nconst issueBody = ($input.item.json.issueBody || 'No description provided.').substring(0, 800);\nconst repoFullName = $input.item.json.repoFullName;\nconst issueUrl = $input.item.json.issueUrl;\nconst repoBase = $env.REPO_BASE_PATH;\nconst repoPath = repoBase + '/' + repoFullName;\nconst repoParent = repoPath.split('/').slice(0, -1).join('/');\nconst cloneUrl = `https://${$env.GITHUB_TOKEN}@github.com/${repoFullName}.git`;\nconst safeRepoName = repoFullName.split('/').join('-');\nconst promptFile = `/tmp/claude-${safeRepoName}-${issueNumber}-prompt.txt`;\nconst scriptFile = `/tmp/claude-${safeRepoName}-${issueNumber}.sh`;\nconst sessionName = `claude-${safeRepoName}-${issueNumber}`;\nconst prompt = `Fix GitHub issue #${issueNumber}: ${issueTitle}\\n\\nRepository: ${repoFullName}\\nIssue URL: ${issueUrl}\\n\\nIssue description:\\n${issueBody}\\n\\nRequirements:\\n- Analyze the issue and implement a complete fix\\n- Add or update tests if applicable\\n- Commit your changes with a descriptive message referencing issue #${issueNumber}\\n- Push the branch and open a pull request that closes #${issueNumber}`;\nconst promptB64 = Buffer.from(prompt).toString('base64');\nconst script = [\n  '#!/bin/bash',\n  'export CLAUDE_CODE_OAUTH_TOKEN=$(cat ~/.claude-ssh-token)',\n  `if [ ! -d \"${repoPath}/.git\" ]; then`,\n  `  mkdir -p \"${repoParent}\"`,\n  `  git clone \"${cloneUrl}\" \"${repoPath}\"`,\n  'fi',\n  `cd \"${repoPath}\"`,\n  `PROMPT=$(cat \"${promptFile}\")`,\n  'exec /opt/homebrew/bin/claude --worktree --dangerously-skip-permissions \"$PROMPT\"',\n  ''\n].join('\\n');\nconst scriptB64 = Buffer.from(script).toString('base64');\nconst command = [\n  `printf '%s' '${promptB64}' | base64 -d > ${promptFile}`,\n  `printf '%s' '${scriptB64}' | base64 -d > ${scriptFile}`,\n  `chmod +x ${scriptFile}`,\n  `/opt/homebrew/bin/tmux new-session -d -s \"${sessionName}\" -x 220 -y 50 ${scriptFile}`\n].join(' && ');\nreturn { command, sessionName, issueNumber, issueTitle, repoFullName };"
      },
      "id": "a1b2c3d4-0005-4000-8000-000000000005",
      "name": "Build tmux Command",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "privateKey",
        "resource": "command",
        "operation": "execute",
        "command": "={{ $json.command }}"
      },
      "id": "a1b2c3d4-0006-4000-8000-000000000006",
      "name": "Run Claude on Host",
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [
        1340,
        300
      ],
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Every 5 Minutes": {
      "main": [
        [
          {
            "node": "Read Last Checked",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Last Checked": {
      "main": [
        [
          {
            "node": "Search New Issues",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search New Issues": {
      "main": [
        [
          {
            "node": "Extract Issues & Save Cursor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Issues & Save Cursor": {
      "main": [
        [
          {
            "node": "Build tmux Command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build tmux Command": {
      "main": [
        [
          {
            "node": "Run Claude on Host",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}