# How to Enable Context Receiver in Kotlin multiplatform?

**URL:** <https://discuss.kotlinlang.org/t/how-to-enable-context-receiver-in-kotlin-multiplatform/28595>\
**Category:** Multiplatform\
**Created:** [May 10, 2024, 8:13am UTC](https://discuss.kotlinlang.org/t/how-to-enable-context-receiver-in-kotlin-multiplatform/28595 "2024-05-10T08:13:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefanus.ayudha](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/stefanus.ayudha/32/10729_2.png) [@stefanus.ayudha](https://discuss.kotlinlang.org/u/stefanus.ayudha)\
**Post date:** [May 10, 2024, 8:13am UTC](https://discuss.kotlinlang.org/t/how-to-enable-context-receiver-in-kotlin-multiplatform/28595/1 "2024-05-10T08:13:33Z")

</div>

I tried to do this:

```kotlin
tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs += listOf("-Xcontext-receivers")
    }
}

```

but it din’t work.  
How to enable it properly in kotlin multiplatform project?

---

<div class="post-metadata">

**Author:** ![brunojcm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/brunojcm/32/5116_2.png) [@brunojcm](https://discuss.kotlinlang.org/u/brunojcm)\
**Post date:** [May 13, 2024, 5:03am UTC](https://discuss.kotlinlang.org/t/how-to-enable-context-receiver-in-kotlin-multiplatform/28595/2 "2024-05-13T05:03:41Z")

</div>

I don’t have an example handy right now, but I’d be surprised if it’s not documented here: [Compiler options in the Kotlin Gradle plugin | Kotlin Documentation](https://kotlinlang.org/docs/gradle-compiler-options.html#for-all-kotlin-compilation-tasks)

---

<div class="post-metadata">

**Author:** ![Tassilo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tassilo/32/8548_2.png) [@Tassilo](https://discuss.kotlinlang.org/u/Tassilo)\
**Post date:** [May 13, 2024, 8:06pm UTC](https://discuss.kotlinlang.org/t/how-to-enable-context-receiver-in-kotlin-multiplatform/28595/3 "2024-05-13T20:06:48Z")

</div>

As far as I know, the entire context-receivers feature seems to only be supported by the JVM platform as of now. Meaning, given your build-script, it should only work in the `jvmMain` and `jvmTest` source set respectively.

I might be wrong though.

---

<div class="post-metadata">

**Author:** ![MarDSoul](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mardsoul/32/11100_2.png) [@MarDSoul](https://discuss.kotlinlang.org/u/MarDSoul)\
**Post date:** [February 21, 2025, 8:23pm UTC](https://discuss.kotlinlang.org/t/how-to-enable-context-receiver-in-kotlin-multiplatform/28595/4 "2025-02-21T20:23:32Z")

</div>

I’ve enabled by this:

```auto
kotlin {
    sourceSets {
        val main by getting
        main.dependencies {
            implementation(libs.compose.resources)
        }
        main {
            compilerOptions {
                freeCompilerArgs.add("-Xcontext-receivers")
            }
        }
    }
}

```

The project was only for desktop

---

<div class="post-metadata">

**Author:** ![Landei](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/landei/32/9407_2.png) [@Landei](https://discuss.kotlinlang.org/u/Landei)\
**Post date:** [February 21, 2025, 9:05pm UTC](https://discuss.kotlinlang.org/t/how-to-enable-context-receiver-in-kotlin-multiplatform/28595/5 "2025-02-21T21:05:14Z")

</div>

Just as a heads up, context receivers won’t end up in Kotlin. The new concept is called “[context parameters](https://github.com/Kotlin/KEEP/blob/context-parameters/proposals/context-parameters.md)”, it’s similar (basically context receivers with named arguments) but unfortunately it’s not yet available, not even experimental.

---

<div class="post-metadata">

**Author:** ![kyay10](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@kyay10](https://discuss.kotlinlang.org/u/kyay10)\
**Post date:** [February 21, 2025, 9:15pm UTC](https://discuss.kotlinlang.org/t/how-to-enable-context-receiver-in-kotlin-multiplatform/28595/6 "2025-02-21T21:15:41Z")

</div>

It’s actually available in `2.1.20-Beta1` I believe (Definitely a beta version for `2.1.20`) with the argument `-Xcontext-parameters`. It sadly has no IDE support yet though
