Dotfiles-nix github-code-search
Search GitHub code using gh code-search command. Use when looking for reference implementations, code examples, or specific patterns across GitHub repositories. Particularly useful for Nix configurations, language-specific patterns, or learning how others solved similar problems.
git clone https://github.com/not-matthias/dotfiles-nix
T=$(mktemp -d) && git clone --depth=1 https://github.com/not-matthias/dotfiles-nix "$T" && mkdir -p ~/.claude/skills && cp -r "$T/modules/home/programs/cli-agents/shared/skills/github-code-search" ~/.claude/skills/not-matthias-dotfiles-nix-github-code-search && rm -rf "$T"
modules/home/programs/cli-agents/shared/skills/github-code-search/SKILL.mdGitHub Code Search via gh CLI
Search across GitHub's entire codebase using the
gh code-search command. This is faster than browsing and helps you find real-world examples of how to structure code, configure tools, or solve problems.
When to Use
- Finding reference implementations (e.g., how others structure flake.nix)
- Learning patterns for specific languages or frameworks
- Discovering how popular projects configure tools
- Finding examples of specific Nix packages or functions
- Researching best practices for code organization
Prerequisites
CLI installed and authenticated (gh
)gh auth login- Understanding basic GitHub search syntax
Workflow
Step 1: Construct Your Search Query
Use operators and filters to narrow results:
Basic syntax:
gh code-search [query] [flags]
Common operators:
- Search only in Nix fileslanguage:nix
- Search in Python fileslanguage:python
- Limit to specific repositoryrepo:owner/repo
- Search only in files named flake.nixfilename:flake.nix
- Search within an organizationorg:nixos
- Limit to popular repos (helps avoid noise)stars:>100
Combining operators:
gh code-search 'stdenv.mkDerivation' language:nix repo:nixos/nixpkgs stars:>50
Step 2: Execute the Search
Run the search and review results:
gh code-search 'search query' language:nix --limit 10
Flags:
- Show first N results (default 30, max 100)--limit N
- Output as JSON for processing--json
- Match against: path, symbol, or content (default: content)--match <field>
Step 3: Navigate Results
Each result shows:
- Repository name
- File path
- Repository description
- URL to view on GitHub
Click or copy the URL to examine the full context in your browser.
Examples
Find Nix Package Examples
Search for how others define packages:
# Look for fetchFromGitHub usage gh code-search 'fetchFromGitHub' language:nix stars:>50 --limit 10 # Find similar packages (e.g., Rust tools) gh code-search 'rustPlatform.buildRustPackage' language:nix --limit 20 # Find AppImage packaging examples gh code-search 'appimageTools' language:nix --limit 5
Find Nix Service Configurations
# Systemd service examples gh code-search 'systemd.services' language:nix org:nixos --limit 10 # Home Manager module examples gh code-search 'home.packages' language:nix stars:>100 --limit 15
Find flake.nix Patterns
# Browse flakes with specific input patterns gh code-search 'inputs.nixpkgs' filename:flake.nix stars:>50 --limit 20 # Find flake outputs patterns gh code-search 'outputs = {' filename:flake.nix --limit 10
Non-Nix Examples
# Python package examples gh code-search 'def setup(' language:python filename:setup.py stars:>100 # Rust build patterns gh code-search 'cargo.toml' language:toml stars:>50 # Shell script patterns gh code-search '#!/bin/bash' language:shell --limit 10
Advanced Patterns
Exclude Noise
Add negative filters to exclude test files or templates:
gh code-search 'pattern' language:nix -filename:test.nix
Search Organization
Find patterns within the NixOS organization (most authoritative):
gh code-search 'stdenv.mkDerivation' language:nix org:nixos --limit 50
Combine With Local Processing
Export to JSON and process locally:
gh code-search 'query' language:nix --json | jq '.[] | .url' > results.txt
Common Issues
Issue: Too many irrelevant results
- Solution: Add filters like
to focus on popular, well-maintained repos. Addstars:>100
for authoritative NixOS examples.org:nixos
Issue: Results seem outdated
- Solution: Focus on recent changes by searching for specific patterns in active projects. Check the repository's last update date on GitHub.
Issue: Can't find specific syntax
- Solution: Try variations of the syntax (e.g.,
vsstdenv.mkDerivation
). Search for similar projects that use the same tool/library.mkDerivation
Tips
- Start broad, narrow down: Begin with simple queries, then add filters based on results
- Use stars for quality:
helps surface well-maintained examplesstars:>50 - Check multiple examples: Different people solve problems differently—see 3-5 implementations to find patterns
- Use filename filters:
is faster than searching content for specific file typesfilename:flake.nix - Bookmark useful repos: When you find a good reference, star it or note the URL for future reference
- Cross-reference: Use multiple searches to find complementary examples
See Also
- Full command referencegh code-search --help- https://docs.github.com/en/search-github/searching-on-github/searching-code - GitHub search documentation
- https://github.com/nixos/nixpkgs - Primary Nix package repository for official examples