# Feature request: --project=@script\_dir

**URL:** https://discourse.julialang.org/t/feature-request-project-script-dir/124828
**Category:** Internals & Design
**Tags:** environment, scripting, project
**Created:** [January 16, 2025, 11:47am UTC](https://discourse.julialang.org/t/feature-request-project-script-dir/124828 "2025-01-16T11:47:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)
#### Post date: [January 16, 2025, 11:47am UTC](https://discourse.julialang.org/t/feature-request-project-script-dir/124828/1 "2025-01-16T11:47:22Z")

</div>

I’d like to run a command like

```
julia --project=@script_dir long/path/to/my/package/src/script.jl

```

rather than what I currently have to use, where the path is repeated verbatim

```
julia --project=long/path/to/my/package long/path/to/my/package/src/script.jl

```

Another inconvenient workaround is using `Pkg` within the script to activate the environment of `@ __DIR__ ` or the parent path thereof.

The proposed behavior is that `julia` wil recursively search the user-supplied `script_dir` and parent directories until `Project.toml` is found and use that as the virtual environment. What do you think?

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [January 16, 2025, 12:02pm UTC](https://discourse.julialang.org/t/feature-request-project-script-dir/124828/2 "2025-01-16T12:02:44Z")

</div>

Maybe try `@scriptdir`? [Allow `--project=@scriptdir` for easier co-packaging of scripts and p… by Keno · Pull Request #50864 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/50864)

Edit: ah maybe it’s `@script`: [Rename @scriptdir to @script, and look for environments in parent directories · Issue #53352 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/53352)

---

<div class="post-metadata">

### Author: ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)
#### Post date: [January 16, 2025, 12:32pm UTC](https://discourse.julialang.org/t/feature-request-project-script-dir/124828/3 "2025-01-16T12:32:06Z")

</div>

Thanks for the links! I vaguely remember reading about it somewhere, but I couldn’t find any information about it when I ran `julia -h` today to look at the command line option list.

I just tried `@script` and it didn’t work. Looks like there’s an open issue about it:

> <https://github.com/JuliaLang/julia/issues/55069>
>
> Launching a script with \`julia --project=@script foo.jl\` does not activate the s…cript project if ran outside the containing folder. 
> 
> In \`test\_at\_script.jL\`
> \`\`\`julia
> \#!/usr/bin/env -S julia --project=@script
> @info "Check Active Env" Base.active\_project() PROGRAM\_FILE LOAD\_PATH Base.load\_path\_expand("@script")
> 
> \# Check that ../Project.toml got activated
> active\_project = realpath(Base.active\_project())
> expected = realpath(joinpath(@\_\_DIR\_\_, "..", "Project.toml"))
> @assert active\_project == expected "$active\_project != $expected"
> \`\`\`
> 
> Expected Directory Structure:
> \`\`\`
> Documents/
> julia\_at\_script\_issue/
> Project.toml
> bin/
> test\_at\_script.jl
> \`\`\`
> 
> \> Alternatively, run \`script.sh\` in the attached achieve: \[julia\_at\_script\_issue.zip\](https://github.com/user-attachments/files/16130231/julia\_at\_script\_issue.zip)
> 
> Running from \`Documents/julia\_at\_script\_issue/\` with \`julia --startup-file=no --project=@script bin/test\_at\_script.jl\` or \`./bin/test\_at\_script.jl\` gives the following (expected) output:
> 
> \`\`\`shell
> ❯ julia --startup-file=no --project=@script bin/test\_at\_script.jl
> ┌ Info: Check Active Env
> │ Base.active\_project() = "/Users/alexwadell/Documents/julia\_at\_script\_issue/Project.toml"
> │ PROGRAM\_FILE = "bin/test\_at\_script.jl"
> │ LOAD\_PATH =
> │ 3-element Vector{String}:
> │ "@"
> │ "@v#.#"
> │ "@stdlib"
> └ Base.load\_path\_expand("@script") = "Project.toml"
> \`\`\`
> However, running from outside of \`Documents/julia\_at\_script\_issue\` activates the default environment instead:
> 
> \`\`\`shell
> ❯ julia --project=@script --startup-file=no julia\_at\_script\_issue/bin/test\_at\_script.jl
> ┌ Info: Check Active Env
> │ Base.active\_project() = "/Users/alexwadell/.julia/environments/v1.11/Project.toml"
> │ PROGRAM\_FILE = "julia\_at\_script\_issue/bin/test\_at\_script.jl"
> │ LOAD\_PATH =
> │ 3-element Vector{String}:
> │ "@"
> │ "@v#.#"
> │ "@stdlib"
> └ Base.load\_path\_expand("@script") = "julia\_at\_script\_issue/Project.toml"
> ERROR: LoadError: AssertionError: /Users/alexwadell/.julia/environments/v1.11/Project.tom
> l != /Users/alexwadell/Documents/julia\_at\_script\_issue/Project.toml
> Stacktrace:
> \[1\] top-level scope
> @ ~/Documents/julia\_at\_script\_issue/bin/test\_at\_script.jl:5
> in expression starting at /Users/alexwadell/Documents/julia\_at\_script\_issue/bin/test\_at\_scr
> ipt.jl:5
> \`\`\`
> 
> Oddly, enough \`Base.load\_path\_expand("@cript")\` resolves the correct project file.
> 
> Setting \`JULIA\_LOAD\_PATH\` directly does result in the expect behavior outside the project directory:
> 
> \`\`\`shell
> ❯ JULIA\_LOAD\_PATH=@script julia --startup-file=no julia\_at\_script\_issue/bin/test\_at\_script.jl
> ┌ Info: Check Active Env
> │ Base.active\_project() = "julia\_at\_script\_issue/Project.toml"
> │ PROGRAM\_FILE = "julia\_at\_script\_issue/bin/test\_at\_script.jl"
> │ LOAD\_PATH =
> │ 1-element Vector{String}:
> │ "@script"
> └ Base.load\_path\_expand("@script") = "julia\_at\_script\_issue/Project.toml"
> \`\`\`
> 
> \## Julia Info
> 
> \`\`\`
> Julia Version 1.11.0-rc1
> Commit 3a35aec36d1 (2024-06-25 10:23 UTC)
> Build Info:
> Official https://julialang.org/ release
> Platform Info:
> OS: macOS (arm64-apple-darwin22.4.0)
> CPU: 8 × Apple M1
> WORD\_SIZE: 64
> LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
> Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
> Environment:
> JULIA\_PKG\_USE\_CLI\_GIT = true
> \`\`\`
> 
> \## Related PRs
> \#50864 
> \#53356

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [January 16, 2025, 4:14pm UTC](https://discourse.julialang.org/t/feature-request-project-script-dir/124828/4 "2025-01-16T16:14:56Z")

</div>

This should be fixed and now that my attention is called to the PR to fix and test it, I’ll make sure those get merged (they seem to be stalled for lack of review). In the meantime, if you put this at the top of your script file, it has the same effect:

```julia
push!(empty!(LOAD_PATH), @ __DIR__ )

```
