DEV Community

Pavel Mulin
Pavel Mulin

Posted on

How I Integrated an AI Agent into Free GitLab CI/CD

How I made Claude write commits and handle Merge Requests — even on GitLab’s free tier

Automation used to mean “run my tests and deploy my code.”

Now it means “let the AI handle the boring stuff while I focus on the real problems.”

Recently, Anthropic published a guide showing how to connect Claude directly to GitLab CI/CD so it can read, fix, and even commit code automatically.

Here’s the original documentation:

https://docs.claude.com/en/docs/claude-code/gitlab-ci-cd

But there’s one challenge — if you’re using the free version of GitLab, you’ll need to wire things together yourself.

That’s exactly what I did.


The setup that worked for me

To make Claude interact with GitLab, I used two components:

  1. An MCP server – a middleware that allows AI agents to safely talk to external APIs.

    For GitLab, there’s a ready-made module: @zereight/mcp-gitlab.

  2. A webhook handler – a lightweight FastAPI service that listens for GitLab events (new issues, comments, MRs) and triggers the AI workflow.

I open-sourced my implementation here:

https://github.com/Devs-Infrastructure/gitlab-hooks-api

(Bonus: includes a method to register hooks across every project in a GitLab group.)


What I learned

  • On average, each task costs about $1 in Claude API usage — mostly due to code scanning.
  • Occasionally, the CI pipeline behaves unpredictably: the agent might forget to commit changes or stop mid-task.

Still, this kind of automation is becoming a core part of modern development.

The agent handles repetitive chores so humans can focus on design, logic, and innovation.


How to improve the setup

  1. Switch to Cursor CLI – it’s not only more stable and better at model selection,

    but its basic subscription already includes a generous token allowance and native MCP support,

    so you can integrate AI workflows without worrying about API limits.

  2. Add loop control – restrict the number of iterations the agent can run to avoid runaway tasks.

  3. Run post-checks after the agent finishes:


bash
   npm run lint --fix
   npm test
   git add . && git commit -m "AI fixes" && git push
Enter fullscreen mode Exit fullscreen mode

Top comments (0)