Skip to content

Commit ca1049f

Browse files
Zahin-Mohammad-plugZahin Mohammadfrenck
authored
Persist Claude Code credentials and document AI assistant support (#1129)
Co-authored-by: Zahin Mohammad <ahmedbaysuyev14@gmail.com> Co-authored-by: Franck Nijhof <frenck@frenck.dev>
1 parent 96a0e2a commit ca1049f

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

  • vscode

‎vscode/DOCS.md‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,57 @@ return to the defaults as delivered by this app, do the following:
9696
1. Execute the following command in the terminal window: `reset-settings`.
9797
1. Done!
9898

99+
## Using AI coding assistants
100+
101+
This app is built on [code-server][code-server], which is a build of
102+
VS Code that uses the [Open VSX][open-vsx] extension registry instead of the
103+
Microsoft Marketplace. Microsoft only allows their marketplace to be used by
104+
their own branded builds of Visual Studio Code, so which assistants you can
105+
use is decided by what is published on Open VSX.
106+
107+
- **GitHub Copilot is not available.** The `GitHub.copilot` and
108+
`GitHub.copilot-chat` extensions are published exclusively on the Microsoft
109+
Marketplace and are not on Open VSX, so they cannot be found or installed
110+
from within this app. VS Code may still advertise its built-in AI
111+
features; attempting to enable them fails with
112+
`extension GitHub.copilot-chat not found`.
113+
- **Claude Code works.** The `Anthropic.claude-code` extension is published on
114+
Open VSX and can be installed from the Extensions view as usual. It bundles
115+
its own `claude` binary, so no separate Node.js installation is needed.
116+
117+
Because the app runs behind Home Assistant ingress, browser-based sign-in
118+
flows that redirect back to a `vscode://` URL do not work. Sign in from a
119+
terminal inside the editor instead:
120+
121+
1. Open the Visual Studio Code editor.
122+
1. Click on `Terminal` in the top menu bar and click on `New Terminal`.
123+
1. Run `claude` and use the `/login` command, which prints a URL and asks you
124+
to paste back the code it gives you.
125+
126+
Claude Code keeps its settings and credentials in a configuration folder that
127+
this app points at its own data folder, so your login survives app restarts
128+
and updates.
129+
130+
The bundled `claude` binary lives inside the extension folder. If you want it
131+
on your `PATH` for use in the terminal, add the following to the app's
132+
`init_commands` option:
133+
134+
```yaml
135+
init_commands:
136+
- for f in /data/vscode/extensions/anthropic.claude-code-*/resources/native-binary/claude; do test -x $f && ln -sf $f /usr/local/bin/claude; done; true
137+
```
138+
139+
Init commands run before the editor starts, so the link appears after the
140+
first restart following the installation of the extension.
141+
142+
Claude Code's optional voice input needs ALSA, which the app does not ship.
143+
Add it using the `packages` option if you want to use it:
144+
145+
```yaml
146+
packages:
147+
- libasound2t64
148+
```
149+
99150
## Known issues and limitations
100151

101152
- Can this app run on a Raspberry Pi? Yes, but only if you run a 64 bits
@@ -181,12 +232,14 @@ SOFTWARE.
181232

182233
[addon-badge]: https://my.home-assistant.io/badges/supervisor_addon.svg
183234
[addon]: https://my.home-assistant.io/redirect/supervisor_addon/?addon=a0d7b954_vscode&repository_url=https%3A%2F%2Fgithub.com%2Fhassio-addons%2Frepository
235+
[code-server]: https://github.com/coder/code-server
184236
[contributors]: https://github.com/hassio-addons/app-vscode/graphs/contributors
185237
[discord-ha]: https://discord.gg/c5DvZ4e
186238
[discord]: https://discord.me/hassioaddons
187239
[forum]: https://community.home-assistant.io/t/home-assistant-community-add-on-visual-studio-code/107863?u=frenck
188240
[frenck]: https://github.com/frenck
189241
[issue]: https://github.com/hassio-addons/app-vscode/issues
242+
[open-vsx]: https://open-vsx.org
190243
[reddit]: https://reddit.com/r/homeassistant
191244
[releases]: https://github.com/hassio-addons/app-vscode/releases
192245
[semver]: https://semver.org/spec/v2.0.0

‎vscode/rootfs/etc/s6-overlay/s6-rc.d/code-server/run‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ options+=(--auth none)
2828
export HASS_SERVER="http://supervisor/core"
2929
export HASS_TOKEN="${SUPERVISOR_TOKEN:-}"
3030

31+
# Keep the Claude Code configuration in the persistent data folder. The
32+
# extension host and the integrated terminals inherit this, so both the
33+
# extension and the bundled claude binary use it.
34+
export CLAUDE_CONFIG_DIR="/data/claude"
35+
3136
# Run the code server
3237
cd "${config_path}" || bashio::exit.nok "Could not change working directory"
3338
exec code-server "${options[@]}" "${config_path}"

‎vscode/rootfs/etc/s6-overlay/s6-rc.d/init-user/run‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Persists user settings and installs custom user packages.
66
# ==============================================================================
77
readonly -a DIRECTORIES=(addon_configs addons backup homeassistant media share ssl)
8+
readonly CLAUDE_USER_PATH=/data/claude
89
readonly GIT_USER_PATH=/data/git
910
readonly SSH_USER_PATH=/data/.ssh
1011
readonly ZSH_HISTORY_FILE=/root/.zsh_history
@@ -69,6 +70,31 @@ if ! bashio::fs.file_exists "${GIT_USER_PATH}/.gitconfig"; then
6970
fi
7071
ln -s "${GIT_USER_PATH}/.gitconfig" ~/.gitconfig || bashio::log.warning "Failed linking .gitconfig"
7172

73+
# Store Claude Code settings & credentials in app data folder. The service
74+
# points Claude Code here through CLAUDE_CONFIG_DIR, which covers both of the
75+
# locations it would otherwise use: ~/.claude and ~/.claude.json.
76+
if ! bashio::fs.directory_exists "${CLAUDE_USER_PATH}"; then
77+
mkdir -p "${CLAUDE_USER_PATH}" \
78+
|| bashio::exit.nok 'Failed to create a persistent Claude Code folder'
79+
80+
chmod 700 "${CLAUDE_USER_PATH}" \
81+
|| bashio::exit.nok \
82+
'Failed setting permissions on persistent Claude Code folder'
83+
fi
84+
85+
# Migrate the non-persistent locations left behind by an older app version.
86+
# Existing files are never overwritten, and the originals are left alone;
87+
# they are simply no longer read once CLAUDE_CONFIG_DIR is set.
88+
if bashio::fs.directory_exists ~/.claude; then
89+
cp -a -n ~/.claude/. "${CLAUDE_USER_PATH}/" \
90+
|| bashio::log.warning 'Failed migrating the Claude Code folder'
91+
fi
92+
93+
if bashio::fs.file_exists ~/.claude.json; then
94+
cp -a -n ~/.claude.json "${CLAUDE_USER_PATH}/.claude.json" \
95+
|| bashio::log.warning 'Failed migrating the Claude Code configuration'
96+
fi
97+
7298
# Install user configured/requested packages
7399
if bashio::config.has_value 'packages'; then
74100
apt update \

0 commit comments

Comments
 (0)