diff --git a/DESCRIPTION b/DESCRIPTION
index fa9d766d4..b33ac8d0a 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -56,7 +56,6 @@ Collate:
     'qenv-get_var.R'
     'qenv-get_warnings.R'
     'qenv-join.R'
-    'qenv-replace_code.R'
     'qenv-show.R'
     'qenv-within.R'
     'teal.code-package.R'
diff --git a/R/qenv-replace_code.R b/R/qenv-replace_code.R
deleted file mode 100644
index f61832280..000000000
--- a/R/qenv-replace_code.R
+++ /dev/null
@@ -1,58 +0,0 @@
-#' Replace code
-#'
-#' Replace last element of code stored in `qenv`.
-#'
-#' Replace the last element of the character vector stored in `@code` with provided `code`.
-#' This can be used to mask sensitive information, e.g. credentials.
-#'
-#' @param object `qenv`
-#' @param code (`character` or `language`) code to set
-#'
-#' @return A modified `qenv`.
-#'
-#' @seealso [`qenv-class`], [`eval_code`]
-#'
-#' @section Examples:
-#' `q <- qenv()` \cr
-#' `q <- eval_code(q, expression(i <- iris, ii <- subset(i, Species == "virginica")))` \cr
-#' `get_code(q)` \cr
-#' `q <- replace_code(q, expression(i <- iris, ii <- subset(i, Species != "virginica")))` \cr
-#' `get_code(q)` \cr
-
-#' @name replace_code
-#' @rdname replace_code
-#' @aliases replace_code,qenv,character-method
-#' @aliases replace_code,qenv,language-method
-#' @aliases replace_code,qenv,expression-method
-#' @aliases replace_code,qenv.error,ANY-method
-
-#' @keywords internal
-setGeneric("replace_code", function(object, code) standardGeneric("replace_code"))
-
-#' @keywords internal
-setMethod("replace_code", signature = c("qenv", "character"), function(object, code) {
-  masked_code <- get_code(object)
-  code_lines <- unlist(strsplit(masked_code, "\n"))
-
-  if (!is.null(code_lines)) {
-    code_lines[length(code_lines)] <- code
-    object@code <- paste(code_lines, collapse = "\n")
-  }
-
-  object
-})
-
-#' @keywords internal
-setMethod("replace_code", signature = c("qenv", "language"), function(object, code) {
-  replace_code(object, code = paste(lang2calls(code), collapse = "\n"))
-})
-
-#' @keywords internal
-setMethod("replace_code", signature = c("qenv", "expression"), function(object, code) {
-  replace_code(object, code = paste(lang2calls(code), collapse = "\n"))
-})
-
-#' @keywords internal
-setMethod("replace_code", signature = c("qenv.error", "ANY"), function(object, code) {
-  object
-})
diff --git a/man/replace_code.Rd b/man/replace_code.Rd
deleted file mode 100644
index b77591296..000000000
--- a/man/replace_code.Rd
+++ /dev/null
@@ -1,40 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/qenv-replace_code.R
-\name{replace_code}
-\alias{replace_code}
-\alias{replace_code,qenv,character-method}
-\alias{replace_code,qenv,language-method}
-\alias{replace_code,qenv,expression-method}
-\alias{replace_code,qenv.error,ANY-method}
-\title{Replace code}
-\usage{
-replace_code(object, code)
-}
-\arguments{
-\item{object}{\code{qenv}}
-
-\item{code}{(\code{character} or \code{language}) code to set}
-}
-\value{
-A modified \code{qenv}.
-}
-\description{
-Replace last element of code stored in \code{qenv}.
-}
-\details{
-Replace the last element of the character vector stored in \verb{@code} with provided \code{code}.
-This can be used to mask sensitive information, e.g. credentials.
-}
-\section{Examples}{
-
-\code{q <- qenv()} \cr
-\code{q <- eval_code(q, expression(i <- iris, ii <- subset(i, Species == "virginica")))} \cr
-\code{get_code(q)} \cr
-\code{q <- replace_code(q, expression(i <- iris, ii <- subset(i, Species != "virginica")))} \cr
-\code{get_code(q)} \cr
-}
-
-\seealso{
-\code{\linkS4class{qenv}}, \code{\link{eval_code}}
-}
-\keyword{internal}
diff --git a/tests/testthat/test-qenv-replace_code.R b/tests/testthat/test-qenv-replace_code.R
deleted file mode 100644
index 7b27e7e7d..000000000
--- a/tests/testthat/test-qenv-replace_code.R
+++ /dev/null
@@ -1,42 +0,0 @@
-q <- qenv()
-qq <- within(q, i <- iris)
-
-# argument checks ----
-test_that("object argument accepts qenv", {
-  testthat::expect_no_error(replace_code(qq, "i <- mtcars"))
-})
-
-test_that("object argument accepts qenv.error", {
-  qe <- within(q, stop())
-  testthat::expect_no_error(replace_code(qe, "i <- mtcars"))
-})
-
-test_that("code argument accepts character", {
-  testthat::expect_no_error(replace_code(qq, "i <- mtcars"))
-})
-
-test_that("code argument accepts language", {
-  testthat::expect_no_error(replace_code(qq, quote(i <- mtcars)))
-})
-
-test_that("code argument accepts expression", {
-  testthat::expect_no_error(replace_code(qq, expression(i <- mtcars)))
-})
-
-# code replacement ----
-testthat::test_that("code_replace replaces last element of the code", {
-  qq <- within(qq, m <- mtcars)
-  replacement <- "i <- mtcars"
-  qr <- replace_code(qq, replacement)
-  previous <- get_code(qq)
-  current <- get_code(qr)
-
-  previous <- head(strsplit(previous, split = "\n")[[1]], -1)
-  testthat::expect_identical(current, paste0(c(previous, replacement), collapse = "\n"))
-})
-
-# edge cases ----
-testthat::test_that("no changes are made to empty @code slot", {
-  qe <- replace_code(q, "i <- mtcars")
-  testthat::expect_identical(get_code(qe), character(0L))
-})
