Foundation Runtime Classpath

# Class Loading

Klyn resolves classes through a deterministic search order. The rule is deliberately strict: standard library classes are always resolved before application classes, so local files cannot impersonate or shadow core `klyn.*` types.

Search Order

When the runtime looks for a class source file, it checks these roots in order:

1. `$KLYN_HOME/lib`, the standard library root.
2. The directory containing the startup `.kn` file passed to `klyn`.
3. Each directory passed through `-kp` or `--klasspath`, from left to right.
4. Each directory listed in `$KLASSPATH`, from left to right.
5. The current working directory, if it was not already added as the startup directory.

Security first

This order prevents an application or launch directory from replacing standard library classes. For example, a local `klyn/String.kn` will not override the real `klyn.String` implementation.

Startup Source Directory

The startup directory is the folder that contains the script you launch, not necessarily the shell current directory.

    cd ~/Klyn
    klyn tools/deepcodia/DeepCodiaApp.kn

In this example, Klyn searches `~/Klyn/tools/deepcodia` before explicit klasspath roots, before `$KLASSPATH` and before `~/Klyn`. This keeps applications relocatable without making the current directory more powerful than the application root.

Using Klasspath Roots

Use `-kp` or `--klasspath` when an application depends on additional source roots outside its startup directory. On Linux, entries are separated with `:`. On Windows, entries are separated with `;`.

    klyn -kp "/opt/klyn-libs:/home/me/shared-klyn" app/Main.kn
    klyn --klasspath "/opt/klyn-libs" app/Main.kn

For reproducible launch commands, prefer the explicit command-line option. Environment variables remain useful for developer shells and CI jobs that share a common dependency layout.

    export KLASSPATH="/opt/klyn-libs:/home/me/shared-klyn"
    klyn app/Main.kn

Klyn also accepts the historical `KLYNPATH` variable when `KLASSPATH` is not defined, but new projects should use `KLASSPATH`.

Compilation Cache

Class lookup and object caching are separate concerns. Once a source file has been resolved, the compiler reuses its cached `.o` file when that object is newer than the corresponding `.kn` source. If the source changes, Klyn recompiles it automatically.

Next Step

Continue with Coding Conventions before moving to the core syntax chapters.