# Can a package detect whether it was imported in the REPL vs inside another package?

**URL:** https://discourse.julialang.org/t/can-a-package-detect-whether-it-was-imported-in-the-repl-vs-inside-another-package/136449
**Category:** Internals & Design
**Created:** [March 29, 2026, 3:20pm UTC](https://discourse.julialang.org/t/can-a-package-detect-whether-it-was-imported-in-the-repl-vs-inside-another-package/136449 "2026-03-29T15:20:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [March 29, 2026, 3:20pm UTC](https://discourse.julialang.org/t/can-a-package-detect-whether-it-was-imported-in-the-repl-vs-inside-another-package/136449/1 "2026-03-29T15:20:04Z")

</div>

Continuing the discussion from [[ANN] UseAll.jl – Temporarily Demodularize Julia Code](https://discourse.julialang.org/t/ann-useall-jl-temporarily-demodularize-julia-code/136432/6):

> [@\[ANN\] UseAll.jl – Temporarily Demodularize Julia Code](https://discourse.julialang.org/t/ann-useall-jl-temporarily-demodularize-julia-code/136432/6):
>
> Is it possible for a package to detect whether it is being used/imported in the REPL or inside another package?

Even outside of the specific context of what makes sense for that `UseAll` package, that seems like an interesting question by itself.

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [March 29, 2026, 4:25pm UTC](https://discourse.julialang.org/t/can-a-package-detect-whether-it-was-imported-in-the-repl-vs-inside-another-package/136449/2 "2026-03-29T16:25:38Z")

</div>

Not really, no.

---

<div class="post-metadata">

### Author: ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)
#### Post date: [March 29, 2026, 4:57pm UTC](https://discourse.julialang.org/t/can-a-package-detect-whether-it-was-imported-in-the-repl-vs-inside-another-package/136449/3 "2026-03-29T16:57:57Z")

</div>

```julia-auto
module MyPackage
function __init__ ()
    if !isinteractive()
        error("MyPackage is intended for interactive REPL use only.")
    end
end
end

```

This won’t prevent `OtherPackage` from accidentally making `MyPackage` a dependency, but at least would break `OtherPackage`’s CI, thus also preventing it’s registration.

---

<div class="post-metadata">

### Author: ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)
#### Post date: [March 30, 2026, 5:02am UTC](https://discourse.julialang.org/t/can-a-package-detect-whether-it-was-imported-in-the-repl-vs-inside-another-package/136449/4 "2026-03-30T05:02:00Z")

</div>

You can check which module has a specific symbol in its namespace

```julia
julia> using UseAll

julia> filter(x -> isdefined(x, Symbol("@useall")), Base.loaded_modules_array())
2-element Vector{Module}:
 Main
 UseAll

```

AFAIK it’s guaranteed, that at least one binding is in the importing namespace. So in general you can loop through all names of all modules and check with `parentmodule` whether it’s a binding of your package.

However, this does not work in ` __init__ `, as the binding seems to be imported only after ` __init__ ` finishes, so you would need to use `async` with some `sleep` to do the check after ` __init__ ` finished.

With `Base.active_repl`, `isinteractive` and the above, I think you have all the building blocks to detect the specific conditions your package is operating in.

So while it seems to be possible, I think it somehow resembles [COMEFROM](https://en.wikipedia.org/wiki/COMEFROM) :-).
