Metadata-Version: 2.5
Name: amagi-model-shelf
Version: 0.15.0
Summary: Find duplicate local LLM files across LM Studio, Ollama, the Hugging Face cache and llama.cpp, and resolve models from your own disks before downloading.
Project-URL: Homepage, https://github.com/amagilabs/amagi-model-shelf
Project-URL: Issues, https://github.com/amagilabs/amagi-model-shelf/issues
Project-URL: Upstream, https://github.com/alexziskind1/model-shelf
Author-email: "AmagiLabs (Amagisolutionsgroup, Inc.)" <dev@amagisolutionsgroup.com>
License: MIT License
        
        Copyright (c) 2026 Alex Ziskind
        Copyright (c) 2026 Amagisolutionsgroup, Inc. (AmagiLabs)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: claude-code,disk-space,duplicates,gguf,huggingface,llama.cpp,llm,lm-studio,local-models,ollama
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Requires-Dist: huggingface-hub>=0.24
Requires-Dist: questionary>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Description-Content-Type: text/markdown

# amagi-model-shelf

Find the model files LM Studio, Ollama, llama.cpp and the Hugging Face cache have each downloaded separately, and get that disk space back. Also resolves models from your own disks before anything downloads.

![amagi-model-shelf finding duplicate models across four tools](assets/demo.gif)

<sub>Recorded against the fixture stores from `examples/make_stores.py`, placed in a throwaway home folder so default discovery finds them. Real command, real output, filler-byte files.</sub>

```bash
pipx install amagi-model-shelf
```

Python 3.11+. Works on Windows, macOS and Linux.

## Why

Every local LLM tool keeps its own model folder. Pull Qwen3 in Ollama, download the same GGUF in LM Studio, let llama.cpp fetch it with `-hf`, and you have three copies of one file under three different names. Nothing warns you, because none of the tools knows the others exist.

`amagi-model-shelf` reads all of those folders, matches files by content rather than by name, and tells you exactly how much space the copies cost. If you want, it replaces the copies with hard links: every tool keeps its path and keeps working, and the data is stored once.

## Usage

The output below is a real run against `examples/make_stores.py`, which builds a tiny fake LM Studio / Ollama / HF cache / llama.cpp setup out of filler bytes (a few MB, not real weights). Point it at your real folders and the numbers are yours.

```bash
python examples/make_stores.py stores --mb 1
```

### See what every tool has

```
$ amagi-model-shelf scan
  lmstudio      3.0 MB  bartowski/Llama-3.2-1B-Instruct-GGUF/Llama-3.2-1B-Instruct-Q8_0.gguf
  lmstudio      2.0 MB  HuggingFaceTB/SmolLM2-360M/model.safetensors
  lmstudio      8.0 MB  Qwen/Qwen3-4B-GGUF/Qwen3-4B-Q4_K_M.gguf
  lmstudio      8.0 MB  someone/Qwen3-4B-finetune-GGUF/qwen3-4b-ft-Q4_K_M.gguf
  lmstudio      5.0 MB  TheBloke/Mistral-7B-Instruct-GGUF/mistral-7b-instruct.Q4_K_M.gguf
  ollama        8.0 MB  qwen3:4b
  ollama        8.0 MB  qwen3:latest
  hf            2.0 MB  HuggingFaceTB/SmolLM2-360M model.safetensors
  hf            8.0 MB  Qwen/Qwen3-4B-GGUF Qwen3-4B-Q4_K_M.gguf
  llamacpp      3.0 MB  bartowski/Llama-3.2-1B-Instruct-GGUF/Llama-3.2-1B-Instruct-Q8_0.gguf
  llamacpp      8.0 MB  Qwen/Qwen3-4B-GGUF/Qwen3-4B-Q4_K_M.gguf

  11 model files from 4 source(s), 55.0 MB on disk
```

With no flags it looks in each tool's standard location and honours `OLLAMA_MODELS`, `HF_HOME` / `HF_HUB_CACHE` and `LLAMA_CACHE`. Use `--root ollama=D:\ollama\models` for a custom location, or `--path DIR` to add any folder of `.gguf` / `.safetensors` files. (The demo passes `--root` for each fixture store; those lines are trimmed here.)

