> ## Documentation Index
> Fetch the complete documentation index at: https://docs.githits.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Code examples: prior art and implementation patterns

> Use get_example and npx githits@latest example when your agent needs prior art or implementation patterns from open-source repositories, issues, discussions, and pull requests.

Code Examples are one GitHits context tool. Use them when your agent needs prior art or implementation patterns from open-source repositories, issues, discussions, and pull requests, and does not need to inspect a specific package version or repository ref.

The `get_example` MCP tool and its CLI counterpart `npx githits@latest example` accept a plain-language query and return an implementation example with source citations.

<Note>
  Code Examples are not version-aware. Use [Code Navigation](/tools/code-navigation) when your agent needs to inspect a specific package version or repository ref.
</Note>

## How agents use it

Your agent calls `get_example` automatically when it is stuck on an unfamiliar API, needs to validate a pattern, or encounters an error it cannot resolve from training data. You do not need to prompt it manually — once GitHits is connected via MCP, the agent decides when to reach for the tool.

You can also trigger it explicitly from the CLI for manual research or to give your agent a head start with fresh context:

```bash theme={null}
npx githits@latest example "how to use Redis pub/sub in Python"
```

When using the CLI, pass `--lang` to force a language and `--license` to choose the license filter. The MCP parameters are named `language` and `license_mode`.

## Parameters

<ParamField query="query" type="string" required>
  Natural-language description of the code pattern or API usage you need. Write it the way you would describe the problem to a colleague — for example, `"broadcast messages to specific rooms using python-socketio with Redis as the message queue backend"`.
</ParamField>

<ParamField query="language" type="string">
  Programming language to target. Omit this parameter and GitHits infers the language from your query automatically. Only supply it when you need to force a specific language and want to be exact. If you are unsure of the canonical name, use `npx githits@latest languages` first (see below).
</ParamField>

<ParamField query="license_mode" type="string" default="strict">
  Controls license filtering for Code Examples only. Use `strict` by default, `yolo` for unfiltered research, or `custom` for your configured blocklist at [githits.com](https://githits.com).
</ParamField>

## Example output

The following query asks for a Python Redis pub/sub pattern. GitHits returns an implementation example alongside citations showing where that prior art appears in the open-source ecosystem.

```bash theme={null}
npx githits@latest example "broadcast messages to specific rooms using python-socketio with Redis pub/sub"
```

The result includes:

* An implementation example based on real-world usage
* Source repository citations (e.g., `socketio/socket.io-redis-adapter`, `miguelgrinberg/python-socketio`)
* A `solution_id` on the final line of the output, used when submitting feedback

```python theme={null}
import socketio
import asyncio
import redis.asyncio as redis

# Initialize Redis client
r = redis.Redis(host='localhost', port=6379, decode_responses=True)

# Create AsyncRedisManager for horizontal scaling via Redis pub/sub
mgr = socketio.AsyncRedisManager(r)

# Create SocketIO server with the Redis manager
sio = socketio.AsyncServer(client_manager=mgr)

@sio.event
async def broadcast_to_room(sid, data):
    room = data.get('room')
    message = data.get('message')
    if room and message:
        await sio.emit('room_message', {'message': message, 'from': sid}, room=room)

app = socketio.ASGIApp(sio)
```

<Note>
  Results are useful for current ecosystem patterns, not for version-pinned dependency inspection.
</Note>

## Language support

`get_example` supports over 800 programming languages. In most cases, GitHits infers the correct language from your query without any additional input.

When you need to force a specific language and are unsure of the exact name GitHits expects, use the `search_language` tool or `npx githits@latest languages` command to look it up:

```bash theme={null}
npx githits@latest languages typescript
```

```bash theme={null}
npx githits@latest languages elixir
```

The command returns up to five matching languages by name, display name, or alias.

<Tip>
  You only need `npx githits@latest languages` when you want to pass an explicit `language` parameter and need the canonical name. For most queries, skip it — GitHits infers the language automatically.
</Tip>

## Submitting feedback

After reviewing an example, submit feedback with the `solution_id` from the output. See [Feedback](/tools/feedback) for the full tool reference.

## MCP tool reference

| Tool              | CLI command                    | Purpose                                                     |
| ----------------- | ------------------------------ | ----------------------------------------------------------- |
| `get_example`     | `npx githits@latest example`   | Natural-language search returning an implementation example |
| `search_language` | `npx githits@latest languages` | List or filter supported language names                     |
