Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/simonw/LLM/llms.txt

Use this file to discover all available pages before exploring further.

Fragments are reusable pieces of text that LLM injects into your prompt at runtime. Unlike pasting content directly into a prompt, a fragment is stored exactly once in the database and referenced by every prompt that uses it — saving disk space and enabling powerful filtering in llm logs. Fragments can be files on disk, URLs fetched at prompt time, SHA-256 hash IDs of previously stored content, named aliases, or values produced by plugins.

Using Fragments in a Prompt

Pass one or more -f / --fragment options. LLM prepends the fragment content to your prompt in the order you provide them:
llm -f https://llm.datasette.io/robots.txt 'explain this'
URLs are fetched with a descriptive llm/<version> user-agent. Use --sf / --system-fragment to inject a fragment into the system prompt instead of the user prompt:
llm -f cli.py --sf explain_code.txt

Using Fragments in Chat

Start a chat with an initial fragment loaded:
llm chat -f my_doc.txt
Add fragments during a running chat with the !fragment command:
> !fragment https://llm.datasette.io/en/stable/fragments.html
Combine !fragment with !multi for multi-line prompts that reference fragments:
> !multi
Explain the difference between fragments and templates
!fragment https://llm.datasette.io/en/stable/fragments.html https://llm.datasette.io/en/stable/templates.html
!end
!fragment lines inside a !edit prompt are not parsed. Use !multi instead.

Browsing Fragments

View recently stored fragments:
llm fragments
Example output:
- hash: 0d6e368f9bc21f8db78c01e192ecf925841a957d8b991f5bf9f6239aa4d81815
  aliases: []
  datetime_utc: '2025-04-06 07:36:53'
  source: https://raw.githubusercontent.com/simonw/llm-docs/refs/heads/main/llm/0.22.txt
  content: |-
    <documents>
    <document index="1">
    ...
- hash: 16b686067375182573e2aa16b5bfc1e64d48350232535d06444537e51f1fd60c
  aliases: []
  datetime_utc: '2025-04-06 23:03:47'
  source: simonw/files-to-prompt/pyproject.toml
  content: |-
    [project]
    name = "files-to-prompt"
    ...
Reference a fragment by its hash in future prompts:
llm -f 16b686067375182573e2aa16b5bfc1e64d48350232535d06444537e51f1fd60c 'Extract metadata'
Search fragments with -q:
llm fragments -q pytest -q asyncio
Show only fragments that have aliases:
llm fragments --aliases
View the full content of one fragment:
llm fragments show 0d6e368f9bc21f8db78c01e192ecf925841a957d8b991f5bf9f6239aa4d81815

Setting Aliases for Fragments

Assign a short alias to any fragment so you can reference it by name instead of a 64-character hash:
llm fragments set cli cli.py
Use the alias in a prompt:
llm -f cli 'explain this code'
Remove an alias (the underlying fragment record is kept, since it is linked to past responses):
llm fragments remove cli

Viewing Fragments in Logs

The llm logs command lists fragments used in each prompt by their hash ID. Add -e / --expand to display the full content inline:
# Expand fragments for the most recent conversation
llm logs -c --expand

# JSON output with full fragment content
llm logs -c --json --expand
Filter logs to only entries that used a specific fragment (accepts URLs, file paths, aliases, or hash IDs):
llm logs -f https://llm.datasette.io/robots.txt --expand
Multiple -f options return only responses that used all of the specified fragments.

Fragments from Plugins

Plugins can register custom fragment loaders accessed via a prefix:argument syntax. Install llm-fragments-github to load entire GitHub repositories as fragments:
llm install llm-fragments-github
llm -f github:simonw/s3-credentials 'Suggest new features for this tool'
This single -f call expands into one fragment per file in the repository. View the full breakdown with:
llm logs -c --usage --expand
Fragment plugins can also return binary attachments such as images — see the register_fragment_loaders plugin hook documentation for details.

Listing Available Prefixes

llm fragments loaders
Example output after installing llm-fragments-github:
github:
  Load files from a GitHub repository as fragments

  Argument is a GitHub repository URL or username/repository

issue:
  Fetch GitHub issue and comments as Markdown

  Argument is either "owner/repo/NUMBER"
  or "https://github.com/owner/repo/issues/NUMBER"

Build docs developers (and LLMs) love