Skip to content
Back to skills

Detect Repo Host

ASecurity

Detect repository hosting service (GitHub/GitLab) from git remote and extract owner/repo/project_path. Internal utility skill used by commands that need platform-aware routing.

  • 16 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 26, 2026
developmentbashgitapibackend

Works with

  • api
  • mcp

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add sgaunet/claude-plugins --skill detect-repo-host --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Detect Repo Host?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Detect Repo Host
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sgaunet-detect-repo-host/badge)](https://www.skillsdirectory.com/skills/sgaunet-detect-repo-host)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: detect-repo-host
description: Detect repository hosting service (GitHub/GitLab) from git remote and extract owner/repo/project_path. Internal utility skill used by commands that need platform-aware routing.
user-invocable: false
allowed-tools: Bash(git remote:*)
---

# Detect Repository Host Skill

Detect the repository hosting service from git remote configuration and extract structured metadata for platform-aware command routing.

## Overview

Many commands need to determine whether the current repository is hosted on GitHub or GitLab to route MCP calls correctly. This skill centralizes that detection logic so commands can invoke it via the `Skill` tool instead of duplicating `git remote -v` parsing.

## When to Use

- Before calling GitHub or GitLab MCP tools that require `owner/repo` or `project_path`
- When a command needs to branch logic based on hosting platform
- Any workflow requiring platform-aware routing

## Workflow

### Step 1: Read Git Remotes

```bash
git remote -v
```

Parse the output to find the `origin` remote (or the first available remote if `origin` is not set).

### Step 2: Parse Remote URL

Support both SSH and HTTPS URL formats:

**SSH formats:**
```
git@github.com:owner/repo.git
git@gitlab.com:group/subgroup/project.git
git@gitlab.self-hosted.example.com:group/project.git
```

**HTTPS formats:**
```
https://github.com/owner/repo.git
https://gitlab.com/group/subgroup/project.git
https://gitlab.self-hosted.example.com/group/project.git
```

**Parsing rules:**
1. Strip trailing `.git` suffix if present
2. Extract hostname from URL
3. Extract path segments after hostname

### Step 3: Detect Platform

| Hostname Pattern | Platform |
|-----------------|----------|
| `github.com` | GitHub |
| `gitlab.com` | GitLab |
| Other hostnames | Assume GitLab (self-hosted instances are common) |

### Step 4: Extract Metadata

**For GitHub** (`github.com`):
- `owner`: First path segment (user or organization)
- `repo`: Second path segment (repository name)
- `project_path`: `owner/repo`

**For GitLab** (`gitlab.com` or self-hosted):
- `project_path`: Full path after hostname (supports nested groups, e.g., `group/subgroup/project`)
- `owner`: First path segment (top-level group)
- `repo`: Last path segment (project name)

## Output

Return the following structured information:

| Field | Description | Example (GitHub) | Example (GitLab) |
|-------|-------------|-------------------|-------------------|
| `platform` | Hosting service | `github` | `gitlab` |
| `owner` | User/org/group | `sgaunet` | `myorg` |
| `repo` | Repository name | `claude-plugins` | `myproject` |
| `project_path` | Full path | `sgaunet/claude-plugins` | `myorg/team/myproject` |
| `remote_url` | Raw remote URL | `git@github.com:sgaunet/claude-plugins.git` | `https://gitlab.com/myorg/team/myproject.git` |

## Error Handling

| Condition | Action |
|-----------|--------|
| Not a git repository | Abort: "Not a git repository. Initialize with `git init` first." |
| No remotes configured | Abort: "No git remotes found. Add a remote with `git remote add origin <url>`." |
| No `origin` remote | Fall back to first available remote, warn user |
| URL format unrecognized | Abort: "Could not parse remote URL: `<url>`. Expected GitHub or GitLab format." |

## Examples

### GitHub SSH
```
$ git remote -v
origin  git@github.com:sgaunet/claude-plugins.git (fetch)

→ platform: github
→ owner: sgaunet
→ repo: claude-plugins
→ project_path: sgaunet/claude-plugins
→ remote_url: git@github.com:sgaunet/claude-plugins.git
```

### GitLab HTTPS with Subgroups
```
$ git remote -v
origin  https://gitlab.com/myorg/backend/api-service.git (fetch)

→ platform: gitlab
→ owner: myorg
→ repo: api-service
→ project_path: myorg/backend/api-service
→ remote_url: https://gitlab.com/myorg/backend/api-service.git
```

### Self-Hosted GitLab
```
$ git remote -v
origin  git@gitlab.company.internal:devteam/infra.git (fetch)

→ platform: gitlab
→ owner: devteam
→ repo: infra
→ project_path: devteam/infra
→ remote_url: git@gitlab.company.internal:devteam/infra.git
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.