Claude Code for GitLab CLI glab — Guide
The Setup
You are using glab, the official GitLab CLI, for managing merge requests, issues, CI/CD pipelines, and repositories from the terminal. glab mirrors GitHub CLI’s workflow but for GitLab, supporting both GitLab.com and self-hosted instances. Claude Code can automate Git workflows, but it defaults to gh (GitHub CLI) commands that do not work with GitLab.
What Claude Code Gets Wrong By Default
-
Uses
ghcommands instead ofglab. Claude writesgh pr createandgh issue list. GitLab uses merge requests, not pull requests, and the command isglab mr createandglab issue list. -
References GitHub-specific features. Claude mentions GitHub Actions, GitHub Pages, and Dependabot. GitLab equivalents are GitLab CI/CD (
.gitlab-ci.yml), GitLab Pages, and Dependency Scanning — different configuration and commands. -
Uses GitHub API endpoints. Claude calls
api.github.comfor automation. glab has its own API command:glab apithat hits your GitLab instance’s API with proper authentication. -
Creates
.github/directory structure. Claude puts workflows in.github/workflows/. GitLab CI configuration goes in.gitlab-ci.ymlat the project root — there is no.github/directory.
The CLAUDE.md Configuration
# GitLab CLI (glab) Project
## Platform
- VCS: GitLab (self-hosted or GitLab.com)
- CLI: glab (official GitLab CLI)
- CI/CD: .gitlab-ci.yml
- Merge Requests: glab mr (not gh pr)
## glab Rules
- Merge requests: glab mr create, glab mr list, glab mr merge
- Issues: glab issue create, glab issue list
- CI/CD: glab ci view, glab ci status
- Pipelines: glab ci list, glab ci retry
- API: glab api /projects/:id/... for custom operations
- Auth: glab auth login for token management
## Conventions
- Use glab for all GitLab operations, never gh
- Merge request titles: conventional commits format
- CI config: .gitlab-ci.yml at project root
- Use glab mr create -f for draft merge requests
- Pipeline status: glab ci status before merging
- Labels: glab mr update --label "review"
- Self-hosted: glab config set -g host gitlab.company.com
Workflow Example
You want to create a merge request with CI pipeline check from the terminal. Prompt Claude Code:
“Create a merge request for the current branch targeting main, with a description summarizing the recent commits. Wait for the CI pipeline to pass, then merge it automatically. Use glab commands.”
Claude Code should run glab mr create --target-branch main --fill to create the MR with auto-filled description from commits, then glab ci status --wait to wait for the pipeline, and finally glab mr merge --when-pipeline-succeeds to auto-merge when CI passes.
Common Pitfalls
-
Self-hosted GitLab not configured. Claude uses glab commands but they hit GitLab.com instead of your self-hosted instance. Run
glab auth login --hostname gitlab.company.comto configure authentication for your instance. -
Missing CI pipeline check before merge. Claude merges immediately with
glab mr merge. Always check pipeline status first withglab ci status— merging with a failed pipeline can break the main branch. -
PR terminology in descriptions. Claude writes “this PR” in merge request descriptions. GitLab uses “merge request” or “MR” terminology — using “PR” indicates the description was not written for GitLab.