| name | p4-config |
| description | Switch between Perforce (P4) servers and download files from P4 depots. Use this skill whenever the user wants to switch P4 servers, change Perforce connection, or mentions "p4 switch", "p4 server", "switch perforce", "change p4 port". Also trigger when the user asks "which P4 server am I on" or wants to check/view current P4 settings. ALSO trigger when the user provides a Perforce depot path (starting with "//") and wants to download, sync, print, or view a file from P4 — e.g., "download //depot/project/doc/file.pdf" or "get //depot/path/to/file". |
| compatibility | {"tools":["Bash","Glob","Read","AskUserQuestion"]} |
p4-config
Manages Perforce configs and depot operations — switch configs, download files, and more.
Config file convention
Config files use the naming pattern .p4config.<CONFIG_NAME>, where the extension after .p4config. is a human-friendly config name chosen by the user (e.g., .p4config.austin, .p4config.atlanta).
Each config file contains one KEY=VALUE per line. Supported keys: P4PORT, P4USER, P4CLIENT, and any other P4* environment variable. Blank lines and lines starting with # are ignored.
See assets/.p4config.example for a template.
How settings are applied
Use p4 set KEY=VALUE to apply each setting. On Windows this writes to the registry; on macOS/Linux it writes to ~/.p4enviro. Either way, settings persist across all shells without needing to source or export anything — which is important because shell env vars don't survive between Bash calls in Claude Code.
Workflow
1. Discover available configs
Search for .p4config.* files. Check these locations in order, using the first one that has matches:
- The current working directory
- The user's home directory (
$HOME or $USERPROFILE)
Use Glob with pattern .p4config.* in each location.
Extract the config name from each filename — the part after .p4config. is the config name.
Parse each file to extract all KEY=VALUE pairs (skip blank lines and lines starting with #).
If no config files are found, tell the user and explain how to create one (point them to assets/.p4config.example in this skill's directory for a template).
2. Show current settings
Run p4 set to display what the user currently has active, so they can see what will change.
3. Prompt the user
Use AskUserQuestion to present the available configs:
- Label: the config name from the filename (e.g.,
austin)
- Description: the
P4PORT and P4USER from that config file
4. Apply the selected config
For each KEY=VALUE pair in the chosen config file, run p4 set KEY=VALUE. Chain all of them with && in a single Bash call. Only set keys that have non-empty values.
5. Verify
Run p4 set to confirm the new settings, and show the result to the user.
Downloading files from a depot path
When the user provides a Perforce depot path (anything starting with //), download the file using the currently active P4 config. Follow this logic:
1. Check if a P4 server is already configured
Run p4 set and look for P4PORT. If P4PORT is set, skip to step 3.
2. No server configured — help the user pick one
Search for .p4config.* files (same discovery logic as the Workflow section above).
- Configs found: Use AskUserQuestion to prompt the user to choose a config, then apply it with
p4 set.
- No configs found: Ask the user if they want to create a config file. Point them to
assets/.p4config.example in this skill's directory as a template. Do not proceed until a config is set up.
3. Download the file
Use p4 print -o <output_path> <depot_path> to download.
- Save to the
download/ subdirectory under the current working directory. Create the directory if it doesn't exist.
- Preserve the original filename from the depot path.
- If the download fails with a connection error, inform the user and suggest switching servers or checking network/VPN.
4. Confirm
Tell the user the local path where the file was saved.
Adding new configs
If the user wants to add a new config:
- Ask for all details in a single prompt using AskUserQuestion with four questions:
- Config name: a short name for the filename (e.g.,
austin)
- Protocol:
tcp (Recommended) or ssl
- Server hostname: the server address (e.g.,
myserver.example.com)
- P4USER: the Perforce username
Use the default port
1666. Combine protocol and hostname into P4PORT=<protocol>:<hostname>:1666. Do not ask for P4CLIENT — it's optional and many operations like p4 print work without it. The user can add it to the config file later if needed.
- Ask where to store the config file using AskUserQuestion:
- Current working directory (Recommended) — the default, keeps configs alongside the project
- Home directory —
$HOME or $USERPROFILE, useful if the config should be available from anywhere
- Read
assets/.p4config.example from this skill's directory. Use it as the base template — keep the comment block structure, replace the placeholder values (your-server-host, your-username) with the user's actual values, remove the P4CLIENT line, and update the CONFIG_NAME in the comments. Write the result as .p4config.<CONFIG_NAME> in the chosen location.