[proofplan]
We prove that if $A \subset \Omega$ is a compact analytic subset of complex codimension at least $2$ and $f \in \mathcal{O}(\Omega \setminus A)$, then $f$ extends uniquely to a [holomorphic function](/page/Holomorphic%20Function) on all of $\Omega$. The argument has three ingredients: (1) a topological fact that removing a set of real codimension $\geq 4$ from a connected open subset of $\mathbb{R}^{2n}$ leaves it connected, (2) a local extension argument using the Hartogs extension phenomenon near each point of $A$, and (3) the [Identity Principle](/theorems/3357) for uniqueness.
[/proofplan]
[step:Establish that $\Omega \setminus A$ is connected]
The set $A$ has complex codimension $\geq 2$ in $\mathbb{C}^n$, so it has real dimension at most $2n - 4$. Since $\Omega$ is open and connected in $\mathbb{C}^n \cong \mathbb{R}^{2n}$, and a connected open subset of $\mathbb{R}^{2n}$ remains connected after removing a closed subset of real dimension at most $2n - 4 \leq 2n - 2$ (the complement of a [closed set](/page/Closed%20Set) of real codimension $\geq 2$ in a connected open subset of $\mathbb{R}^m$ is connected for $m \geq 2$), the set $\Omega \setminus A$ is connected.
More precisely: $A$, being a compact analytic subset of complex codimension $\geq 2$, is contained in a finite union of smooth real submanifolds of $\mathbb{R}^{2n}$ of dimension at most $2n - 4$. A connected [open set](/page/Open%20Set) in $\mathbb{R}^{2n}$ cannot be disconnected by removing a closed subset of Hausdorff dimension at most $2n - 4 < 2n - 1$, since path-connectivity in the complement is preserved: any two points in $\Omega \setminus A$ can be connected by a path in $\Omega$ that avoids $A$ by a transversality argument (generic paths miss sets of codimension $\geq 2$ in $\mathbb{R}^{2n}$).
[guided]
Why is the codimension condition $\geq 2$ essential here? In $\mathbb{R}^{2n}$, a [closed set](/page/Closed%20Set) can disconnect an [open set](/page/Open%20Set) only if it has dimension at least $2n - 1$ (codimension $1$). An analytic set of complex codimension $\geq 2$ has real codimension $\geq 4$, which is strictly greater than $1$ whenever $n \geq 2$. This is a large margin: even a real hypersurface (codimension $1$) can disconnect, but our set has codimension at least $4$.
Concretely, to show $\Omega \setminus A$ is connected, take any two points $p, q \in \Omega \setminus A$. Since $\Omega$ is connected, there exists a continuous path $\gamma: [0,1] \to \Omega$ with $\gamma(0) = p$, $\gamma(1) = q$. If $\gamma$ meets $A$, we perturb it: the space of smooth paths from $p$ to $q$ in $\Omega$ is infinite-dimensional, while $A$ has real dimension $\leq 2n - 4$. By a standard transversality argument, the set of paths meeting $A$ has infinite codimension in path space, so a generic small perturbation of $\gamma$ avoids $A$ entirely.
This topological fact fails for complex codimension $1$: a complex hypersurface in $\mathbb{C}^n$ has real dimension $2n - 2$, which is codimension $2$ in $\mathbb{R}^{2n}$. While codimension $2$ still does not disconnect (for $n \geq 2$), the [extension theorem](/theorems/59) itself fails for codimension-$1$ singularities. The function $f(z) = 1/z_1$ on $\mathbb{C}^2 \setminus \{z_1 = 0\}$ demonstrates this: $\{z_1 = 0\}$ has complex codimension $1$, and $f$ does not extend holomorphically across it.
[/guided]
[/step]
[step:Extend $f$ locally across each point of $A$ using the Hartogs extension phenomenon]
Fix $a \in A$. Since $A$ has complex codimension $\geq 2$ at $a$, there exist local holomorphic coordinates $(w_1, \ldots, w_n)$ centred at $a$ such that $A$ is contained in the set $\{w_1 = 0, w_2 = 0\}$ (or more generally a set of complex codimension $\geq 2$) near $a$.
Choose a polydisc $P = \mathbb{D}^n(a, r) \subset \Omega$. Since $A \cap P$ has complex codimension $\geq 2$, the set $P \setminus A$ contains a Hartogs figure: there exists $\varepsilon > 0$ such that the set
\begin{align*}
H = \{z \in P : |z_1 - a_1| > r_1 - \varepsilon \text{ or } |z_2 - a_2| > r_2 - \varepsilon \text{ or } \cdots\}
\end{align*}
(a suitable "frame" of the polydisc) is contained in $P \setminus A$. More precisely, since $A \cap P$ has real dimension $\leq 2n - 4$, for a sufficiently small polydisc $P$, the function $f$ is defined and holomorphic on a Hartogs-type domain inside $P$ whose complement is the small set $A \cap P$.
By the [Hartogs Extension Theorem](/theorems/3401) (applied iteratively: first extend in two of the variables while the others are held fixed, using the codimension-$2$ condition to guarantee the Hartogs figure geometry), the restriction $f|_{P \setminus A}$ extends to a [holomorphic function](/page/Holomorphic%20Function) $F_a \in \mathcal{O}(P)$.
[guided]
The local argument works as follows. Since $A$ has complex codimension $\geq 2$ near $a$, after a generic linear change of coordinates we may assume $A \cap P$ is contained in the analytic set $\{g_1 = g_2 = 0\}$ for some holomorphic functions $g_1, g_2$ on $P$. Consider the two-dimensional slice through $a$ in the $(w_1, w_2)$-plane (holding $w_3, \ldots, w_n$ fixed). In this slice, $A$ consists of isolated points (complex codimension $2$ in $\mathbb{C}^n$ becomes complex codimension $2$ in $\mathbb{C}^2$, which is a discrete set of points).
For each such slice, the function $f$ is holomorphic on a punctured neighbourhood of these isolated points in $\mathbb{C}^2$. The [No Isolated Singularities](/theorems/3384) result (which itself follows from Hartogs extension) shows $f$ extends across each such point.
Ranging over all slices as the parameters $(w_3, \ldots, w_n)$ vary, we obtain a holomorphic extension of $f$ to all of $P$. The extension depends holomorphically on the parameters by [Osgood's Lemma](/theorems/3379) (the extension in each slice depends on the parameters, and separate holomorphicity implies joint holomorphicity).
[/guided]
[/step]
[step:Patch the local extensions and conclude by the identity principle]
For each $a \in A$, the local extension $F_a \in \mathcal{O}(P_a)$ (where $P_a$ is a polydisc around $a$) satisfies $F_a = f$ on $P_a \setminus A$. On the overlap of two such polydiscs $P_a \cap P_b$, the holomorphic functions $F_a$ and $F_b$ agree on $P_a \cap P_b \setminus A$, which is open and non-empty (since $A$ has no interior). By the [Identity Principle](/theorems/3357) (applicable because $P_a \cap P_b$ is connected — the removal of $A$ from a polydisc does not disconnect it, as shown in the first step), $F_a = F_b$ on all of $P_a \cap P_b$.
Define the extension $\tilde{f}: \Omega \to \mathbb{C}$ by
\begin{align*}
\tilde{f}(z) = \begin{cases} f(z) & \text{if } z \in \Omega \setminus A, \\ F_a(z) & \text{if } z \in P_a \text{ for some } a \in A. \end{cases}
\end{align*}
By the agreement on overlaps, $\tilde{f}$ is well-defined. It is holomorphic on $\Omega \setminus A$ (where it equals $f$) and on each $P_a$ (where it equals $F_a$). Since $\{P_a : a \in A\} \cup \{\Omega \setminus A\}$ is an open cover of $\Omega$, the function $\tilde{f}$ is holomorphic on $\Omega$.
Uniqueness follows from the [Identity Principle](/theorems/3357): if $\tilde{f}_1$ and $\tilde{f}_2$ are two holomorphic extensions, they agree on $\Omega \setminus A$ (both equal $f$), which is a connected open subset of $\Omega$, so they agree on all of $\Omega$.
[/step]