I first heard this song on Pete Seeger's 1966 album Dangerous Songs!? Here is his version. I next heard it in the TV movie The Birdmen in 1971. The Birdmen is a fictionalized account of a very real plan by Allied POWs to build a glider and escape from Colditz Castle during World War II. The soundtrack song and more on the movie and history of the real escape plan is here. And a traditional German rendering of the song is here.
The only known picture of the real Colditz glider constructed by Allied POWs.
Here is the Wikipedia citation for Die Gedanken sind frei:
Die Gedanken sind frei
"Die Gedanken sind frei" is a German song about the freedom of thought. The text and the melody can be found in Lieder der Brienzer Mädchen, printed in Bern, Switzerland between 1810 and 1820. The original lyricist and the composer are unknown, though the most popular version Aus Neukirch bei Schönau (Nowy Kościół) was rendered by Hoffmann von Fallersleben in his 1842 collection Schlesische Volkslieder mit Melodien.
The idea represented in the title — that thoughts are free — was expressed as early as in Antiquity and became prominent again in the Middle Ages, when Walther von der Vogelweide (c.1170-1230) wrote: joch sint iedoch gedanke frî ("yet still thoughts are free"). In the 12th century Austrian minnesinger Dietmar von Aist (presumably) had composed the song Gedanke die sint ledic vrî ("only thoughts are free"). About 1229 Freidank wrote: diu bant mac nieman vinden, diu mîne gedanke binden. ("this band may no one twine, that will my thoughts confine").
The text as it first occurred on leaflets about 1780 originally had four strophes to which a fifth was later added. Today, their order may vary. An early version in the shape of a dialogue between a captive and his beloved can be found under the title Lied des Verfolgten im Thurm. Nach Schweizerliedern ("Song of the persecuted in the tower. After Swiss songs") in Achim von Arnim and Clemens Brentano's circa 1805 folk poetry collection Des Knaben Wunderhorn, Vol. III. This version was given a new musical setting by Gustav Mahler in his 1898 Lieder aus "Des Knaben Wunderhorn" for voice and orchestra.
Die Gedanken sind frei, wer kann sie erraten,
sie fliegen vorbei wie nächtliche Schatten.
Kein Mensch kann sie wissen, kein Jäger erschießen
mit Pulver und Blei, Die Gedanken sind frei!
Ich denke was ich will und was mich beglücket,
doch alles in der Still', und wie es sich schicket.
Mein Wunsch und Begehren kann niemand mir wehren,
es bleibet dabei: Die Gedanken sind frei!
Und sperrt man mich ein im finsteren Kerker,
das alles sind rein vergebliche Werke.
Denn meine Gedanken zerreißen die Schranken
und Mauern entzwei, die Gedanken sind frei!
Drum will ich auf immer den Sorgen absagen
und will mich auch nimmer mit Grillen mehr plagen.
Man kann ja im Herzen stets lachen und scherzen
und denken dabei: Die Gedanken sind frei!
Ich liebe den Wein, mein Mädchen vor allen,
sie tut mir allein am besten gefallen.
Ich sitz nicht alleine bei einem Glas Weine,
mein Mädchen dabei: Die Gedanken sind frei!
Thoughts are free, who can guess them?
They flee by like nocturnal shadows.
No man can know them, no hunter can shoot them,
with powder and lead: Thoughts are free!
I think what I want, and what delights me,
still always reticent, and as it is suitable.
My wish and desire, no one can deny me
and so it will always be: Thoughts are free!
And if I am thrown into the darkest dungeon,
all this would be futile work,
because my thoughts tear all gates
and walls apart. Thoughts are free!
So I will renounce my sorrows forever,
and never again will torture myself with some fancy ideas.
In one's heart, one can always laugh and joke
and think at the same time: Thoughts are free!
I love wine, and my girl even more,
Only I like her best of all.
I'm not alone with my glass of wine,
my girl is with me: Thoughts are free!
The rhyme scheme of the lyrics is a - b/ a - b/ c - c/ d - d.
Since the days of the Carlsbad Decrees and the Age of Metternich Die Gedanken sind frei was a popular protest song against political repression and censorship, especially among the banned Burschenschaften student fraternities. In the aftermath of the 1848 German Revolution and in Nazi Germany, the song was proscribed. It had importance for the White Rose anti-Nazi resistance movement in Germany.  One night in 1942 Sophie Scholl played the song on her recorder outside the walls of Ulm prison where her father Robert had been detained for calling Adolf Hitler a "Scourge of God".
Pete Seeger recorded the song in 1966 on his Dangerous Songs!? album. Norwegian composer Alf Cranner translated and recorded it as Din tanke er fri in 1985. Parts of the poem were also taken as the basis of a song on the 2005 album of the band Brazilian Girls.
In Canadian author Jean Little's book From Anna the song is used to represent the freedom the titular character's father craves for his children, and as such figures predominantly into the plot at the beginning of the novel.
Die Gedanken sind frei was used as the theme and was sung by the Allied Prisoners of War in the 1971 TV movie The Birdmen, which was a fictionalized dramatization of an attempt to escape from the German Oflag IV-C camp at Colditz Castle in World War II. It is also featured in the 1998 German movie 23 about the hacker Karl Koch.
In recent years the song again gained popularity among the movement against internet censorship in Germany.