Skip to content

Commit ff3fbb2

Browse files
authored
feat(claude-code): add yoloAlias option (#19)
## Summary - Adds a `yoloAlias` boolean option (default: `false`) to the claude-code feature - When enabled, creates a `yolo` alias that expands to `claude --allow-dangerously-skip-permissions` - Configures the alias for **bash** (`.bashrc`), **zsh** (`.zshrc`), and **fish** (function file at `~/.config/fish/functions/yolo.fish`) ## Test plan - [x] `devcontainer features validate ./src` passes - [x] New `claude_code_yolo_alias` scenario tests pass - [x] Existing claude-code scenarios remain green
2 parents 7abdd63 + fc8c781 commit ff3fbb2

6 files changed

Lines changed: 130 additions & 1 deletion

File tree

src/claude-code/NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ By default, the `latest` release channel is installed. You can also specify:
1313

1414
The channel chosen at install time becomes the default for auto-updates.
1515

16+
## YOLO Alias
17+
18+
When `yoloAlias` is set to `true`, a `yolo` shell alias is created that expands to `claude --allow-dangerously-skip-permissions`. The alias is configured for bash, zsh, and fish.
19+
20+
> **Warning:** `--allow-dangerously-skip-permissions` disables Claude Code's normal permission checks and confirmation prompts for potentially sensitive actions. This meaningfully reduces safety and may allow unintended or unsafe changes, so only enable `yoloAlias` if you understand and accept the security implications.
21+
>
22+
> If a `yolo` alias already exists in `.bashrc`/`.zshrc`, or a `yolo.fish` function file already exists, the installer will skip adding it to avoid overwriting your setup.
23+
1624
## Auto-Updates
1725

1826
The native binary automatically updates in the background. Update checks are performed on startup and periodically while running. To disable auto-updates, set the `DISABLE_AUTOUPDATER=1` environment variable.

src/claude-code/devcontainer-feature.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{
22
"id": "claude-code",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"name": "Claude Code",
55
"description": "Installs Claude Code CLI for AI-powered development assistance",
66
"options": {
77
"version": {
88
"type": "string",
99
"default": "latest",
1010
"description": "Version to install. Use 'latest', 'stable', or a specific semver (e.g. '1.0.58')."
11+
},
12+
"yoloAlias": {
13+
"type": "boolean",
14+
"default": false,
15+
"description": "Create a 'yolo' shell alias for 'claude --allow-dangerously-skip-permissions' in bash, zsh, and fish."
1116
}
1217
},
1318
"customizations": {

src/claude-code/install.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,61 @@ if [ -f "$INSTALL_HOME/.local/bin/claude" ] && [ ! -f /usr/local/bin/claude ]; t
5353
echo "Symlinked claude to /usr/local/bin/claude"
5454
fi
5555

56+
# Set up yolo alias if requested
57+
if [ "${YOLOALIAS:-false}" = "true" ]; then
58+
echo "Setting up 'yolo' alias..."
59+
ALIAS_CMD='alias yolo="claude --allow-dangerously-skip-permissions"'
60+
TARGET_HOME="${INSTALL_HOME}"
61+
62+
add_shell_alias_if_missing() {
63+
local rc_file="$1"
64+
local alias_name="$2"
65+
local alias_cmd="$3"
66+
67+
if [ -f "$rc_file" ] && grep -Eq "^[[:space:]]*alias[[:space:]]+${alias_name}=" "$rc_file"; then
68+
echo "Skipping $rc_file: alias '$alias_name' already exists."
69+
return 0
70+
fi
71+
72+
touch "$rc_file"
73+
# Ensure the file ends with a newline before appending
74+
if [ -s "$rc_file" ] && [ "$(tail -c 1 "$rc_file" | wc -l)" -eq 0 ]; then
75+
printf '\n' >> "$rc_file"
76+
fi
77+
printf '%s\n' "$alias_cmd" >> "$rc_file"
78+
}
79+
80+
# bash
81+
add_shell_alias_if_missing "$TARGET_HOME/.bashrc" "yolo" "$ALIAS_CMD"
82+
83+
# zsh
84+
add_shell_alias_if_missing "$TARGET_HOME/.zshrc" "yolo" "$ALIAS_CMD"
85+
86+
# fish — create a function file (idiomatic for fish)
87+
FISH_FUNC_DIR="$TARGET_HOME/.config/fish/functions"
88+
FISH_FUNC_FILE="$FISH_FUNC_DIR/yolo.fish"
89+
FISH_CREATED=false
90+
if [ -f "$FISH_FUNC_FILE" ]; then
91+
echo "Skipping $FISH_FUNC_FILE: function already exists."
92+
else
93+
mkdir -p "$FISH_FUNC_DIR"
94+
cat > "$FISH_FUNC_FILE" << 'FISHEOF'
95+
function yolo --description "claude --allow-dangerously-skip-permissions"
96+
claude --allow-dangerously-skip-permissions $argv
97+
end
98+
FISHEOF
99+
FISH_CREATED=true
100+
fi
101+
102+
# Fix ownership if installing for non-root user
103+
if [ -n "$_REMOTE_USER" ] && [ "$_REMOTE_USER" != "root" ]; then
104+
chown "$_REMOTE_USER" "$TARGET_HOME/.bashrc" "$TARGET_HOME/.zshrc"
105+
if [ "$FISH_CREATED" = true ]; then
106+
chown "$_REMOTE_USER" "$TARGET_HOME/.config" "$TARGET_HOME/.config/fish" "$FISH_FUNC_DIR" "$FISH_FUNC_FILE"
107+
fi
108+
fi
109+
110+
echo "yolo alias configured for bash, zsh, and fish."
111+
fi
112+
56113
echo "Claude Code installed successfully!"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# This test file will be executed against the 'claude_code_yolo_alias' scenario
4+
# to verify that the yolo alias is properly configured.
5+
6+
set -e
7+
8+
# Import test library bundled with the devcontainer CLI
9+
source dev-container-features-test-lib
10+
11+
# Feature-specific tests
12+
check "claude command available" which claude
13+
check "yolo alias in bashrc" bash -c "grep -Fq 'claude --allow-dangerously-skip-permissions' ~/.bashrc"
14+
check "yolo alias in zshrc" bash -c "grep -Fq 'claude --allow-dangerously-skip-permissions' ~/.zshrc"
15+
check "fish yolo function body" bash -c "test -f ~/.config/fish/functions/yolo.fish && grep -Fq 'claude --allow-dangerously-skip-permissions' ~/.config/fish/functions/yolo.fish"
16+
check "yolo resolves in bash" bash -ic "type yolo"
17+
18+
# Report results
19+
reportResults
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# This test file will be executed against the 'claude_code_yolo_alias_with_custom_user' scenario
4+
# to verify that the yolo alias is properly configured for a non-root remoteUser.
5+
6+
set -e
7+
8+
# Import test library bundled with the devcontainer CLI
9+
source dev-container-features-test-lib
10+
11+
# Feature-specific tests
12+
check "claude command available" which claude
13+
check "yolo alias in bashrc" bash -c "grep -Fq 'claude --allow-dangerously-skip-permissions' ~/.bashrc"
14+
check "yolo alias in zshrc" bash -c "grep -Fq 'claude --allow-dangerously-skip-permissions' ~/.zshrc"
15+
check "fish yolo function body" bash -c "test -f ~/.config/fish/functions/yolo.fish && grep -Fq 'claude --allow-dangerously-skip-permissions' ~/.config/fish/functions/yolo.fish"
16+
check "bashrc owned by current user" bash -c "test \"$(stat -c '%U' ~/.bashrc)\" = \"$(whoami)\""
17+
check "zshrc owned by current user" bash -c "test \"$(stat -c '%U' ~/.zshrc)\" = \"$(whoami)\""
18+
check "fish functions dir owned by current user" bash -c "test \"$(stat -c '%U' ~/.config/fish/functions)\" = \"$(whoami)\""
19+
check "fish function owned by current user" bash -c "test \"$(stat -c '%U' ~/.config/fish/functions/yolo.fish)\" = \"$(whoami)\""
20+
check "yolo resolves in bash" bash -ic "type yolo"
21+
22+
# Report results
23+
reportResults

test/claude-code/scenarios.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,22 @@
1919
"features": {
2020
"claude-code": {}
2121
}
22+
},
23+
"claude_code_yolo_alias": {
24+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
25+
"features": {
26+
"claude-code": {
27+
"yoloAlias": true
28+
}
29+
}
30+
},
31+
"claude_code_yolo_alias_with_custom_user": {
32+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
33+
"remoteUser": "vscode",
34+
"features": {
35+
"claude-code": {
36+
"yoloAlias": true
37+
}
38+
}
2239
}
2340
}

0 commit comments

Comments
 (0)