Finding $A \subseteq \omega_1$ such that $\omega_1^{L[A]} = \omega_1$ and $\omega_2^{L[A]} = \omega_2$ Exercise 13.31 of Jech's Set Theory says:

If $\omega_2$ is not inaccessible in $L$, then there exists $A \subseteq \omega_1$ such that $\omega_1^{L[A]} = \omega_1$ and $\omega_2^{L[A]} = \omega_2$.

Jech also specifically noted that $\mathsf{AC}$ is needed for this exercise.
If we weaken the statement to allowing $A \subseteq \omega_2$, then we may encode the order-type of all ordinals $\alpha < \omega_2$ into subsets of $\omega_1$, say $A_\alpha$, and by $\mathsf{AC}$ we obtain a set $A$ such that $A_\alpha = \{\xi : (\alpha,\xi) \in A\}$. Then one may prove that $\omega_1^{L[A]} = \omega_1$ and $\omega_2^{L[A]} = \omega_2$ in $L[A]$, and convert $A$ to a subset of $\omega_2$ via the canonical well-ordering. Here we did not use the fact that $\omega_2$ is not inaccessible in $L$.
The following is my guess on the approach to obtain an $A \subseteq \omega_1$ instead: Since $\omega_2$ is not inaccessible in $L$, there exists a cardinal $\kappa$ such that $(\omega_2 \leq 2^{\kappa^L})^L$. Since $\kappa^L$ is an ordinal of cardinality $\leq \aleph_1$, we may perhaps be able to "collect" all the $A_\alpha$'s above using subsets of $\kappa^L \subseteq \omega_1$, so that $\omega_1^{L[A]} = \omega_1$ and $\omega_2^{L[A]} = \omega_2$. But I'm not sure if this is the right direction to go.
 A: With the help of Andreas Blass' comment I was able to solve the exercise. I will post the full solution here.
Lemma (Exercise 13.28). Let $\alpha \geq \omega$ be a countable ordinal. There exists $A \subseteq \omega$ such that $\alpha$ is countable in $L[A]$.
Proof. Let $f : \omega \to \alpha$ be one-to-one and onto. Define $W \subseteq \omega \times \omega$ by stipulating that $n \, W \, m$ iff $f(n) \in f(m)$. Then $W$ is a well-ordering of order-type $\alpha$. Since "$W$ is a well-ordering of order-type $\alpha$" is $\Delta_0$ relative to $\alpha$, we have that $L[W] \models$ "$W$ is a well-ordering of order-type $\alpha$", so $L[W] \models \alpha$ is countable.
Let $A = \Gamma(W) \subseteq \omega$, where $\Gamma$ is the canonical well-ordering of $\mathbf{ORD}^2$ (recall that $\Gamma(\omega_\alpha \times \omega_\alpha) = \omega_\alpha$ for all ordinals $\alpha$). Since $\Gamma$ is definable without parameters, we have that $A \in L[W]$ and $W \in L[A]$. Thus $L[A] = L[W]$. Note that $\mathsf{AC}$ is not used in this proof. $\square$
Lemma (Exercise 13.30). There exists $A \subseteq \omega_1$ such that $\omega_1 = \omega_1^{L[A]}$.
Proof. By the above lemma, for each $\alpha < \omega_1$ there exists $A_\alpha \subseteq \omega$ such that $\alpha$ is countable in $L[A_\alpha]$. Let $F$ be the function $\alpha \mapsto A_\alpha$ (this is a choice function, so $\mathsf{AC}$ is required), and let $A = \bigcup_{\alpha < \omega_1} \{\alpha\} \times F(\alpha) \subseteq \omega_1 \times \omega_1$. Then $L[A_\alpha] \subset L[A]$, and since "$X$ is countable'' is $\Sigma_1$, hence upward absolute, $\alpha$ is countable in $L[A]$. Thus $\omega_1^{L[A]} = \omega_1$.
To ensure that $A \subseteq \omega_1$, we simply consider the canonical well-ordering $\Gamma$ on $\omega_1 \times \omega_1$. Then $L[\Gamma(A)] = L[A]$, as we argued in the previous lemma. $\square$
Theorem (Exercise 13.31). If $\omega_2$ is not inaccessible in $L$, then there exists $A \subseteq \omega_1$ such that $\omega_1^{L[A]} = \omega_1$ and $\omega_2^{L[A]} = \omega_2$.
Proof. Since $L \models \mathsf{GCH}$, we have that in $L$, $\omega_2$ is inaccessible iff it is a regular limit cardinal (weakly inaccessible). As "$\alpha$ is a regular cardinal'' is $\Pi_1$we have that $\omega_2$ is a regular cardinal in $L$. Therefore, if $\omega_2$ is not inaccessible in $L$, then $\omega_2$ is a successor cardinal in $L$.
Let $\alpha < \omega_2$ be an ordinal such that $\omega_2 = \alpha^+$ in $L$. By repeating the proof in the first lemma but for $\alpha \geq \omega_1$ and $|\alpha| = \omega_1$, one may obtain an $A \subseteq \omega_1$ such that $|\alpha| = \omega_1^{L[A]}$ in $L[A]$. By the second lemma, one obtain another $B \subseteq \omega_1$ such that $\omega_1 = \omega_1^{L[B]}$ ($\mathsf{AC}$ is used here). Thus we have that $\omega_1^{L[A \times B]} = \omega_1$ and $\omega_2^{L[A \times B]} = \omega_2$. Now convert $A \times B \subseteq \omega_1 \times \omega_1$ to a subset of $\omega_1$ using the canonical well-ordering $\Gamma$. $\square$
