Bringing Claude Code to Gitea: From GitHub Actions to Self-Hosted Git

GiteaAIClaudeGitHub ActionsOpen Source

When Anthropic released Claude Code Action, it was a game-changer for GitHub users. The ability to have Claude analyze code, implement changes, and provide reviews directly within pull request comments was revolutionary. But there was one problem for those of us running self-hosted Git solutions: it only worked with GitHub.

As someone who uses Gitea for my personal projects, I wanted that same AI-powered workflow in my self-hosted environment. So I built claude-code-gitea-action - a port that brings Claude’s capabilities to Gitea installations.

Claude Code Gitea Action Preview

The Challenge: API Differences and Local Operations

The main challenge in adapting the GitHub Action for Gitea wasn’t just changing API endpoints. While Gitea implements many of GitHub’s APIs for compatibility, there are subtle differences in how certain operations work, especially around file management and branch operations.

Key Technical Differences

  1. File Operations Strategy: The original GitHub Action relies heavily on GitHub’s file API for creating and updating files. Gitea’s API has more limited support for complex file operations, so I switched to using local git commands instead.

  2. Branch Management: While GitHub’s API excels at programmatic branch creation and management, Gitea’s approach required a more traditional git-based workflow using local commands.

  3. Authentication Flexibility: I added support for multiple authentication methods, including Claude Max OAuth credentials for users with subscriptions, in addition to direct API keys.

Implementation Deep Dive

The core architectural change was introducing a gitea-client.ts that handles Gitea-specific API calls while maintaining compatibility with the existing Claude Code framework:

export class GiteaApiClient {
  private baseUrl: string;
  private token: string;

  constructor(token: string, baseUrl: string = GITEA_API_URL) {
    this.token = token;
    this.baseUrl = baseUrl.replace(/\/+$/, ""); // Remove trailing slashes
  }

  // Gitea-specific API implementations...
}

Local Git Operations

Instead of relying on API-based file operations, the Gitea version uses local git commands through a local-git.ts utility:

/**
 * Check if a branch exists locally using git commands
 */
export async function branchExists(branchName: string): Promise<boolean> {
  try {
    await $`git show-ref --verify --quiet refs/heads/${branchName}`;
    return true;
  } catch {
    return false;
  }
}

This approach is more reliable with Gitea’s API limitations and actually provides better performance for file-heavy operations.

Workflow Configuration

The Gitea version includes specific workflow examples that account for Gitea’s event system:

name: Claude Assistant for Gitea

on:
  issue_comment:
    types: [created]
  issues:
    types: [opened, assigned]

jobs:
  claude-assistant:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
      (github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
    runs-on: ubuntu-latest
    steps:
      - uses: markwylde/claude-code-gitea-action
        with:
          gitea_token: ${{ secrets.GITEA_TOKEN }}
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

Enhanced Authentication Options

One improvement I made over the original is supporting multiple authentication methods:

  • Direct Anthropic API (original method)
  • Claude Max OAuth (for subscription users)
  • Amazon Bedrock (for enterprise users)
  • Google Vertex AI (for Google Cloud users)

This flexibility allows teams to use their preferred authentication method and billing structure.

Why This Matters

Self-hosted Git solutions like Gitea are increasingly popular among developers who want:

  • Privacy and Control: Keep code and AI interactions on your own infrastructure
  • Cost Management: Avoid per-seat licensing for large teams
  • Customization: Tailor the Git experience to your organization’s needs

By bringing Claude Code to Gitea, developers can now have AI-powered code assistance without sacrificing the benefits of self-hosted Git.

Real-World Usage

In my own projects, I’ve found the Gitea version particularly useful for:

  • Code Reviews: Automated analysis of pull requests with security and best practice suggestions
  • Documentation: Automatically updating README files when API endpoints change
  • Bug Fixes: Claude can often identify and fix issues directly from screenshots or descriptions

The local git operations actually make certain workflows faster than the GitHub version, especially when dealing with large file changes or multiple commits.

The Open Source Advantage

Building on Anthropic’s open-source foundation made this adaptation possible. The original codebase was well-structured with clear separation between GitHub-specific code and the core Claude integration logic.

Key files that required modification:

  • API client implementation (gitea-client.ts)
  • Local git operations (local-git.ts)
  • Workflow examples (gitea-claude.yml)
  • Authentication handling (OAuth support)

Most of the core Claude Code logic remained unchanged, demonstrating the value of good architectural design in the original implementation.

Getting Started

To try Claude Code with Gitea:

  1. Add the workflow file to your repository’s .gitea/workflows/
  2. Configure your secrets (Gitea token and Claude credentials)
  3. Start using @claude in your issue and PR comments

The setup is straightforward, and the experience is nearly identical to the GitHub version, with the added benefit of running on your own infrastructure.

Looking Forward

This project demonstrates how AI-powered development tools can be adapted across different platforms. As the ecosystem evolves, having choice in where and how we use these tools becomes increasingly important.

The Gitea version is actively maintained and includes all the latest features from the upstream GitHub Action. It’s a testament to the power of open source collaboration and the importance of making AI tools accessible across different platforms.

Whether you’re running Gitea for privacy, cost, or customization reasons, you no longer have to choose between self-hosted Git and AI-powered development assistance. You can have both.

🚀 Try It Yourself

Ready to bring Claude Code to your Gitea installation?

View on GitHub

Complete setup instructions, examples, and documentation