### Find the duplicates

```
$ amagi-model-shelf dupes --verify full
  10 model files, 55.0 MB on disk
  1 already shared (Ollama tags on one blob, symlinks, hard links: no waste)
  3 duplicate group(s), 29.0 MB reclaimable (full sha256)

  [1] 8.0 MB x4   reclaim 24.0 MB   sha256 68768aed41d9
      ollama    qwen3:4b, qwen3:latest
                stores/ollama/blobs/sha256-68768aed41d92431af4917ef4779b86fc12615619e72a0f961b8760408413e1a
      hf        stores/hf/models--Qwen--Qwen3-4B-GGUF/snapshots/0123abcd/Qwen3-4B-Q4_K_M.gguf
      lmstudio  stores/lmstudio/Qwen/Qwen3-4B-GGUF/Qwen3-4B-Q4_K_M.gguf
      llamacpp  stores/llamacpp/Qwen_Qwen3-4B-GGUF_Qwen3-4B-Q4_K_M.gguf
  [2] 3.0 MB x2   reclaim 3.0 MB   sha256 c877ea18c3a0
      lmstudio  stores/lmstudio/bartowski/Llama-3.2-1B-Instruct-GGUF/Llama-3.2-1B-Instruct-Q8_0.gguf
      llamacpp  stores/llamacpp/bartowski_Llama-3.2-1B-Instruct-GGUF_Llama-3.2-1B-Instruct-Q8_0.gguf
  [3] 2.0 MB x2   reclaim 2.0 MB   sha256 65d8d76d070f
      hf        stores/hf/models--HuggingFaceTB--SmolLM2-360M/snapshots/9f8e7d6c/model.safetensors
      lmstudio  stores/lmstudio/HuggingFaceTB/SmolLM2-360M/model.safetensors
```

Two Ollama tags pointing at one blob are not waste, so they count once. The fixture also plants a same-size "finetune" that differs by 4 KiB in the middle. Full verification keeps it out of group 1.

How matching works:

1. Files that are already the same file on disk (hard links, symlinks) are collapsed first.
2. Only files with identical sizes are compared.
3. The default `--verify quick` hashes the size plus three 1 MiB samples (start, middle, end). On a 40 GB file that is 3 MiB of reading, and the report says "fingerprint match, not yet verified".
4. `--verify full` hashes every byte. Ollama blobs and HF cache blobs are named after their sha256, so those are reused instead of re-read.

`--json` gives the same report in machine-readable form.

### Reclaim the space

```
$ amagi-model-shelf dedupe
  planned      8.0 MB  stores/hf/models--Qwen--Qwen3-4B-GGUF/snapshots/0123abcd/Qwen3-4B-Q4_K_M.gguf
                       -> stores/ollama/blobs/sha256-68768aed41d92431af4917ef4779b86fc12615619e72a0f961b8760408413e1a
  planned      8.0 MB  stores/lmstudio/Qwen/Qwen3-4B-GGUF/Qwen3-4B-Q4_K_M.gguf
                       -> stores/ollama/blobs/sha256-68768aed41d92431af4917ef4779b86fc12615619e72a0f961b8760408413e1a
  planned      8.0 MB  stores/llamacpp/Qwen_Qwen3-4B-GGUF_Qwen3-4B-Q4_K_M.gguf
                       -> stores/ollama/blobs/sha256-68768aed41d92431af4917ef4779b86fc12615619e72a0f961b8760408413e1a
  planned      3.0 MB  stores/llamacpp/bartowski_Llama-3.2-1B-Instruct-GGUF_Llama-3.2-1B-Instruct-Q8_0.gguf
                       -> stores/lmstudio/bartowski/Llama-3.2-1B-Instruct-GGUF/Llama-3.2-1B-Instruct-Q8_0.gguf
  planned      2.0 MB  stores/lmstudio/HuggingFaceTB/SmolLM2-360M/model.safetensors
                       -> stores/hf/models--HuggingFaceTB--SmolLM2-360M/snapshots/9f8e7d6c/model.safetensors

  dry run: nothing changed. --apply links 5 copies and frees 29.0 MB.
  Every path keeps working; the copies just share one file on disk.
```

