Skip to main content

Prerequisites

Before you begin, ensure you have the following installed:
  • Docker & Docker Compose: For containerized development
  • pre-commit: For automated code quality checks
  • Node.js/Yarn: Alternative to Bun for web development

Installation Methods

Development Setup Script

For a faster setup, use the provided development script:
# Basic setup (server + web app)
./scripts/dev_setup.sh

# Full setup (includes Desktop and Obsidian clients)
./scripts/dev_setup.sh --full
This script:
  • Installs the Khoj server and web app
  • Sets up Git hooks for automatic code formatting and type checking
  • Configures pre-commit hooks
  • Optionally installs Desktop and Obsidian client apps

Client Configuration

When testing with Khoj clients (Desktop, Obsidian, Emacs), update the server URL to point to your local instance:
http://127.0.0.1:42110

Validation and Testing

Before Making Changes

1

Install Git Hooks

./scripts/dev_setup.sh
If pre-commit isn’t installed:
pip install pre-commit
pre-commit install -t pre-push -t pre-commit
2

Verify Setup

# Run pre-commit checks manually
pre-commit run --hook-stage manual --all

Before Creating a PR

You must be in an active virtual environment to run tests and linters.
1

Create or Link GitHub Issue

Ensure there’s a GitHub issue that can be linked to your PR. Tag a maintainer on the issue for visibility. Discuss the code design before creating a PR to get it merged faster.
2

Run Tests

pytest
Run specific tests:
pytest tests/test_client.py
pytest tests/test_agents.py -v
3

Run Type Checker

mypy
4

Add Unit Tests

Think about how to verify your functionality with tests. Ask for help in the GitHub issue or Discord’s #contributors channel if you’re unsure.

After Creating a PR

Automated validation workflows will run for every PR. Tag a maintainer to trigger the workflows if they don’t start automatically. The workflows include:
  • Test Suite: Runs on Python 3.10, 3.11, and 3.12
  • Type Checking: Validates type hints with mypy
  • Linting: Checks code style with ruff
  • Pre-commit Hooks: Validates formatting and imports

Obsidian Plugin Development

Setup

1

Navigate to Plugin Directory

cd src/interface/obsidian
2

Install Dependencies

yarn install
3

Start Development Server

yarn dev
This continuously rebuilds the plugin as you make changes, outputting to main.js.

Loading in Obsidian

1

Install Khoj Plugin

Make sure you have the Khoj plugin installed in Obsidian.
2

Open Plugin Folder

  • Open Obsidian settings (gear icon)
  • Click ‘Community Plugins’
  • Click the folder icon next to ‘Installed Plugins’
3

Replace main.js

Navigate to the khoj folder and replace main.js with your development build from src/interface/obsidian/main.js.
4

Reload Obsidian

Restart Obsidian or use the “Reload app without saving” command to test your changes.

Windows Installation Troubleshooting

  1. Try reactivating the virtual environment:
    .venv\Scripts\deactivate
    .venv\Scripts\activate
    
  2. If it still doesn’t work, repeat the installation process
Use uv to add the missing package:
uv add <package-name>
Then try running khoj again.
Add PostgreSQL binaries to your PATH:
C:\Program Files\PostgreSQL\16\bin
  1. Locate pg_hba.conf in your PostgreSQL installation directory
  2. Edit the file to use trust authentication:
host    all             postgres        127.0.0.1/32            trust
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
  1. Restart PostgreSQL service
  1. Reinstall Visual Studio 2022 Build Tools with:
    • Desktop development with C++ (in Workloads)
    • MSVC C++ Build Tools (in Individual Components)
    • Windows 10/11 SDK (in Individual Components)
    • C++/CLI support for build tools (in Individual Components)
  2. Open “x64 Native Tools Command Prompt for VS 2022” as Administrator
  3. Follow pgvector Windows installation instructions

Environment Variables

# Database
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=khoj

# Server
KHOJ_DOMAIN=localhost
KHOJ_NO_HTTPS=true

# Debugging
KHOJ_DEBUG=true

Next Steps

Understand the Architecture

Learn about Khoj’s system design and code structure

Performance Guidelines

Learn about optimization and benchmarking

Find Issues to Work On

Browse beginner-friendly issues

Join Discord

Connect with other contributors

Build docs developers (and LLMs) love