Search All of GitHub's Code and Pass the Results to AI Agents in Cursor

I often find myself wondering how to use certain APIs in certain situations, and I have a couple of keywords that I try and search up on Google. And what you can really do in this situation is turn to GitHub and see how other people have actually used this code on public projects. The GitHub CLI enables us to run searches like this, and we can take the results and work on them programmatically. And inside of Cursor with their Composer AI agent, we can search for the files we want, and we can tell the agent to download them and then work on them and inspect them and teach us how those things work together.

Share with a coworker

Transcript

[00:00] The GitHub CLI includes a search command and you can actually search through all the code on GitHub. So if you want to see how someone used React and UseMachine for an XState example, you can pass that as a string, hit enter, and get a bunch of results. We'll type Q to escape. I even want to filter it by, so react use machine language colon TypeScript. This way all the results will be TypeScript and Q escapes.

[00:25] We can actually format the result with dash dash JSON and it will ask us to specify which properties we want. And we'll say we want the URL. And this way we get JSON objects back with URLs to all of the files. In cursor in the terminal you can just highlight a bunch of stuff and hit command-i or click add to composer and I can say download these files to my examples folder. And it can go ahead and start writing out the commands necessary and running them for you.

[00:50] I already had five examples in there so now it's going to number them six through ten and it's generating all these files for me. So now that we have all these files we can explore them a bit, see how people use UseMachine with TypeScript and React, and if you're doing research ask it more questions in Composer or in chat. And this all becomes very helpful when you're trying to look at a specific language or a couple of features interact with each other such as XState and React.