Skip to content

Commit b076988

Browse files
disconnect3dclaude
andauthored
Add cp command to copy files from container to host (#30)
Enables ad-hoc file extraction from a running devcontainer using `docker cp`, without requiring a mount or container rebuild. Usage: devc cp <container_path> <host_path> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c7ec556 commit b076988

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

install.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Commands:
3737
exec <cmd> Execute a command in the running container
3838
upgrade Upgrade Claude Code to latest version
3939
mount <host> <cont> Add a mount to the devcontainer (recreates container)
40+
cp <cont> <host> Copy files/directories from container to host
4041
help Show this help message
4142
4243
Examples:
@@ -49,6 +50,7 @@ Examples:
4950
devc exec ls -la # Run command in container
5051
devc upgrade # Upgrade Claude Code to latest
5152
devc mount ~/data /data # Add mount to container
53+
devc cp /some/file ./out # Copy a path from container to host
5254
EOF
5355
}
5456

@@ -328,6 +330,33 @@ cmd_mount() {
328330
log_success "Mount added: $host_path$container_path"
329331
}
330332

333+
cmd_cp() {
334+
local container_path="${1:-}"
335+
local host_path="${2:-}"
336+
337+
if [[ -z "$container_path" ]] || [[ -z "$host_path" ]]; then
338+
log_error "Usage: devc cp <container_path> <host_path>"
339+
exit 1
340+
fi
341+
342+
local workspace_folder
343+
workspace_folder="$(get_workspace_folder)"
344+
345+
# Find the running container
346+
local label="devcontainer.local_folder=$workspace_folder"
347+
local container_id
348+
container_id=$(docker ps -q --filter "label=$label" 2>/dev/null || true)
349+
350+
if [[ -z "$container_id" ]]; then
351+
log_error "No running devcontainer found for $workspace_folder"
352+
exit 1
353+
fi
354+
355+
log_info "Copying $container_path$host_path"
356+
docker cp "$container_id:$container_path" "$host_path"
357+
log_success "Copied $container_path$host_path"
358+
}
359+
331360
cmd_self_install() {
332361
local install_dir="$HOME/.local/bin"
333362
local install_path="$install_dir/devc"
@@ -415,6 +444,9 @@ main() {
415444
mount)
416445
cmd_mount "$@"
417446
;;
447+
cp)
448+
cmd_cp "$@"
449+
;;
418450
self-install)
419451
cmd_self_install
420452
;;

0 commit comments

Comments
 (0)