Skip to content
Agentmart
Submit a tool

codespace-port-visibility

Automate Codespace port visibility via CLI w/ vscode token.

Skill by gitricko

IndexedMIT★ 1
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/gitricko-codespace-port-visibility

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Automate Codespace port visibility via CLI w/ vscode token.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Python package

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/codespace-port-visibility

What's inside

Skill name
codespace-port-visibility
Description
Automate Codespace port visibility via CLI w/ vscode token.
License
MIT
Instructions
94 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Files (5)

  • SKILL.md
  • export_codespace_token.sh · scripts/
  • expose_port.py · scripts/
  • get_codespace_token.py · scripts/
  • set_port_visibility.py · scripts/

SKILL.md (first lines)

# Codespace Port Visibility Automation

## Problem

GitHub Codespaces require manual UI interaction to change port visibility (public/private/org). This breaks automation for services that need specific port visibility configurations.

## Solution

Extract `GITHUB_TOKEN` from the vscode-server process environment (not shell env), then use `gh codespace ports visibility` CLI.

## Usage

```bash
# Make port public
python3 scripts/set_port_visibility.py 8899 public

# Make port private
python3 scripts/set_port_visibility.py 4387 private

# List all ports
python3 scripts/set_port_visibility.py list

# Or use the CLI directly after sourcing token
source scripts/export_codespace_token.sh
gh codespace ports visibility 8080:public -c $CODESPACE_NAME
```

## NEW Port Exposure (zero manual clicks)

To expose a port that VS Code has **NOT** auto-forwarded yet (e.g. a fresh nginx slot), two steps are required:

```bash
# Step 1: Establish the tunnel (forward to a DIFFERENT local port to avoid bind conflict
# with the service already listening on <port>). gh tries to bind the local side, so if
# nginx already holds 8081, forward 8081:18081 instead.
gh codespace ports forward 8081:18081 -c $CODESPACE_NAME

# Step 2: Flip visibility to public
gh codespace ports visibility 8081:public -c $CODESPACE_NAME
```

**Why:** `gh codespace ports visibility` alone returns `404` for a port GitHub's backend
doesn't yet know about. The `forward` command registers the tunnel; `visibility` then works.
Already-forwarded ports (like 8080, auto-detected by VS Code) only need the `visibility` step.

**Script wrapper:** `scripts/expose_port.py <port> [local-port] [codespace]` does both steps.

## Scripts

| Script | Purpose |
|--------|---------|
| `scripts/set_port_visibility.py` | Main CLI: `python3 set_port_visibility.py <port> <visibility> [codespace]` |
| `scripts/expose_port.py` | NEW: forward + make public in one call (for un-forwarded ports) |
| `scripts/export_codespace_token.sh` | Exports GITHUB_TOKEN for direct `gh` usage |
| `scripts/get_codespace_token.py` | Reusable token extraction module |

## Token Extraction Logic

```python
def get_codespace_token():
    # Find code-server process (PID 399 typically)
    for pid in /proc/*/cmdline:
        if b'code-server' in open(pid, 'rb').read():
            with open(f'/proc/{pid}/environ', 'rb') as f:
                for entry in f.read().split(b'\x00'):
                    if entry.startswith(b'GITHUB_TOKEN='):
                        return entry.decode().split('=', 1)[1]
```

## Integration Example

```bash
# 1. Make service port private for security
python3 scripts/set_port_visibility.py 4387 private

# 2. Make proxy port public for access
python3 scripts/set_port_visibility.py 8080 public

# 3. Start services
LAVISH_AXI_NO_OPEN=1 node dist/cli.mjs sample.html --no-open &
sudo nginx -g 'daemon off;' &
```

## Prerequisites

- `gh` CLI installed (`pnpm add -g @github/cli` or `apt install gh`)
- Running in a GitHub Codespace (vscode-server process exists)
- `CODESPACE_NAME` environment variable set (auto-set in Codespaces)

## Related Skills

- `codespace-gh-auth` — GitHub auth setup for Codespaces
- `github-codespace` — Full Codespace workflow (auth, CI, PR)

From gitricko/.minions, MIT.

More from gitricko/.minions

Signals

Stars
1
Forks
2
Open issues
3
Last commit (this folder)
Oct 13, 2026 (16 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from gitricko

Cite this page

codespace-port-visibility skill. Agent Mart. https://agentmart.dev/skills/gitricko-codespace-port-visibility (last updated 2026-10-24)