Claude Skills Guide

How to Use Claude Code with Existing GitHub Repo

Connecting Claude Code to an existing GitHub repository transforms how you work with established codebases. Rather than starting fresh, you can use AI assistance directly within projects that already have history, tests, and infrastructure in place. For beginner resources, check the getting started hub.

This guide walks you through the process of setting up Claude Code with your existing GitHub repository, covering authentication, project initialization best practices, and practical workflows that work well with real-world projects.

Prerequisites

Before connecting Claude Code to your GitHub repo, ensure you have:

Verify your GitHub CLI authentication:

gh auth status

If not authenticated, run:

gh auth login

Cloning Your Repository

Start by cloning your existing repository using SSH (recommended for Claude Code integration):

git clone git@github.com:your-username/your-repo.git
cd your-repo

If you already have the repository cloned with HTTPS, switch to SSH:

git remote set-url origin git@github.com:your-username/your-repo.git

Navigate into the project directory before initializing Claude Code:

cd your-repo

Initializing Claude Code in an Existing Project

Start Claude Code within your existing repository by running it from the project directory:

claude

Claude Code will read your project structure from the current directory. It uses your existing files to understand the project context, including:

After initialization, check that the .claude directory was created:

ls -la .claude

This directory contains settings that apply specifically to this repository.

Connecting to GitHub Through Claude Code

While Claude Code doesn’t directly “connect” to GitHub as a service, it integrates with your local git workflow. Here are the key integration points:

Authentication Setup

For Claude Code to interact with GitHub repositories, ensure your SSH keys are configured:

# Check existing SSH keys
ls -la ~/.ssh

# Generate new SSH key if needed
ssh-keygen -t ed25519 -C "your-email@example.com"

Add the public key to your GitHub account, then test the connection:

ssh -T git@github.com

Working with Remote Branches

When Claude Code creates branches for feature work, push them to GitHub:

# Within Claude Code, after making changes
git checkout -b feature/your-feature-name
# Make your changes
git push -u origin feature/your-feature-name

This workflow integrates naturally with your existing GitHub workflow, whether you use pull requests, branch protection rules, or direct commits.

Practical Workflows for Existing Repos

Understanding Large Codebases

When first connecting Claude Code to a large existing repository, use the Read tool strategically:

# Get project structure overview
find . -type f -name "*.js" | head -20
# or for Python
find . -type f -name "*.py" | head -20

Then ask Claude Code to explain specific components:

Explain the authentication flow in this codebase, focusing on how users log in and session management works.

Incremental Improvements

For existing projects, start with small, focused tasks rather than large refactors:

  1. Fix a specific bug — Provide the error message and relevant code context
  2. Add a single feature — Be explicit about the desired behavior
  3. Improve test coverage — Target one module or function at a time

Example task formulation:

In src/auth/login.js, the forgot password function throws an unhandled error when the email is not found in the database. Add proper error handling that returns a user-friendly message instead of crashing.

Respecting Existing Patterns

Claude Code works best when you help it understand your project’s conventions. Provide context about:

This project uses the conventional commits format. When making changes, follow this pattern: feat: add new login button, fix: resolve auth token expiry issue.

Configuration for GitHub Projects

Customize Claude Code behavior for your repository by editing .claude/settings.json:

{
  "permissions": {
    "allow": [
      "Bash(bash)",
      "Read(read)",
      "Edit(edit)",
      "Write(write)"
    ],
    "deny": [
      "Bash(git push --force)"
    ]
  },
  "preferences": {
    "focusedMode": true,
    "maxTokens": 8000
  }
}

This configuration ensures Claude Code has appropriate permissions while preventing destructive operations.

Troubleshooting Common Issues

Permission Denied Errors

If Claude Code cannot read files in your repository, check file permissions:

chmod -R 755 your-repo
chmod -R 644 *.json *.yaml *.yml

Context Window Limits

Large repositories may exceed Claude Code’s context window. Use the Glob tool to identify key files rather than loading entire directories:

Find all files related to user authentication, particularly those handling password reset functionality.

Git Conflicts

When Claude Code generates code that conflicts with existing files, review changes carefully:

git diff --name-only
git diff path/to/file.js

Accept or reject changes based on your project’s requirements.

Security Considerations

When using Claude Code with GitHub repositories, follow these security practices:

Your .gitignore should include:

.env
.env.local
*.pem
*.key
credentials.json

Summary

Using Claude Code with an existing GitHub repository involves cloning the project, initializing Claude Code within it, and using your established git workflow. The key to success is starting with small, focused tasks and providing context about your project’s conventions.

Connect Claude Code to your repository, respect existing patterns, and gradually expand your AI-assisted workflow. The combination of your project’s history and AI assistance unlocks productivity gains without disrupting established development processes.


Built by theluckystrike — More at zovo.one