plandex-ai/plandex · warning
Cannot delete main branch
Error message
Cannot delete main branch
What it means
DeleteBranchHandler explicitly rejects deletion of the 'main' branch, returning HTTP 400 'Cannot delete main branch'. This is a deliberate business-rule guard: main is the plan's primary branch and always kept. It is a static validation, not an unexpected failure.
Source
Thrown at app/server/handlers/branches.go:180
auth := Authenticate(w, r, true)
if auth == nil {
return
}
vars := mux.Vars(r)
planId := vars["planId"]
branch := vars["branch"]
log.Println("planId: ", planId)
if authorizePlan(w, planId, auth) == nil {
return
}
if branch == "main" {
log.Println("Cannot delete main branch")
http.Error(w, "Cannot delete main branch", http.StatusBadRequest)
return
}
ctx, cancel := context.WithCancel(r.Context())
err := db.ExecRepoOperation(db.ExecRepoOperationParams{
OrgId: auth.OrgId,
UserId: auth.User.Id,
PlanId: planId,
Branch: "main",
Reason: "delete branch",
Scope: db.LockScopeWrite,
Ctx: ctx,
CancelFn: cancel,
}, func(repo *db.GitRepo) error {
err := repo.GitDeleteBranch(branch)
return err
})View on GitHub (pinned to e2d772072e)
Solutions
- Exclude 'main' from any bulk-delete loop before calling the delete endpoint
- Fix the client to pass the intended non-main branch in the URL path
- Treat this as an expected 400 in client code and skip main silently
Example fix
// before
for _, b := range branches {
client.DeleteBranch(planId, b)
}
// after
for _, b := range branches {
if b != "main" {
client.DeleteBranch(planId, b)
}
} Defensive patterns
Strategy: validation
Validate before calling
// client: never attempt to delete main
if branch == "main" {
return errors.New("refusing to delete main branch")
} Type guard
func isDeletable(branch string) bool { return branch != "main" } Prevention
- Filter 'main' out of bulk-delete lists before iterating
- Double-check the branch variable you pass in the URL path
- Handle 400 for this case gracefully in UI (show 'main is protected')
- Add client-side guard tests for protected branch names
When it happens
Trigger: DELETE to the branch endpoint with branch path variable exactly equal to "main". No other condition produces this error.
Common situations: A client or script iterating all branches and deleting each without excluding main; a UI bug passing the wrong branch variable; manual API testing with main in the path.
Related errors
- Error parsing request body
- User is already a member of org
- Invite already exists
- Error parsing request body
- Error parsing request body
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/fd83abaf03516b44.
Report an issue: GitHub.