@@ -197,7 +197,7 @@ func ListDirectoryTree(searchPath string, ignore []string) (string, error) {
197197 return "", fmt.Errorf("error listing directory: %w", err)
198198 }
199199
200− tree := createFileTree(files)
200+ tree := createFileTree(files, searchPath)
201201 output := printTree(tree, searchPath)
202202
203203 if truncated {
@@ -207,12 +207,13 @@ func ListDirectoryTree(searchPath string, ignore []string) (string, error) {
207207 return output, nil
208208}
209209
210−func createFileTree(sortedPaths []string) []*TreeNode {
210+func createFileTree(sortedPaths []string, rootPath string) []*TreeNode {
211211 root := []*TreeNode{}
212212 pathMap := make(map[string]*TreeNode)
213213
214214 for _, path := range sortedPaths {
215− parts := strings.Split(path, string(filepath.Separator))
215+ relativePath := strings.TrimPrefix(path, rootPath)
216+ parts := strings.Split(relativePath, string(filepath.Separator))
216217 currentPath := ""
217218 var parentPath string
218219
@@ -241,7 +242,7 @@ func createFileTree(sortedPaths []string) []*TreeNode {
241242 }
242243
243244 isLastPart := i == len(parts)-1
244− isDir := !isLastPart || strings.HasSuffix(path, string(filepath.Separator))
245+ isDir := !isLastPart || strings.HasSuffix(relativePath, string(filepath.Separator))
245246 nodeType := "file"
246247 if isDir {
247248 nodeType = "directory"
@@ -273,7 +274,12 @@ func createFileTree(sortedPaths []string) []*TreeNode {
273274func printTree(tree []*TreeNode, rootPath string) string {
274275 var result strings.Builder
275276
276− result.WriteString(fmt.Sprintf("- %s%s\n", rootPath, string(filepath.Separator)))
277+ result.WriteString("- ")
278+ result.WriteString(rootPath)
279+ if rootPath[len(rootPath)-1] != '/' {
280+ result.WriteByte(filepath.Separator)
281+ }
282+ result.WriteByte('\n')
277283
278284 for _, node := range tree {
279285 printNode(&result, node, 1)