`dedupe` is a dry run until you add `--apply`. It always does a full sha256 check first, whatever `--verify` says. Each copy is swapped for a hard link atomically (link to a temp name, then rename over), so a crash mid-run never leaves a missing file. Hard links can't cross drives, so copies on a different drive are reported and skipped.

One thing to know: after linking, the paths are one file. If a tool edits a model in place, every path sees the edit. Inference tools only read weights, but if you fine-tune in place, keep that copy out.

### Put everything on one shelf

```bash
amagi-model-shelf import                 # dry run
amagi-model-shelf import --apply         # hard-link onto the shelf
amagi-model-shelf import --mode copy     # shelf on another drive
```

`import` lays the models from LM Studio, Ollama, the HF cache and llama.cpp onto your shelf in the `gguf/<publisher>/<repo>/<file>` layout (Ollama models land under `gguf/ollama/<name>/`). It never overwrites an existing file. `--mode symlink` is also available.

### Resolve before downloading

The original model-shelf job still works the same way. An agent (or you) asks for a model; it comes from your disks if it's anywhere on them, and downloads to the shelf only on a miss.

```bash
amagi-model-shelf init                                   # pick or detect a shelf
amagi-model-shelf resolve "Qwen/Qwen3-14B-GGUF" --quant Q4_K_M --json
amagi-model-shelf find "qwen 3 4b mlx 4-bit" --format mlx --limit 5
amagi-model-shelf list
```

Format is detected from the repo id (`*-GGUF` is gguf and needs `--quant`, `mlx-community/*` or `*-mlx` is mlx, anything else is safetensors). Lookup checks the configured shelf, then every mounted drive with a `ModelShelf/models` folder, then `~/.cache/model-shelf/models`. On Windows, every drive letter other than the system drive counts as a mounted drive. Exit codes: `0` found or downloaded, `1` missing.

Config lives at `~/.config/model-shelf/config.toml` (override with `$MODEL_SHELF_CONFIG` or `--config`). It's the same file upstream model-shelf uses, so an existing setup carries over. See [`config.example.toml`](config.example.toml).

## Windows fix

Upstream model-shelf writes a Windows path such as `shelf_root = "D:\Models\ModelShelf"` into its TOML config without escaping. TOML treats each backslash as the start of an escape sequence (`\M` is invalid, `\U` expects eight hex digits), so the very next command crashes with `TOMLDecodeError` (`Unescaped '\' in a string`, or `Invalid hex value` for any path under the Users folder). This fork escapes paths when writing, and repairs an already-broken config in memory when reading (with a warning telling you to re-run `init`). A regression test runs `init C:\...` and then `list`.

## Claude Code

The repo ships a Claude Code plugin with a [skill](skills/amagi-model-shelf/SKILL.md) that routes model downloads through `resolve` and knows the audit commands. The skill tells the agent never to run `dedupe --apply` or `import --apply` without asking you first.

```
/plugin marketplace add amagilabs/amagi-model-shelf
/plugin install amagi-model-shelf@amagilabs
```

## Development

```bash
pip install -e ".[dev]"
pytest
```

The tests build fixture stores for all four tools and run the real CLI against them, including the impostor file, Ollama multi-tag blobs, cross-drive skips and the Windows config crash.

If this saved you time, a star helps others find it.

## More from AmagiLabs

- [amagilabs on GitHub](https://github.com/amagilabs): small open-source tools for local AI work.
- [amagi-weights](https://github.com/amagilabs/amagi-weights)

## What changed from upstream

Forked from model-shelf v0.14.0.

- Fixed: Windows paths in the config crashed every command after `init` (upstream #2, #7).
- Added: Windows drive-letter discovery for multi-shelf lookup.
- Added: `scan` across LM Studio, Ollama, the HF cache and llama.cpp (upstream #3 asked for LM Studio).
- Added: `dupes` and `dedupe`, the duplicate report and hard-link reclaim.
- Added: `import` from all four tools onto the shelf (upstream #9).
- Renamed: package `amagi-model-shelf`, command `amagi-model-shelf`. The config path is unchanged.

## License

MIT. See [LICENSE](LICENSE).

Based on model-shelf by Alex Ziskind (MIT).
