Skip to main content

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.

Metadata

Release files for code-xray 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for code-xray 2.0.1
File Size Uploaded
code_xray-2.0.1.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for code-xray 2.0.1
File Interpreter ABI Platform
code_xray-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.9 kB

Release files / code_xray-2.0.1.tar.gz

Download URL code_xray-2.0.1.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
648b1695444a359f4585c0c392a9a6046d0b6d2e12919224e4f15e2a7e153fef
BLAKE2b-256 checksum
How to use checksums
9beed50e9ac0aaa2efa68d28ca57e175956bc2ca288d92c9f2a124fb56f59844
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Release files / code_xray-2.0.1-py3-none-any.whl

Download URL code_xray-2.0.1-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8aab1dc7f084bc4a1d5fd53b7546d5c1b74c5e12df5e47d7f357a42207422be6
BLAKE2b-256 checksum
How to use checksums
f41593997d25587f0c7f4febe5400c7f339603b52d706fb7037c8384ba0d8c2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page