Granting an AI bot write access to your GitHub repository feels reckless. The first time 365Finds connected Sweep to an active repository, the security team winced: read and write access to repository contents, issues, and pull requests. But watching a vague bug ticket transform into a tested, multi-file pull request within four minutes changes how you think about backlog management.
Sweep positions itself as an autonomous junior developer. Instead of requiring you to babysit an IDE chat window, copy-paste snippets, and manually create branches, Sweep lives directly inside GitHub. It listens for issues, searches your codebase, drafts code, checks for syntax errors, and delivers a complete pull request ready for human code review.
Here is an architectural breakdown of how Sweep turns a GitHub issue into a pull request, alongside the exact permissions and security controls required to let it operate safely.
1. The Trigger: Catching the Issue
Sweep operates entirely event-driven through the GitHub Apps API. It doesn't crawl your repository continuously; it waits for clear signals:
- Issue Titles or Labels: Opening an issue with a title like
Sweep: Add pagination to user APIor attaching thesweeplabel triggers Sweep's webhook listener. - Direct Mentions: Writing
@sweepin an issue description or issue comment directs the bot to take on the ticket. - Specific Scopes: Sweep can be scoped to specific repositories or allowed across an entire GitHub organization.
The Sweep backend catches GitHub's issues.opened or issue_comment.created webhook payloads. At this moment, Sweep extracts the user's intent, parses the bug description or feature request, and initializes a background task.
2. Codebase Retrieval: Semantic Search Without Plaintext Exposure
An AI cannot fix a bug if it doesn't know where the bug lives. Sweeping an entire repository of 500,000 lines of code into a single LLM context window is neither feasible nor cost-effective. Sweep uses a multi-stage retrieval architecture:
[GitHub Issue]
│
▼
[Tree-sitter AST Parser] ──► Chunks Code by Classes & Functions
│
▼
[Redis Vector Cache] ──► SHA-256 Hash Matching (Caches 99% of Unchanged Files)
│
▼
[Embedding Pointers] ──► Retrieves File Paths + Line Ranges (No Plaintext Stored)
│
▼
[Synthesized Context] ──► Selected Source Files Fed to the LLM Plan
- Structural AST Parsing: Using Tree-sitter, Sweep parses code along structural boundaries—classes, methods, and functions—rather than arbitrary 500-token text blocks.
- SHA-256 Incremental Caching: Repositories change incrementally. Sweep hashes code blocks with SHA-256 keys in a Redis cache. A typical git merge alters less than 1% of a codebase; Sweep caches the remaining 99%, keeping re-indexing times to mere seconds.
- Pointer-Based Security: To prevent proprietary code leaks, Sweep’s vector index stores structural pointers (
filename.py:line10:line45) rather than raw source code strings. The actual code snippets are fetched dynamically from repository memory during execution.
3. The Planning & Code Generation Loop
Once the relevant files are isolated, Sweep generates an execution plan before writing a single line of code:
- Public Plan Comment: Sweep posts an implementation plan directly to the GitHub issue. It outlines which files it intends to create, modify, or delete. If the plan looks completely misguided, a maintainer can comment immediately to course-correct.
- Sandboxed Diff Generation: Sweep prompts its underlying LLMs (such as GPT-4 or Claude 3.5 Sonnet) with the issue instructions, repo guidelines, and retrieved snippets. It generates precise unified diffs across the target files.
- Syntax and Lint Verification: If enabled, Sweep verifies whether the generated patch complies with basic syntax trees and linting rules.
4. Branch Creation, CI Integration, and the Pull Request
When the code is ready, Sweep switches from passive reader to active contributor:
- Branch Checkout: Sweep creates an isolated git branch following the convention
sweep/<issue-slug>-<id>. - Commit and Push: It commits the modified files with a descriptive git message detailing the changes.
- Opening the Pull Request: Sweep opens a pull request referencing the original issue (e.g.,
Closes #42). The PR description contains a summary of changes, modified file paths, and confidence notes. - Iterating on CI Failures: If
gha_enabled: trueis set in the repository configuration, Sweep monitors GitHub Actions check runs. If a unit test fails or a linter rejects the code, Sweep parses the CI error logs, generates a patch commit, and pushes it directly to the PR branch.
5. Conversational Code Review
The PR is not a dead end. Sweep supports in-line PR review conversations:
- A reviewer leaves a comment on line 42: "@sweep please use loguru here instead of print, and handle ValueError."
- GitHub fires a
pull_request_review_commentwebhook. - Sweep reads the diff context, the line reference, and the reviewer's feedback.
- It pushes a new commit directly to the branch within 60 to 90 seconds.
At 365Finds, we consider this iterative review cycle Sweep's strongest asset. It matches how senior engineers mentor junior developers: point out the defect in the PR, let the junior push the fix.
6. GitHub App Permissions Required by Sweep
To automate this entire lifecycle, Sweep requires substantive permissions when installed as a GitHub App.
| Scope | Permission Level | Why Sweep Requires It |
|---|---|---|
| Repository Contents | Read & Write | Read source files to build context; create new branches and push code commits. |
| Pull Requests | Read & Write | Open pull requests, write PR descriptions, and respond to review comments. |
| Issues | Read & Write | Read issue prompts, post implementation plans, and add labels or status notes. |
| Workflows / Checks | Read & Write (Optional/Recommended) | Monitor GitHub Actions test logs to detect CI failures and push automated bug fixes. |
| Metadata | Read-Only | Basic GitHub App operational access to repository names and IDs. |
Webhook Event Subscriptions
Sweep subscribes to several real-time webhook events:
issues(opened, edited, labeled)issue_comment(created)pull_request(opened, closed, review requested)pull_request_review_comment(created)check_run(completed, when CI tracking is enabled)
7. Guardrails: Configuring sweep.yaml
Granting write permissions to an external agent requires strict repository guardrails. Sweep allows repository maintainers to place a sweep.yaml configuration file in the repository root:
# Target base branch for pull requests
branch: "main"
# Automatically run GitHub Actions and iterate on CI failures
gha_enabled: true
# Open PRs as drafts so they cannot be accidentally merged
draft: true
# Block Sweep from touching sensitive files or secret configs
blocked_dirs:
- ".github/workflows/"
- "infra/"
- "config/secrets.json"
- "sweepai/core/prompts.py"
# Custom coding rules Sweep must follow
rules:
- "All new public methods must include docstrings and type annotations."
- "Do not use raw print statements; always use the application logger."
- "Ensure unit test coverage is added for every new route."
365Finds strongly advises setting draft: true and locking down .github/workflows/ and all environment configuration directories under blocked_dirs. Sweep should never possess the authority to modify CI pipeline scripts or privilege configurations.
The 365Finds Verdict
At 365Finds, we like tools that eliminate boilerplate toil. Sweep tackles the most tedious part of software development: small bug fixes, missing docstrings, minor refactoring, and straightforward feature flags. When an issue is crisp and well-scoped, Sweep delivers a 90% complete pull request before you finish making coffee.
However, Sweep is not a drop-in replacement for engineering judgment. The permission profile—Contents: Write and Workflows: Write—is substantial. For regulated enterprise codebases or teams with strict IP compliance, self-hosting Sweep's open-source stack or restricting it to staging repositories is non-negotiable.
Set up branch protection rules that require human approvals, ban auto-merges on bot PRs, define blocked_dirs on day one, and treat Sweep like an eager intern: give it tasks, check its work, and never hand it the keys to production.