Skip to content

Instantly share code, notes, and snippets.

@maleta
Last active February 16, 2026 21:31
Show Gist options
  • Select an option

  • Save maleta/16e7072bf469b95df73aa64d7471f6f6 to your computer and use it in GitHub Desktop.

Select an option

Save maleta/16e7072bf469b95df73aa64d7471f6f6 to your computer and use it in GitHub Desktop.
Clone a GitHub repo and start Claude Code in it. Repos are cached locally for fast reuse.

gitask

A bash script that clones GitHub repositories (with local caching) and launches Claude Code inside the cloned directory.

Ask Claude questions about any public GitHub repo without manually cloning it first.

Install

curl -fsSL https://gist.githubusercontent.com/maleta/16e7072bf469b95df73aa64d7471f6f6/raw/gitask -o /usr/local/bin/gitask
chmod +x /usr/local/bin/gitask

Requires: git, claude (Claude Code CLI).

Usage

gitask <github-url> [claude args...]

Examples

# Open Claude Code in a repo
gitask https://github.com/anthropics/claude-code

# Target a specific branch and path
gitask https://github.com/anthropics/claude-code/tree/main/src

# Point to a specific file (blob URL)
gitask https://github.com/anthropics/claude-code/blob/main/src/index.ts

# Pass additional arguments to Claude
gitask https://github.com/user/repo -p "explain the architecture"

How it works

  1. Parses the GitHub URL to extract owner, repo, branch, and file path.
  2. Clones the repo to ~/.gitask/<owner>/<repo> (reuses the cache on subsequent runs).
  3. Checks out the specified branch if provided.
  4. Launches claude in the repo directory, forwarding any extra arguments.
# Clone a GitHub repo (cached in ~/.gitask) and launch Claude Code
# in the repo directory. Supports blob/tree URLs to checkout a specific
# branch and reference a file path.
#!/usr/bin/env bash
set -euo pipefail
GITASK_DIR="${HOME}/.gitask"
usage() {
echo "Usage: gitask <github-url> [claude args...]"
echo ""
echo "Clone a GitHub repo (cached) and start Claude interactively with context."
echo ""
echo "Examples:"
echo " gitask https://github.com/user/repo"
echo " gitask https://github.com/user/repo/blob/main/src/index.ts"
echo " gitask https://github.com/user/repo/tree/develop/docs"
exit 1
}
[[ $# -lt 1 ]] && usage
url="$1"
shift
# Strip github.com prefix and extract segments
path="${url#*github.com/}"
IFS='/' read -ra parts <<< "$path"
if [[ ${#parts[@]} -lt 2 || -z "${parts[0]}" || -z "${parts[1]}" ]]; then
echo "Error: could not parse owner/repo from URL"
exit 1
fi
owner="${parts[0]}"
repo="${parts[1]%.git}"
branch=""
file_ref=""
# Parse blob/tree URLs: owner/repo/(blob|tree)/<branch>/path...
if [[ ${#parts[@]} -ge 4 ]] && [[ "${parts[2]}" == "blob" || "${parts[2]}" == "tree" ]]; then
branch="${parts[3]}"
if [[ ${#parts[@]} -ge 5 ]]; then
file_ref=$(IFS='/'; echo "${parts[*]:4}")
fi
fi
clone_dir="${GITASK_DIR}/${owner}/${repo}"
repo_url="https://github.com/${owner}/${repo}.git"
# Clone if not cached
if [[ -d "$clone_dir/.git" ]]; then
echo "Using cached ${owner}/${repo}"
else
echo "Cloning ${owner}/${repo}..."
git clone "$repo_url" "$clone_dir"
fi
# Checkout branch if specified
if [[ -n "$branch" ]]; then
git -C "$clone_dir" checkout "$branch" 2>/dev/null \
|| git -C "$clone_dir" checkout -b "$branch" "origin/$branch" 2>/dev/null \
|| echo "Warning: could not checkout branch '$branch'"
fi
cd "$clone_dir"
exec claude "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment