MCPcopy
hub / github.com/claude-code-best/claude-code / call

Function call

src/commands/attach/attach.ts:13–137  ·  view source on GitHub ↗
(args, context)

Source from the content-addressed store, hash-verified

11import { addSlaveClient } from '../../hooks/useMasterMonitor.js'
12
13export const call: LocalCommandCall = async (args, context) => {
14 const targetName = args.trim()
15 if (!targetName) {
16 return {
17 type: 'text',
18 value: 'Usage: /attach <pipe-name>\nUse /pipes to list available pipes.',
19 }
20 }
21
22 const currentState = context.getAppState()
23
24 // Check if already attached to this slave
25 if (getPipeIpc(currentState).slaves[targetName]) {
26 return {
27 type: 'text',
28 value: `Already attached to "${targetName}".`,
29 }
30 }
31
32 // Controlled sub sessions cannot attach to other sub sessions.
33 if (isPipeControlled(getPipeIpc(currentState))) {
34 return {
35 type: 'text',
36 value:
37 'Cannot attach: this sub is currently controlled by a master. Detach it from the master first.',
38 }
39 }
40
41 // Resolve TCP endpoint for LAN peers
42 let tcpEndpoint: TcpEndpoint | undefined
43 if (feature('LAN_PIPES')) {
44 const pipeState = getPipeIpc(currentState)
45 const discoveredPeer = pipeState.discoveredPipes.find(
46 (p: { pipeName: string }) => p.pipeName === targetName,
47 )
48 if (discoveredPeer) {
49 // Check if this is a LAN peer by looking up beacon data
50 const { getLanBeacon } =
51 require('../../utils/lanBeacon.js') as typeof import('../../utils/lanBeacon.js')
52 const beaconRef = getLanBeacon()
53 if (beaconRef) {
54 const lanPeers = beaconRef.getPeers()
55 const lanPeer = lanPeers.get(targetName)
56 if (lanPeer) {
57 tcpEndpoint = { host: lanPeer.ip, port: lanPeer.tcpPort }
58 }
59 }
60 }
61 }
62
63 // Connect to the target pipe server (UDS or TCP)
64 let client: PipeClient
65 try {
66 const myName =
67 getPipeIpc(currentState).serverName ?? `master-${process.pid}`
68 client = await connectToPipe(targetName, myName, undefined, tcpEndpoint)
69 } catch (err) {
70 return {

Callers

nothing calls this directly

Calls 12

getPipeIpcFunction · 0.85
isPipeControlledFunction · 0.85
getLanBeaconFunction · 0.85
connectToPipeFunction · 0.85
addSlaveClientFunction · 0.85
getPeersMethod · 0.80
getMethod · 0.65
disconnectMethod · 0.65
keysMethod · 0.65
sendMethod · 0.65
resolveFunction · 0.50
onMessageMethod · 0.45

Tested by

no test coverage detected