Skip to main content

Terminal-based code explainer powered by Ollama

Project description

code-xray logo

🧠 code-xray

code-xray is a terminal-based code exploration and explanation tool powered by local LLMs (like Ollama).
Select lines of code interactively, send them for explanation, and get human-friendly insights – right in your terminal.

Demo


✨ Features

  • ✅ Terminal-based file viewer with syntax highlighting
  • ✅ Line-by-line navigation and selection
  • ✅ Interactive directory tree when run without arguments
  • ✅ Integration with local LLMs via Ollama
  • ✅ On-demand code explanation using selected lines and full-file context
  • ✅ Works fully offline
  • ✅ Switch between file viewer and file tree (b to go back)
  • ✅ Customizable LLM model and port via CLI

🚀 Usage

1. Launch without arguments

code-xray

This opens a directory tree starting from your current working directory.
You can navigate folders and open files for explanation. Press b inside a viewer to return to the file tree.

2. Launch with a file directly

code-xray /path/to/your/file.py

This opens an interactive terminal interface to browse and explain code.

3. Launch with custom model and port

code-xray /path/to/your/file.py --model mistral --port 11434
  • --model or -m: LLM model name (e.g. mistral, llama3, codellama)
  • --port or -p: Port where Ollama is running (default is 11434)

🧭 Keybindings

Key Action
h Move up one line
l Move down one line
Shift+h Expand selection up
Shift+l Expand selection down
e Explain selected code
b Go back to file tree
q Quit viewer or popup
Esc Close explanation popup
Enter Select file or enter folder
../ Navigate up in the file tree

🛠 Requirements

  • Python 3.10+
  • Ollama running locally with your preferred model

Example to pull a model:

ollama pull mistral

Then start the server:

ollama serve

🧩 Installation

pip install code-xray

Make sure code-xray is available in your PATH or create an alias.


🙌 Acknowledgements

  • Textual for the beautiful terminal UI
  • Ollama for local model hosting
  • Rich for the syntax highlighting

🔗 Contributions

Pull requests welcome! Feel free to fork and build on top of this.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_xray-2.0.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_xray-2.0.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file code_xray-2.0.1.tar.gz.

File metadata

  • Download URL: code_xray-2.0.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for code_xray-2.0.1.tar.gz
Algorithm Hash digest
SHA256 648b1695444a359f4585c0c392a9a6046d0b6d2e12919224e4f15e2a7e153fef
MD5 f2beff81ff225dd4a17bc67a8b057381
BLAKE2b-256 9beed50e9ac0aaa2efa68d28ca57e175956bc2ca288d92c9f2a124fb56f59844

See more details on using hashes here.

File details

Details for the file code_xray-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: code_xray-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for code_xray-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8aab1dc7f084bc4a1d5fd53b7546d5c1b74c5e12df5e47d7f357a42207422be6
MD5 5297e31c1ad1579abc3e6d66e3b9ff11
BLAKE2b-256 f41593997d25587f0c7f4febe5400c7f339603b52d706fb7037c8384ba0d8c2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page